xmltodict icon indicating copy to clipboard operation
xmltodict copied to clipboard

Keep Text order after parsing if there is an ordereddict between them

Open raaaaay-c opened this issue 6 years ago • 3 comments

Example XML that are full of HTML tags: <p>XXXXXXX <a href="url" type="external">123456</a>: YYYYYYY</p>

currently, when I parse this xml , it shows

OrderedDict([('p', [OrderedDict([('a', OrderedDict([('@href', 'url'), ('@type', 'external'), ('#text', '123456')])), ('#text', XXXXXXXXYYYYYY')]) , which combines the texts in #text

XXXXXX and YYYYY are combined which is not the xml element order.

Is there a way to parse xml to #text,OrderedDict[a],#text rather then OrdererDict[a] and #text ?

raaaaay-c avatar Nov 17 '18 18:11 raaaaay-c

<p>XXXXXXX <a href="url" type="external">123456</a>: YYYYYYY</p>

maybe converted to:

{
  "p": {
    "#text": "XXXXXXX ",
    "a": {
      "-href": "url",
      "-type": "external",
      "#text": "123456"
    },
    "#text1": ": YYYYYYY"
  },
  "#omit-xml-declaration": "yes"
}

javadev avatar Nov 21 '18 05:11 javadev

or maybe convert to a list :

{p: ["XXXX",{"a": {...}},"YYYYYY"]}

xgodon avatar Apr 03 '19 16:04 xgodon

However much I would like to use xmltodict, this issue makes it a no-go :/

briunsilo avatar Jan 20 '20 09:01 briunsilo