xmltodict icon indicating copy to clipboard operation
xmltodict copied to clipboard

Parsing processing instructions

Open mindey opened this issue 7 years ago • 1 comments

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>

mindey avatar Nov 20 '18 09:11 mindey

<?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\""
      }
    ]
  }
}

javadev avatar Dec 03 '18 05:12 javadev