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

xml2json is losing textnodes #148

Open

Description

@denghauser

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?

Activity

  1. corroded commented on May 24, 2018

    @corroded

    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?

  2. javadev commented on Dec 5, 2018

    @javadev
    <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 join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions