question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is there a way to keep order of mixed and repeating tags?

See original GitHub issue

Example 🍔

<DoubleCheeseburger>
    <Bread/>
    <Cheese/>
    <Beef/>
    <Cheese/>
    <Beef/>
    <Bread/>
</DoubleCheeseburger>
import xmltodict, json
data = xmltodict.parse(double_cheeseburger_xml)
print(json.dumps(data, indent=3))
{
   "DoubleCheeseburger": {
      "Bread": [
         null,
         null
      ],
      "Cheese": [
         null,
         null
      ],
      "Beef": [
         null,
         null
      ]
   }
}

Can we tell the order of each Bread, Cheese and Beef with respect to each other not only within the same tag, but also in the parent node (DoubleCheeseburger)?

If not, is there a way to monkeypatch to write it down?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:1
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

7reactions
lindsay-stevenscommented, Sep 19, 2016

@andreif: I needed the same feature and wrote a patch for that, the branch is on my fork here: https://github.com/lindsay-stevens/xmltodict/tree/ordered-children-short-tags

It’s got a flag to deal with mixed child ordering on parse and unparse. During parse it’ll add an @order attribute, on unparse it’ll remove the attribute and sort the mixed nodes. Also has a bonus XHTML-ish feature to enable output of short-form of empty tags, e.g. “<tag/>” vs. “<tag></tag>”

Not opened a PR for it yet since my previous one is still open and I didn’t want to be annoying.

3reactions
andreifcommented, Sep 4, 2016

Some services do require certain order of children unfortunately.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Does the order of tags matter? - Meta Stack Exchange
No, the order you add the tags doesn't matter because you don't actually get to set the order of the tags. Tag order...
Read more >
Repeat item labels in a PivotTable - Microsoft Support
Right-click the row or column label you want to repeat, and click Field Settings. Click the Layout & Print tab, and check the...
Read more >
order - CSS: Cascading Style Sheets - MDN Web Docs
Since order is only meant to affect the visual order of elements and not their logical or tab order. order must not be...
Read more >
Etsy SEO: Should you repeat keywords? - TIZZIT
You will have to look at the keyword data and figure out how the keyword mix at the listing level will work together...
Read more >
Shuffle an array with python, randomize array item order with ...
Advantage: You can random multiple arrays simultaneously without disrupting the mapping. And 'random_state' can control the shuffling for reproducible ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found