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

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

Open
AlexBravo opened this issue Jul 25, 2013 · 6 comments
Open

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

AlexBravo opened this issue Jul 25, 2013 · 6 comments

Comments

@AlexBravo
Copy link

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.

@adamalex
Copy link
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!

@AlexBravo
Copy link
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.

@adamalex
Copy link
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?

@atorres757
Copy link

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

@mahanthsh
Copy link

Hello,

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

Thanks

@sudhakar-sekar
Copy link

sudhakar-sekar commented Aug 7, 2018

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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants