I have XML files following an XSD and I need to transform them into JSON.
The files are typically like this
example.xml :
<object name="foo">
<values>one</values>
<values>two</values>
<values>three</values>
<param attr="2" value="true" />
</object>
Which translate into JSON to this
{
"name" : "foo",
"values" : [
"one",
"two",
"three"
],
"param" : {
"attr" : "2",
"value" : "true"
}
}
This is almost fine, except that I would like the data to be typed, so that param becomes :
"param" : {
"attr" : 2,
"value" : true
}
The XML files reference an XSD schema that defines the data type for each element or attribute, such as
<xs:attribute name="attr" type="xs:integer"
The XML to JSON transformation is done using XML::Simple
to read the XML into a Perl hash and the JSON module is used to encode into JSON.
How could I do the same job but using the definitions from the XSD Schema to load the XML with the right type for each field?
I need to use the XSD because it may happen that text field are made of only numbers.