Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ChakralaKartheek opened this issue Oct 20, 2016 · 7 comments

Comments

@ChakralaKartheek
Copy link

ChakralaKartheek commented Oct 20, 2016

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
Copy link

maa105 commented Nov 30, 2016

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
Copy link

discreteinfinity commented Dec 20, 2016

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

I have a format like :
<key name='key name'> <item1>string</item1> <item2><p>string</p><br>string<p>string</p></item2> </key>

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
Copy link

witwave commented Mar 29, 2017

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

@witwave
Copy link

witwave commented Mar 29, 2017

@discreteinfinity did u fix this question?

@hjy1210
Copy link

hjy1210 commented Jul 1, 2017

@maa105 So xml2js is not bidirectonal?

@maa105
Copy link

maa105 commented Jul 5, 2017

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

@Leonidas-from-XIV
Copy link
Owner

I agree.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants