Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Position of elements inside #text is lost #247

Open
j0hannes opened this issue May 14, 2020 · 3 comments
Open

Position of elements inside #text is lost #247

j0hannes opened this issue May 14, 2020 · 3 comments

Comments

@j0hannes
Copy link

Example:

print(json.dumps(xmltodict.parse('<x>a <b>c</b> d</x>'), indent=2)){
  "x": {
    "b": "c",
    "#text": "a  d"
  }
}

How do I know that "c" goes between "a " and " d"?

@javadev
Copy link

javadev commented Jun 20, 2020

It may be other json.

{
  "x": {
    "#text": "a ",
    "b": "c",
    "#text1": " d"
  },
  "#omit-xml-declaration": "yes"
}

@hholst80
Copy link

hholst80 commented Dec 9, 2021

The solution to this could be to make x a list of objects.

{
  "x": [
    { "#text": "a " },
    { "b": "c" },
    { "#text": " d" }
  ]
}

@gdh1995
Copy link

gdh1995 commented Sep 13, 2022

I also expect this, because some of my XML looks like:

<list>
  <key>1</key>
  <value>results 1<value>
  <key>2</key>
  <value>results 2<value>
<list>

And the order is decided by other applications and can not be changed.

I suggest a new syntax of:

{
  "$list": [
     { "#comment": "1" },
     { "key": 1 },
     "text data",
     { "value": "..." }
  ]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants