Comments on: How to Convert XML to a JSON-Like JavaScript Objecthttps://www.sitepoint.com/how-to-convert-xml-to-a-javascript-object/
Learn CSS | HTML5 | JavaScript | Wordpress | Tutorials-Web Development | Reference | Books and MoreFri, 09 Dec 2016 15:29:00 +0000hourly1https://wordpress.org/?v=4.4.2By: Onlinekreditehttps://www.sitepoint.com/how-to-convert-xml-to-a-javascript-object/#comment-81524
Thu, 03 Nov 2011 12:45:43 +0000http://www.sitepoint.com/?p=46262#comment-81524This is exactly I was looking for. Actually I use currently JQuery for the customers website. Therefore it would be better to use the jquery plugin. I will try both variants.
]]>By: JoeZimJShttps://www.sitepoint.com/how-to-convert-xml-to-a-javascript-object/#comment-81523
Mon, 31 Oct 2011 20:11:31 +0000http://www.sitepoint.com/?p=46262#comment-81523Beautiful. I was actually thinking about something like this. I hate XML with a passion. Way too many characters to show data that JSON can show just as easily with fewer characters. But if you need to use it then this is a great way to get around its ugliness. I’ll have to make a mention of this on my JavaScript blog at http://www.joezimjs.com.
]]>By: Craig Bucklerhttps://www.sitepoint.com/how-to-convert-xml-to-a-javascript-object/#comment-81522
Fri, 21 Oct 2011 08:26:30 +0000http://www.sitepoint.com/?p=46262#comment-81522You could use XSL but, in my experience, it can fail in some browsers. Opera was always problematical for me, although later versions might be better. However, assuming it does work, I doubt it’ll be faster. As well as performing the transformation, the resulting string must be evaluated into a JavaScript object using JSON.parse or eval.

In an ideal world you wouldn’t need JavaScript to do this since your web service would return JSON and everyone would be happy! Unfortunately, that’s not always the case. For example, many Microsoft systems use SOAP and don’t offer a JSON option.

]]>By: Craig Bucklerhttps://www.sitepoint.com/how-to-convert-xml-to-a-javascript-object/#comment-81521
Fri, 21 Oct 2011 08:20:10 +0000http://www.sitepoint.com/?p=46262#comment-81521Thanks for the link, Perry. It looks as though it’s doing much the same – although there are a few more options, debugging messages and the code’s considerably longer.
]]>By: Sébastienhttps://www.sitepoint.com/how-to-convert-xml-to-a-javascript-object/#comment-81520
Thu, 20 Oct 2011 21:59:18 +0000http://www.sitepoint.com/?p=46262#comment-81520You could also use a XSL stylesheet that will transform the XML (and take care of attributes and children) into a well-formatted JSON with ease (and very few lines), instantiate the DOM parser with Javascript to make the transformation happen and you are good to go.

In some cases you won’t be able to use a XSL stylesheet, but when you can I think it’s much more appropriate to parse and transform XML than Javascript. Actually, Javascript isn’t the right tool for this particular case IMHO.

]]>By: Perryhttps://www.sitepoint.com/how-to-convert-xml-to-a-javascript-object/#comment-81519
Thu, 20 Oct 2011 16:36:45 +0000http://www.sitepoint.com/?p=46262#comment-81519You could also take the jQuery route using the XML to JSON plugin.http://www.fyneworks.com/jquery/xml-to-json
I know, this doesn’t do a lot in the way of honing your JavaScript skills but it’s a nice shortcut.
]]>