Leonidas-from-XIV / node-xml2js

XML to JavaScript object converter.
MIT License
4.9k stars 606 forks source link

Missing : Missing Order when child element is combination of Text and Element in Processing XML To Json #340

Open ChakralaKartheek opened 8 years ago

ChakralaKartheek commented 8 years ago

I have a use case in XML , where XML element has Text and element as child elements.

Example

<APPUser> I am <TextValue Elment="UserName"></UserName>. I am <TextValue Element="Gender"> <TextValue > </APPUser>

When I convert this kind of XMLto JSON, It is resulting like this

`APPUser {

  TextValue : [{ Element : UserName"},{Elment:Gender}],

  Value : I am . I am

}`

I don't want it to be grouped, and i want result should be in sequential order like this

`APPUser { Value : I am TextValue : { Element : UserName"} Value : . I am TextValue : ,{Elment:Gender},

}`

is this possible with existing version of xml2js ?

maa105 commented 7 years ago

if u only care for json use options like so: parser = new xml2js.Parser({ explicitChildren: true, preserveChildrenOrder: true, charsAsChildren: true }); note the output format will change. but the order remains the same. but if you want to convert back to xml you are out of luck :( +1 to fix this

discreteinfinity commented 7 years ago

Is this a limitation of this library's implementation ? Do other parser's handle this better ?

I have a format like : `

string

string


string

string

`

I thought that Id be able to use a valueProcessor to pull the contents of item2 as a string (I dont care about parsing the html inside item2 and I need to preserve it) but it doesn't seem to be the case as the valueProcessor gets called after the contents of <p> are grouped together.

Am I missing something or do I need another library ?

witwave commented 7 years ago

how to fix this question? did you find the answer for the question @ChakralaKartheek

witwave commented 7 years ago

@discreteinfinity did u fix this question?

hjy1210 commented 7 years ago

@maa105 So xml2js is not bidirectonal?

maa105 commented 7 years ago

@hjy1210 if node order is a must for you it wont work otherwise it is

Leonidas-from-XIV commented 5 years ago

I agree.