xmltodict
xmltodict copied to clipboard
Parsing processing instructions
Would like to optionally be able to parse the elements starting with <? and ending with ?>, such as the below <?xml version="1.0"?>, <?token attribute="https://some.thing"?>.
Example:
<?xml version="1.0"?>
<data>
<country name="Liechtenstein">
<rank>1</rank>
<year>2008</year>
<gdppc>141100</gdppc>
<neighbor name="Austria" direction="E"/>
<neighbor name="Switzerland" direction="W"/>
<?token attribute="https://some.thing"?>
</country>
<country name="Singapore">
<rank>4</rank>
<year>2011</year>
<gdppc>59900</gdppc>
<neighbor name="Malaysia" direction="N"/>
<?token attribute="https://some.thing"?>
</country>
<country name="Panama">
<rank>68</rank>
<year>2011</year>
<gdppc>13600</gdppc>
<neighbor name="Costa Rica" direction="W"/>
<neighbor name="Colombia" direction="E"/>
<?token attribute="https://some.thing"?>
</country>
</data>
<?xml version="1.0"?>
<data>
<country name="Liechtenstein">
<rank>1</rank>
<year>2008</year>
<gdppc>141100</gdppc>
<neighbor name="Austria" direction="E"/>
<neighbor name="Switzerland" direction="W"/>
<?token attribute="https://some.thing"?>
</country>
<country name="Singapore">
<rank>4</rank>
<year>2011</year>
<gdppc>59900</gdppc>
<neighbor name="Malaysia" direction="N"/>
<?token attribute="https://some.thing"?>
</country>
<country name="Panama">
<rank>68</rank>
<year>2011</year>
<gdppc>13600</gdppc>
<neighbor name="Costa Rica" direction="W"/>
<neighbor name="Colombia" direction="E"/>
<?token attribute="https://some.thing"?>
</country>
</data>
may be converted to
{
"data": {
"country": [
{
"-name": "Liechtenstein",
"rank": "1",
"year": "2008",
"gdppc": "141100",
"neighbor": [
{
"-name": "Austria",
"-direction": "E",
"-self-closing": "true"
},
{
"-name": "Switzerland",
"-direction": "W",
"-self-closing": "true"
}
],
"?token": "attribute=\"https://some.thing\""
},
{
"-name": "Singapore",
"rank": "4",
"year": "2011",
"gdppc": "59900",
"neighbor": {
"-name": "Malaysia",
"-direction": "N",
"-self-closing": "true"
},
"?token": "attribute=\"https://some.thing\""
},
{
"-name": "Panama",
"rank": "68",
"year": "2011",
"gdppc": "13600",
"neighbor": [
{
"-name": "Costa Rica",
"-direction": "W",
"-self-closing": "true"
},
{
"-name": "Colombia",
"-direction": "E",
"-self-closing": "true"
}
],
"?token": "attribute=\"https://some.thing\""
}
]
}
}