sanand0 / xmljson

xmlsjon converts XML into Python dictionary structures (trees, like in JSON) and vice-versa.
MIT License
121 stars 33 forks source link

XML namespaces getting injected into attribute names - parker covention #35

Open LaughingBubba opened 5 years ago

LaughingBubba commented 5 years ago

Hi, after reading issues #1 , #8 and PR #9 I think I have a different issue.

Essentially this:

<EML xmlns="urn:oasis:names:tc:evs:schema:eml" >
  <TransactionId>B313CBA4-BCA9-4B8F-8C50-BADE9423A020</TransactionId>
</EML>

becomes this:

{
  "{urn:oasis:names:tc:evs:schema:eml}TransactionId": "B313CBA4-BCA9-4B8F-8C50-BADE9423A020"
}

where as I was actually expecting this:

{
  "TransactionId": "B313CBA4-BCA9-4B8F-8C50-BADE9423A020"
}

Am I missing something?

dagwieers commented 5 years ago

So you want to ignore namespaces. What if the same element is used in different namespaces, they would end up being the same.

LaughingBubba commented 5 years ago

Hi In the 5 - 6 different xml files I'm dealing with, what you describe does not occur. Also as this I'm specifically using the Parker covention, I would have thought that name spaces would have been discarded along with the root element. If I'd used the preserve root element, not so much..

Thoughts?

javadev commented 5 years ago

Hi,

<EML xmlns="urn:oasis:names:tc:evs:schema:eml" >
  <TransactionId>B313CBA4-BCA9-4B8F-8C50-BADE9423A020</TransactionId>
</EML>

may be converted to json

 {
  "EML": {
    "-xmlns": "urn:oasis:names:tc:evs:schema:eml",
    "TransactionId": "B313CBA4-BCA9-4B8F-8C50-BADE9423A020"
  },
  "#omit-xml-declaration": "yes"
}
LaughingBubba commented 5 years ago

Thanks @javadev that would be the result I would expect if I'd used the option preserve_root=True option. @sanand0 & @dagwieers happy to do a PR but might need some guidance as I'm relatively new to Python but not new to PRs and XML/JSON

LaughingBubba commented 5 years ago

Strike my last comment xmltodict is effectively parker convention without the annoying (and superfluous) namespace injections. Consider this closed but thanks for the work done on this library and your time to read this.

sanand0 commented 5 years ago

Thanks @LaughingBubba

The way xmltodict handles namespaces is elegant. I'm re-opening this issue to apply the same for all conventions. Not sure when we'll get this done, but this is definitely useful.