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.
formatXML(JSON)
formatXML(JSON, boolean)
string
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.1
formatXML({
2
contact: {
3
@type: "Person",
4
firstName: {
5
@: 'First Name'
6
},
7
lastName: {
8
@: 'Last Name'
9
},
10
phone: [{
11
@type: "Mobile",
12
@: Mobile
13
}, {
14
@type: "Phone",
15
@: Phone
16
}]
17
}
18
}, true)
Result: You'll get an XML string with the data from the JSON object.
1
<?xml version="1.0" encoding="utf-8"?>
2
<contact type="Person">
3
<firstName>Steve</firstName>
4
<lastName>Rogers</lastName>
5
<phone type="Mobile">(+1) (202) 123 45 67</phone>
6
<phone type="Phone">+1.151.11 ++66 14 66</phone>
7
</contact>
Last modified 11mo ago