You are here:
XML and JSON in Omnistudio Data Mappers
In addition to JSON, Data Mappers can have XML input and output. The XML format in Data Mappers is an unordered key-value, JSON-like structure.
To specify the order in which the elements of the XML output are serialized, populate the Expected XML Output pane with an XML structure that is composed in the desired order.
This example compares equivalent structures in JSON and XML.
JSON
{
"Root": {
"#text": "rootValue",
"@attribute1": "attVal1",
"#ns": "http://namespace1",
"#ns#a": "http://namespace2",
"Child": [{
"@attribute2": "attval2"
},
{
"#text": "childValue"
}
]
}
}
XML
<Root attribute1="attVal1" xmlns="http://namespace1" xmlns:a="http://namespace2">
rootValue
<Child attribute2="attval2"></Child>
<Child>childValue</Child>
</Root>
Data Mappers that transform XML to JSON by using these conventions to handle the differences between the formats.
- Values in an input XML node are translated to output JSON with the key
#text. - XML:
<Root>rootValue</Root> - JSON:
{ "Root": { "#text": "rootValue" } } - Values in an input XML node are translated to output JSON with a key that is preceded by
an at sign (
@). - XML:
<Root attribute1="attVal1"></Root> - JSON:
{ "Root": { "@attribute1": "attVal1" } } - Namespaces in an input XML node are prepended with
#nsin the output JSON. - XML:
<Root xmlns="http://namespace1" xmlns:a="http://namespace2"> </Root> - JSON:
{ "Root": { "#ns":"http://namespace1", "#ns#a":"http://namespace2, } } - Colons, which are reserved characters in Data Mapper mappings, are replaced by
#. - XML:
<Root:Data>data</Root:Data> - JSON:
{ "Root#Data": { "#text":"data", } }

