Skip to content
This repository was archived by the owner on Feb 12, 2022. It is now read-only.
This repository was archived by the owner on Feb 12, 2022. It is now read-only.

to_xml() always adds root <data> ... </data> #5

Description

@AlexBravo

For versatility, it would be great to have an option of not adding <data></data> by default.
Maybe it should be an option, where if "" is specified, no <data></data> is created, if "root" is specified, <root></root> will be created.

Activity

  1. adamalex commented on Jul 27, 2013

    @adamalex
    Contributor

    Good point, I really like the idea of making the root name configurable as in your <root></root> example. That would be simple to implement.

    Allowing for no root element at all would be less clean to implement, mainly because that isn't valid XML. Could you let us know the use case for this? If it's important to have we can certainly give it some thought. Thanks for the idea!

  2. AlexBravo commented on Jul 29, 2013

    @AlexBravo
    Author

    Allowing for no root element at all would be less clean to implement, mainly because that isn't valid XML. Could you let us know the use case for this?

    My use case is pretty simple:
    I have an XML document that has one root element:

    <entry>
       ...
    </entry>
    

    I convert this document to JSON using node-xmljson.
    Then I convert this JSON back to XML. I get this result:

    <data>
       <entry>
          ...
       </entry>
    </data>
    

    If root element could be configurable, I could convert entries inside of entry JSON object to XML with specifying root element as "entry". But this workaround is less than optimal.

  3. adamalex commented on Jul 31, 2013

    @adamalex
    Contributor

    Got it, <entry> ... </entry> should probably translate to { ... } the same way <data> ... </data> does. Then, going from JSON to XML { ... } should be able to translate back to <entry> ... </entry> if we allow specifying a name for the root element (as you suggest). Does that cover it or is this approach what you feel is less than optimal? If so, what do you think would be more optimal?

  4. atorres757 commented on Jul 14, 2014

    @atorres757

    Hello,
    I'm running into the same issue and I think that sounds like a good solution. However, would it make it easier to use the first property as the root node when converting to xml? I think either solution would work.

    Thanks

  5. mahanthsh commented on Jun 2, 2016

    @mahanthsh

    Hello,

    Interested in this too.Please let us know if you plan to add them.

    Thanks

  6. sd-chandran commented on Aug 7, 2018

    @sd-chandran

    Hello,
    I am also running the same issue. How to skip the root element <data></data> while converting JSON to XML?

    Thanks.

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