You’ll use our JSON-to-XML conventions, which are basically:
{
"root": {
"elementName": {
"@attributeName": "attributeValue",
"$": "elementValue"
},
"repeatedElement": [
{
"key": {
"@attr": "attr1",
"$": "key1"
},
"value": "value1"
},
{
"key": {
"@attr": "attr2",
"$": "key2"
},
"value": "value2"
}
]
}
}
That input Document into the XML Formatter will generate the following XML:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<elementName attributeName="attributeValue">elementValue</elementName>
<repeatedElement>
<key attr="attr1">key1</key>
<value>value1</value>
</repeatedElement>
<repeatedElement>
<key attr="attr2">key2</key>
<value>value2</value>
</repeatedElement>
</root>
So, for the sample I provided above, the following should give you enough information to get to your final desired XML:
[
{
"ProductCode": {
"@xmlns:cac": "urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2",
"@xmlns:cbc": "urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2",
"@xmlns": "urn:oasis:names:specification:ubl:schema:xsd:Invoice-2",
"cbc:ProductName": {
"cac:CostLocation": [
{
"cbc:country": "US",
"cbc:Cost": "$400"
},
{
"cbc:country": "AU",
"cbc:Cost": "$500"
},
{
"cbc:country": "EU",
"cbc:Cost": "$550"
}
]
}
}
}
]
which results in:
<?xml version="1.0" encoding="UTF-8"?>
<ProductCode xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2" xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">
<cbc:ProductName>
<cac:CostLocation>
<cbc:country>US</cbc:country>
<cbc:Cost>$400</cbc:Cost>
</cac:CostLocation>
<cac:CostLocation>
<cbc:country>AU</cbc:country>
<cbc:Cost>$500</cbc:Cost>
</cac:CostLocation>
<cac:CostLocation>
<cbc:country>EU</cbc:country>
<cbc:Cost>$550</cbc:Cost>
</cac:CostLocation>
</cbc:ProductName>
</ProductCode>
Go from there to finish the rest of the XML you want.