xml2json is losing textnodes
denghauser opened this issue · 2 comments
denghauser commented
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 commented
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 commented
<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"
}