javascript - DOMParser.parseFromString fails with XML5619: Incorrect document syntax -


I have this javascript function that gets an XML file from the Web site:

  GetCCDfromHV () {var xmlhttp; If (window.XMLHttpRequest) xmlhttp = new XMLHttpRequest (); // IE 7+, Firefox, Chrome, Opera, Safari and XML HPP = new ActiveX object ("Microsoft. XMLHttp"); // code IE6, IE5 xmlhttp.onreadystatechange = function () {if (xmlhttp.readyState == 4); & Amp; Xmlhttp.status == 200) {var xml = xmlhttp.responseText; Document.getElementById ("uploadResponse") innerHTML = xml XmlDom = createXmlDOM (xml); }} Xmlhttp.open ("GET", "../ HVRawConnectorPHP / demo_app / GetCCDfromHV.php", true); Xmlhttp.send (); }  

The XML has been recovered properly because I dump it. Can I see WinnerHTML But the parsefost string of XmlDOM with "XML5619: incorrect document syntax" fails, as shown below:

  create a function XMLml (xml) {console.log ('createXmlDOM: first 255 Character = '+ xml.substring (0255)); If (window. DOMParser) {var parser = new dumpparser (); XmlDom = parser.parseFromString (xml, "text / xml"); // Failed with XML5619: Incorrect Document Syntax} Else {// Internet Explorer xmlDom = New ActiveXObject ("Microsoft.XMLDOM"); XmlDom.async = false; XmlDom.loadXML (xml); } Return xmlDom; }  

But if I Copy the HTML text and paste it into an editor and save it as a text file, then load that file using the file reader, then send the text XmlDOM to create it, it works fine!

In some way, a translation of some sort of cutting and pasting or writing and reading the file translates into something that makes it acceptable to transform. Is there a way to do this without saving and reloading the file? It seems that the first character is likely to fail, which is' & amp; Because the first letter is actually '& lt;' But there is a change in HTML which does not load it from a text file.

I finally thought it out. XML will have to decode HTML. I added the following function:

  function html decode (input) {var e = document.createElement ('div'); E.innerHTML = Input; Return e.childNodes.length === 0? "": E.childNodes [0] .nodeValue; }  

which I found from here:


Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -