XML tag class.
A valid XML tag must have the following syntax for a tag without a content (with only attributes):
<Tag_Name att#1_Name="att#1_val" att#2_Name="att#2_val"... att#Nt_Name="att#Nt_val"/>
while a tag with a content must have the following syntax:
<Tag_Name att#1_Name="att#1_val" att#2_Name="att#2_val"... att#Nt_Name="att#Nt_val">Tag_Content</Tag_Name>
It is worth noting that the syntax is case sensitive and that the attributes are optional. Each attribute name must be followed by '="' without any additional white spaces and its value must be termined by '"'. Each attribute is separated by one or more white spaces.
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
type(string), | private | :: | tag_name | Tag name. |
|||
type(string), | private | :: | tag_content | Tag content. |
|||
type(string), | private, | allocatable | :: | attribute(:,:) | Attributes names/values pairs, [1:2, 1:]. |
||
integer(kind=I4P), | private | :: | attributes_number | = | 0 | Number of defined attributes. |
|
integer(kind=I4P), | private | :: | indent | = | 0 | Number of indent-white-spaces. |
|
logical, | private | :: | is_self_closing | = | .false. | Self closing tag flag. |
Overload xml_tag with creator procedures.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | name | Tag name. |
||
character(len=*), | intent(in), | optional | :: | attribute(1:) | Attribute name/value pair [1:2]. |
|
character(len=*), | intent(in), | optional | :: | attributes(1:,1:) | Attributes list of name/value pairs [1:2,1:]. |
|
character(len=*), | intent(in), | optional | :: | attributes_stream | Attributes list of name/value pairs as single stream. |
|
logical, | intent(in), | optional | :: | sanitize_attributes_value | Sanitize attributes value. |
|
character(len=*), | intent(in), | optional | :: | content | Tag value. |
|
integer(kind=I4P), | intent(in), | optional | :: | indent | Number of indent-white-spaces. |
|
logical, | intent(in), | optional | :: | is_content_indented | Activate content indentation. |
|
logical, | intent(in), | optional | :: | is_self_closing | The tag is self closing. |
XML tag.
Return an instance of xml tag.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | name | Tag name. |
||
type(xml_tag), | intent(in) | :: | content | Tag value as nested tag.. |
||
character(len=*), | intent(in), | optional | :: | attribute(1:) | Attribute name/value pair [1:2]. |
|
character(len=*), | intent(in), | optional | :: | attributes(1:,1:) | Attributes list of name/value pairs [1:2,1:]. |
|
character(len=*), | intent(in), | optional | :: | attributes_stream | Attributes list of name/value pairs as single stream. |
|
logical, | intent(in), | optional | :: | sanitize_attributes_value | Sanitize attributes value. |
|
integer(kind=I4P), | intent(in), | optional | :: | indent | Number of indent-white-spaces. |
|
logical, | intent(in), | optional | :: | is_content_indented | Activate value indentation. |
XML tag.
Return an instance of xml tag with value being a nested tag.
Add attributes name/value pairs.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(xml_tag), | intent(inout) | :: | self | XML tag. |
||
character(len=*), | intent(in) | :: | attribute(1:) | Attribute name/value pair [1:2]. |
||
logical, | intent(in), | optional | :: | sanitize_value | Sanitize attribute value. |
Add one attribute name/value pair.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(xml_tag), | intent(inout) | :: | self | XML tag. |
||
character(len=*), | intent(in) | :: | attributes(1:,1:) | Attribute name/value pair list [1:2,1:]. |
||
logical, | intent(in), | optional | :: | sanitize_values | Sanitize attribute values. |
Add list of attributes name/value pairs.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(xml_tag), | intent(inout) | :: | self | XML tag. |
||
character(len=*), | intent(in) | :: | attributes_stream | Attribute name/value pair list passed as stream. |
||
logical, | intent(in), | optional | :: | sanitize_values | Sanitize attribute values. |
Add list of attributes name/value pairs passed as stream.
Return attributes name/value pairs as string.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(xml_tag), | intent(in) | :: | self | XML tag. |
The attributes string.
Return attributes name/value pairs as string.
Return tag content.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(xml_tag), | intent(in) | :: | self | XML tag. |
||
character(len=*), | intent(in) | :: | name | Searched tag name. |
Tag content.
Return tag content of self (or its nested tags) if named name.
Delete attributes name/value pairs.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(xml_tag), | intent(inout) | :: | self | XML tag. |
||
character(len=*), | intent(in) | :: | name | Attribute name. |
Delete one attribute name/value pair.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(xml_tag), | intent(inout) | :: | self | XML tag. |
||
character(len=*), | intent(in) | :: | name(1:) | Attributes names. |
Delete list of attributes name/value pairs.
Delete tag conent.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(xml_tag), | intent(inout) | :: | self | XML tag. |
Delete tag content.
Return </tag_name>
end tag.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(xml_tag), | intent(in) | :: | self | XML tag. |
||
logical, | intent(in), | optional | :: | is_indented | Activate content indentation. |
The end tag string.
Return </tag_name>
end tag.
Free dynamic memory.
Return .true. it the queried attribute name is defined.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(xml_tag), | intent(in) | :: | self | XML tag. |
||
character(len=*), | intent(in) | :: | name | Attribute name. |
Inquire result.
Return .true. it the queried attribute name is defined, .false. otherwise.
Check is tag is correctly parsed, i.e. its tag_name is allocated.
Return tag name.
Parse the tag contained into a source string.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(xml_tag), | intent(inout) | :: | self | XML tag. |
||
character(len=*), | intent(in) | :: | source | String containing the input. |
||
integer(kind=I4P), | intent(out), | optional | :: | tstart | Starting index of tag inside the string. |
|
integer(kind=I4P), | intent(out), | optional | :: | tend | Ending index of tag inside the string. |
Parse the tag contained into a source string.
Return <tag_name.../>
self closing tag.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(xml_tag), | intent(in) | :: | self | XML tag. |
||
logical, | intent(in), | optional | :: | is_indented | Flag to check if tag is indented. |
The self closing tag string.
Return <tag_name.../>
self closing tag.
Set tag data.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(xml_tag), | intent(inout) | :: | self | XML tag. |
||
character(len=*), | intent(in), | optional | :: | name | Tag name. |
|
character(len=*), | intent(in), | optional | :: | attribute(1:) | Attribute name/value pair [1:2]. |
|
character(len=*), | intent(in), | optional | :: | attributes(1:,1:) | Attributes list of name/value pairs [1:2,1:]. |
|
character(len=*), | intent(in), | optional | :: | attributes_stream | Attributes list of name/value pairs as single stream. |
|
logical, | intent(in), | optional | :: | sanitize_attributes_value | Sanitize attributes value. |
|
character(len=*), | intent(in), | optional | :: | content | Tag value. |
|
integer(kind=I4P), | intent(in), | optional | :: | indent | Number of indent-white-spaces. |
|
logical, | intent(in), | optional | :: | is_content_indented | Activate value indentation. |
|
logical, | intent(in), | optional | :: | is_self_closing | The tag is self closing. |
Set tag data.
Return <tag_name...>
start tag.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(xml_tag), | intent(in) | :: | self | XML tag. |
||
logical, | intent(in), | optional | :: | is_indented | Flag to check if tag is indented. |
The start tag string.
Return <tag_name...>
start tag.
Convert the whole tag into a string.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(xml_tag), | intent(in) | :: | self | XML tag. |
||
logical, | intent(in), | optional | :: | is_indented | Activate content indentation. |
|
logical, | intent(in), | optional | :: | is_content_indented | Activate content indentation. |
|
logical, | intent(in), | optional | :: | only_start | Write only start tag. |
|
logical, | intent(in), | optional | :: | only_content | Write only content. |
|
logical, | intent(in), | optional | :: | only_end | Write only end tag. |
Output string containing the whole tag.
Convert the whole tag into a string.
Write tag to unit file.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(xml_tag), | intent(in) | :: | self | XML tag. |
||
integer(kind=I4P), | intent(in) | :: | unit | File unit. |
||
logical, | intent(in), | optional | :: | is_indented | Activate content indentation. |
|
logical, | intent(in), | optional | :: | is_content_indented | Activate content indentation. |
|
character(len=*), | intent(in), | optional | :: | form | Format. |
|
character(len=*), | intent(in), | optional | :: | end_record | Ending record. |
|
logical, | intent(in), | optional | :: | only_start | Write only start tag. |
|
logical, | intent(in), | optional | :: | only_content | Write only content. |
|
logical, | intent(in), | optional | :: | only_end | Write only end tag. |
|
integer(kind=I4P), | intent(out), | optional | :: | iostat | IO status. |
|
character(len=*), | intent(out), | optional | :: | iomsg | IO message. |
Write tag to unit file.
Assignment operator overloading.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(xml_tag), | intent(inout) | :: | lhs | Left hand side. |
||
type(xml_tag), | intent(in) | :: | rhs | Right hand side. |
Assignment between two tags.
Add one attribute name/value pair.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(xml_tag), | intent(inout) | :: | self | XML tag. |
||
character(len=*), | intent(in) | :: | attribute(1:) | Attribute name/value pair [1:2]. |
||
logical, | intent(in), | optional | :: | sanitize_value | Sanitize attribute value. |
Add one attribute name/value pair.
Add list of attributes name/value pairs.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(xml_tag), | intent(inout) | :: | self | XML tag. |
||
character(len=*), | intent(in) | :: | attributes(1:,1:) | Attribute name/value pair list [1:2,1:]. |
||
logical, | intent(in), | optional | :: | sanitize_values | Sanitize attribute values. |
Add list of attributes name/value pairs.
Add list of attributes name/value pairs passed as stream.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(xml_tag), | intent(inout) | :: | self | XML tag. |
||
character(len=*), | intent(in) | :: | attributes_stream | Attribute name/value pair list passed as stream. |
||
logical, | intent(in), | optional | :: | sanitize_values | Sanitize attribute values. |
Add list of attributes name/value pairs passed as stream.
Allocate (prepare for filling) dynamic memory of attributes.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(xml_tag), | intent(inout) | :: | self | XML tag. |
||
integer(kind=I4P), | intent(in) | :: | Na | Number of attributes. |
Allocate (prepare for filling) dynamic memory of attributes.
Delete one attribute name/value pair.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(xml_tag), | intent(inout) | :: | self | XML tag. |
||
character(len=*), | intent(in) | :: | name | Attribute name. |
Delete one attribute name/value pair.
Delete list of attributes name/value pairs.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(xml_tag), | intent(inout) | :: | self | XML tag. |
||
character(len=*), | intent(in) | :: | name(1:) | Attributes names. |
Delete list of attributes name/value pairs.
Get the tag value and attributes from source.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(xml_tag), | intent(inout) | :: | self | XML tag. |
||
character(len=*), | intent(in) | :: | source | String containing data. |
Get the tag content and attributes from source after tag_name and attributes names have been set.
Get the tag value from source after tag_name has been set.
Get the attributes values from source.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(xml_tag), | intent(inout) | :: | self | XML tag. |
||
character(len=*), | intent(in) | :: | source | String containing data. |
Get the attributes values from source after tag_name and attributes names have been set.
Parse the tag name contained into a string.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(xml_tag), | intent(inout) | :: | self | XML tag. |
||
character(len=*), | intent(in) | :: | source | String containing the input. |
||
integer(kind=I4P), | intent(out), | optional | :: | tstart | Starting index of tag inside the source. |
|
integer(kind=I4P), | intent(out), | optional | :: | tend | Ending index of tag inside the source. |
Parse the tag name contained into a string.
Parse the tag attributes names contained into a string.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(xml_tag), | intent(inout) | :: | self | XML tag. |
||
character(len=*), | intent(in) | :: | source | String containing the input. |
Parse the tag attributes names contained into a string.
Search tag named tag_name into a string.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(xml_tag), | intent(inout) | :: | self | XML tag. |
||
character(len=*), | intent(in) | :: | tag_name | Searched tag name. |
||
character(len=*), | intent(in) | :: | source | String containing the input. |
||
integer(kind=I4P), | intent(out), | optional | :: | tstart | Starting index of tag inside the source. |
|
integer(kind=I4P), | intent(out), | optional | :: | tend | Ending index of tag inside the source. |
Search tag named tag_name into a string and, in case it is found, store into self.
Assignment between two tags.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(xml_tag), | intent(inout) | :: | lhs | Left hand side. |
||
type(xml_tag), | intent(in) | :: | rhs | Right hand side. |
Assignment between two tags.
type :: xml_tag
!< XML tag class.
!<
!< A valid XML tag must have the following syntax for a tag without a content (with only attributes):
!<```xml
!< <Tag_Name att#1_Name="att#1_val" att#2_Name="att#2_val"... att#Nt_Name="att#Nt_val"/>
!<```
!< while a tag with a content must have the following syntax:
!<```xml
!< <Tag_Name att#1_Name="att#1_val" att#2_Name="att#2_val"... att#Nt_Name="att#Nt_val">Tag_Content</Tag_Name>
!<```
!<
!< It is worth noting that the syntax is case sensitive and that the attributes are optional. Each attribute name must be followed
!< by '="' without any additional white spaces and its value must be termined by '"'. Each attribute is separated by one or more
!< white spaces.
private
type(string) :: tag_name !< Tag name.
type(string) :: tag_content !< Tag content.
type(string), allocatable :: attribute(:,:) !< Attributes names/values pairs, [1:2, 1:].
integer(I4P) :: attributes_number=0 !< Number of defined attributes.
integer(I4P) :: indent=0 !< Number of indent-white-spaces.
logical :: is_self_closing=.false. !< Self closing tag flag.
contains
! public methods
generic :: add_attributes => &
add_single_attribute, &
add_multiple_attributes, &
add_stream_attributes !< Add attributes name/value pairs.
procedure, pass(self) :: attributes !< Return attributes name/value pairs as string.
procedure, pass(self) :: content !< Return tag content.
generic :: delete_attributes => &
delete_single_attribute, &
delete_multiple_attributes !< Delete attributes name/value pairs.
procedure, pass(self) :: delete_content !< Delete tag conent.
procedure, pass(self) :: end_tag !< Return `</tag_name>` end tag.
procedure, pass(self) :: free !< Free dynamic memory.
procedure, pass(self) :: is_attribute_present !< Return .true. it the queried attribute name is defined.
procedure, pass(self) :: is_parsed !< Check is tag is correctly parsed, i.e. its *tag_name* is allocated.
procedure, pass(self) :: name !< Return tag name.
procedure, pass(self) :: parse !< Parse the tag contained into a source string.
procedure, pass(self) :: self_closing_tag !< Return `<tag_name.../>` self closing tag.
procedure, pass(self) :: set !< Set tag data.
procedure, pass(self) :: start_tag !< Return `<tag_name...>` start tag.
procedure, pass(self) :: stringify !< Convert the whole tag into a string.
procedure, pass(self) :: write => write_tag !< Write tag to unit file.
generic :: assignment(=) => assign_tag !< Assignment operator overloading.
! private methods
procedure, pass(self), private :: add_single_attribute !< Add one attribute name/value pair.
procedure, pass(self), private :: add_multiple_attributes !< Add list of attributes name/value pairs.
procedure, pass(self), private :: add_stream_attributes !< Add list of attributes name/value pairs passed as stream.
procedure, pass(self), private :: alloc_attributes !< Allocate (prepare for filling) dynamic memory of attributes.
procedure, pass(self), private :: delete_single_attribute !< Delete one attribute name/value pair.
procedure, pass(self), private :: delete_multiple_attributes !< Delete list of attributes name/value pairs.
procedure, pass(self), private :: get !< Get the tag value and attributes from source.
procedure, pass(self), private :: get_value !< Get the tag value from source after tag_name has been set.
procedure, pass(self), private :: get_attributes !< Get the attributes values from source.
procedure, pass(self), private :: parse_tag_name !< Parse the tag name contained into a string.
procedure, pass(self), private :: parse_attributes_names !< Parse the tag attributes names contained into a string.
procedure, pass(self), private :: search !< Search tag named *tag_name* into a string.
! operators
procedure, pass(lhs), private :: assign_tag !< Assignment between two tags.
final :: finalize !< Free dynamic memory when finalizing.
endtype xml_tag