xml_map_converter

Creator: coderz1093

Last updated:

Add to Cart

Description:

xml map converter

XML Map Converter #
XML to Dart map converter and vice versa.
Inspired by the work of Stefan Goessner.
The package contains two classes, first for converting XML text to dart Maps, and second for converting a dart Map to XML text.
Xml2Map #
Converts XML text to dart Map structures.
Tag names are converted to keys in the Map, tag values and attributes are converted to values in the Map.
For example, the following xml...
<users>
<user id="1">
<name>John</name>
<surname>Doe</surname>
</user>
<user id="2">
<name>Richard</name>
<surname>Roe</surname>
</users>
</users>
copied to clipboard
will be converted to a structure:
{
"users": {
"user": [
{
"@id": "1",
"name": "John",
"surname": "Doe"
},
{
"@id": "2",
"name": "Richard",
"surname": "Roe"
}
]
}
}
copied to clipboard
Attributes #
XML attributes are turned into keys prefixed with @, for example:
<record id="1"/>
copied to clipboard
{
"record": {
"@id": "1"
}
}
copied to clipboard
Node content #
The text content of the xml node is turned into a value in the Map...
<record>Record 1</record>
copied to clipboard
{
"record": "Record 1"
}
copied to clipboard
...but if the Map already has attributes or nested values, then the text content is written to the #text key:
<record id="1">Record 1</record>
copied to clipboard
{
"record": {
"@id": "1",
"#text": "Record 1"
}
}
copied to clipboard
CDATA #
The CDATA content of the xml node is written to the #cdata key:
<record id="1">
<![CDATA
Record 1
]]>
</record>
copied to clipboard
{
"record": {
"@id": "1",
"#cdata": "
Record 1
"
}
}
copied to clipboard
Tag list #
Multiple tags with the same name are combined into a list:
<records>
<record id="1">Record 1</record>
<record id="1">Record 1</record>
<total>2 records</total>
</records>
copied to clipboard
{
"records": {
"record": [
{
"@id": "1",
"#text": "Record 1"
},
{
"@id": "1",
"#text": "Record 1"
}
],
"total": "2 records"
}
}
copied to clipboard
Map2Xml #
Converts dart Map structures to XML text.
Converts a dart Map to XML text, turning keys into tags, values into tag content and child tags, @ prefixed keys into tag attributes, see above for details.

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files:

Customer Reviews

There are no reviews.