I have a requirement to access parts of a XML fragment that is stored in a hidden HTML element on a page. The access to the data in the XML is to be via xPath. For the sake of this example, I would like to extract the data from /root/more-data/data1 element\[code\]<div id="hiddenXMLData" style="display: none;"> <root> <main-data> <summary name="name1" type="amount">0</summary> <summary name="name2" type="years">34</summary> <summary name="name3" type="count">0</summary> <summary name="name4" type="count">0</summary> <summary name="name5" type="amount">0</summary> <summary name="name6" type="amount">0</summary> <summary name="name7" type="count">0</summary> <summary name="name8" type="count">0</summary> <summary name="name9" type="count">0</summary> <summary name="name10" type="count">0</summary> <summary name="name11" type="count">0</summary> <summary name="name12" type="count">0</summary> <summary name="name13" type="months" /> <summary name="name14" type="count">0</summary> <summary name="name15" type="amount">0</summary> <summary name="name16" type="amount">0</summary> <summary name="name17" type="count">0</summary> <summary name="name18" type="count">0</summary> <summary name="name19" type="count">0</summary> <summary name="name20" type="count">0</summary> <summary name="name21" type="count">0</summary> <summary name="name22" type="count">0</summary> <summary name="name23" type="months" /> <summary name="name24" type="count">0</summary> <summary name="name25" type="count">0</summary> <summary name="name26" type="count">0</summary> <summary name="name27" type="count">4</summary> <summary name="name28" type="count">3</summary> <summary name="name29" type="count">4</summary> <summary name="name30" type="count">4</summary> <summary name="name31" type="count">4</summary> <summary name="name32" type="months">0</summary> <summary name="name33" type="count">0</summary> <summary name="name34" type="count">0</summary> <summary name="name35" type="count">0</summary> <summary name="name36" type="match">not requested</summary> <summary name="name37" type="match">not requested</summary> <summary name="name38" type="match">not requested</summary> </main-data> <more-data> <data1>OVR30</data1> <data2>+003.57</data2> <data3>+001.28</data3> <data4>0013.30</data4> </more-data> </root></div>\[/code\]the javascript/jQuery being used to get to the data I need\[code\]function getXMLValueWithXPath(XMLString, xPath) { var xmlDoc; var returnValue; //Browsers seem to create the XML doc entirely in lowerCase?! (Firefox,Chrome, //IE9), so lowercase the xPath to match xPath = xPath.toLowerCase(); if (document.evaluate) { var parser = new DOMParser(); xmlDoc = parser.parseFromString(XMLString, "text/xml"); var node1 = xmlDoc.evaluate(xPath, xmlDoc, null, XPathResult.STRING_TYPE, null); if (node1 != null) { returnValue = http://stackoverflow.com/questions/12507332/node1.stringValue; } } else // Internet Explorer { xmlDoc = new ActiveXObject("Msxml2.DOMDocument.6.0"); xmlDoc.async = false; xmlDoc.loadXML(XMLString); if ($.browser.version < 9) { //IE7 and IE8 uppercase the xml??!, so uppercase the xpath to match xPath = xPath.toUpperCase(); } var node2 = xmlDoc.selectSingleNode(xPath); if (node2 != null) { returnValue = http://stackoverflow.com/questions/12507332/node2.text; } } return returnValue;}\[/code\]How the function will be called\[code\]getXMLValueWithXPath($('#hiddenXMLData').html(), '/root/more-data/data1')\[/code\]Now this works fine in IE 7,8,9, (and going into a different part of the function anyway) but I am having a problem getting it to work in any other browser.The problem is when the parser.parseFromString(XMLString, "text/xml"); line executes, the resulting XML is not formed the same as supplied. The empty summary tags (self closed) are no longer self closing inadvertently created child elements that did not exist before. The problem is that because the structure has now changed, the xPath won't work. I have created a fiddle for an example, which alerts the value obtained from the xml and populates a textarea with the XML that was parsed here http://jsfiddle.net/6EhcD/7/The resulting XML (in browsers other than IE) now looks like this (with indention so that it is easier to see)\[code\]<root> <main-data> <summary name="name1" type="amount">0</summary> <summary name="name2" type="years">34</summary> <summary name="name3" type="count">0</summary> <summary name="name4" type="count">0</summary> <summary name="name5" type="amount">0</summary> <summary name="name6" type="amount">0</summary> <summary name="name7" type="count">0</summary> <summary name="name8" type="count">0</summary> <summary name="name9" type="count">0</summary> <summary name="name10" type="count">0</summary> <summary name="name11" type="count">0</summary> <summary name="name12" type="count">0</summary> <summary name="name13" type="months"> <summary name="name14" type="count">0</summary> <summary name="name15" type="amount">0</summary> <summary name="name16" type="amount">0</summary> <summary name="name17" type="count">0</summary> <summary name="name18" type="count">0</summary> <summary name="name19" type="count">0</summary> <summary name="name20" type="count">0</summary> <summary name="name21" type="count">0</summary> <summary name="name22" type="count">0</summary> <summary name="name23" type="months"> <summary name="name24" type="count">0</summary> <summary name="name25" type="count">0</summary> <summary name="name26" type="count">0</summary> <summary name="name27" type="count">4</summary> <summary name="name28" type="count">3</summary> <summary name="name29" type="count">4</summary> <summary name="name30" type="count">4</summary> <summary name="name31" type="count">4</summary> <summary name="name32" type="months">0</summary> <summary name="name33" type="count">0</summary> <summary name="name34" type="count">0</summary> <summary name="name35" type="count">0</summary> <summary name="name36" type="match">not requested</summary> <summary name="name37" type="match">not requested</summary> <summary name="name38" type="match">not requested</summary> <more-data> <data1>OVR30</data1> <data2>+003.57</data2> <data3>+001.28</data3> <data4>0013.30</data4> </more-data> </summary> </summary> </main-data></root>\[/code\]bit stumped by this one. Seems to be very strange behaviour, unless I'm missing something obvious. I was hoping that a few more pairs of eyes here on SO would be able to helpThanks in advance