Forum Discussion
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.
HI @robin ,
Thanks for the reply…
The steps you have suggested is (as I understand):
JSON Generator >> XML Formatter >> File Writer
If Yes, I still don’t understand how to introduce the namespace…
Related to JSON-to-XML conventions, are you referring to this URL:Convert json to xml
If possible can have a sample pipeline?
Thanks,
Deepak.
Upon completion of the read operation, the “Multi File Reader” snap produces an output document that contains this field: content-location. Pass $[‘content-location’] to the “File Delete” snap with expression enabled for the “File” property. To ensure files are deleted only at the time of pipeline execution, uncheck “Execute during preview” on the File Delete snap.
Note: Currently, the “File Delete” snap supports deletions one file at a time.