formatXML

To convert a given JSON object into XML text, which might be optically structured

Use this function to convert data into XML format. XML is beside JSON one of the most popular formats for exchanging data. That's why this function is of particular interest when connecting to external servers via API.

More about API at Ninox.

Syntax

formatXML(JSON)

formatXML(JSON, boolean)

Return

string

Examples

formatXML(JSON) To convert a given JSON object into XML text.

formatXML(json,pretty) To convert a given JSON object into XML text. If pretty is true the text is optically structured.

formatXML({
    contact: {
        @type: "Person",
        firstName: {
            @: 'First Name'
        },
        lastName: {
            @: 'Last Name'
        },
        phone: [{
                @type: "Mobile",
                @: Mobile
            }, {
                @type: "Phone",
                @: Phone
            }]
    }
}, true)

Result: You'll get an XML string with the data from the JSON object.

<?xml version="1.0" encoding="utf-8"?>
<contact type="Person">
    <firstName>Steve</firstName>
    <lastName>Rogers</lastName>
    <phone type="Mobile">(+1) (202) 123 45 67</phone>
    <phone type="Phone">+1.151.11 ++66 14 66</phone>
</contact>

See also

parseXML, which converts an XML string to a JSON object.

Last updated