convert XML to JSON()
This function converts the text of an XML file or an XML DOM object into the text of a JSON file.
Parameters
Parameter |
Description |
a |
The text of an XML file or the name of an XML DOM object, see function "parse XML()". See also parameter b. |
b |
(option) "true", if an XML DOM object was specified in parameter a. Default: "false". |
c |
(optional) "true" to format the JSON text (pretty format). Default: "false". |
Example
Assume the following XML file.
<
Order
date
=
"today"
>
<
line
>
<
product
pos
=
"1"
ean
=
"0815"
amount
=
"2.0"
vat
=
"19%"
net
=
"100"
>
<
description
>article@pos 1</
description
>
</
product
>
</
line
>
<
line
>
<
product
pos
=
"2"
ean
=
"4711"
amount
=
"1.0"
vat
=
"19%"
net
=
"145.34"
>
<
description
>article@pos 2</
description
>
</
product
>
</
line
>
<
footer
totalSum
=
"345.34"
>end of order</
footer
>
</
Order
>
This will result in the following JSON file.
{
"Order"
:{
"date"
:
"today"
,
"line"
:[
{
"product"
:{
"pos"
:
"1"
,
"ean"
:
"0815"
,
"amount"
:
"2.0"
,
"vat"
:
"19%"
,
"net"
:
"100"
,
"description"
:
"article@pos 1"
}
},
{
"product"
:{
"pos"
:
"2"
,
"ean"
:
"4711"
,
"amount"
:
"1.0"
,
"vat"
:
"19%"
,
"net"
:
"145.34"
,
"description"
:
"article@pos 2"
}
}
],
"footer"
:{
"totalSum"
:
"345.34"
,
"Text"
:
"end of order"
}
}
}