Full-time web dev; JS lover since 2002; CSS fanatic. #CSSIsAwesome
I try to stay up with new web platform features. Web feature you don't understand? Tell me! I'll write an article!
He/him
Couple thoughts. First, you may not need to; JavaScript has solid native support for dealing with XML documents. If you want to check that out, start with this MDN article on dealing with XML in JavaScript.
But if you really need to translate to JSON (or just want to, because let's be real, JSON is way easier to work with than XML), then the question is how you want to do it. XML has an extra feature that JSON doesn't have: attributes. You have to decide how you want to distinguish between element contents and attributes when you convert to JSON.
Hi @kenbellows I have tried the xml to json conversion using DOM parser in nodejs. After parsing it I have tried to get the get the node using document.getElementsByTagName.
But this is not working when my tag name is not in small case.
For eg: if my tagname is "Userprofile"
Can you please help me with this?
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Couple thoughts. First, you may not need to; JavaScript has solid native support for dealing with XML documents. If you want to check that out, start with this MDN article on dealing with XML in JavaScript.
But if you really need to translate to JSON (or just want to, because let's be real, JSON is way easier to work with than XML), then the question is how you want to do it. XML has an extra feature that JSON doesn't have: attributes. You have to decide how you want to distinguish between element contents and attributes when you convert to JSON.
David Walsh has an old blog post demonstrating his personal JavaScript function for converting XML to JSON. It uses a pretty popular method, which is to add a special property at each level that has attributes called
"@attributes"
and put the attribute values in there.Hi @kenbellows I have tried the xml to json conversion using DOM parser in nodejs. After parsing it I have tried to get the get the node using document.getElementsByTagName.
But this is not working when my tag name is not in small case.
For eg: if my tagname is "Userprofile"
Can you please help me with this?