Skip to content
This repository has been archived by the owner on Jan 7, 2021. It is now read-only.

xml2json is losing textnodes #148

Open
denghauser opened this issue Oct 24, 2017 · 2 comments
Open

xml2json is losing textnodes #148

denghauser opened this issue Oct 24, 2017 · 2 comments

Comments

@denghauser
Copy link

denghauser commented Oct 24, 2017

When I have this XML
<foo attr=\"value\">bar<subnode val=\"test\" >glass</subnode></foo>
I would expect this JSON

{"foo":{"attr":"value","$t":"bar","subnode":{"val":"test","$t":"glass"}}} but I get:
{"foo":{"attr":"value","subnode":{"val":"test","$t":"glass"}}}

Losing the "$t":"bar"

I found in the code of xml2json.js -> endElement(name) ... that you delete the textNodeName element of the currentObject. Why would you do this? This removes all text elements but the one on the deepest child node.

Is this by design?

@corroded
Copy link

Also encountering this issue. It looks like it was added here: 8538475

to fix some spaces disappearing. It does not seem to be by design but a side effect.

@denghauser just curious, how did you address this on your end?

@javadev
Copy link

javadev commented Dec 5, 2018

<foo attr="value">bar<subnode val="test" >glass</subnode></foo>

may be converted to:

{
  "foo": {
    "-attr": "value",
    "#text": "bar",
    "subnode": {
      "-val": "test",
      "#text": "glass"
    }
  },
  "#omit-xml-declaration": "yes"
}

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

No branches or pull requests

3 participants