Reputation: 133
My parseFromString returns 'undefined', neither '<parsererror…' nor parsed xml!
I can´t find the reason. Can you help, please?
var parser = new DOMParser(), // https://developer.mozilla.org/en-US/docs/Web/API/DOMParser
_sourceDOC = null;
alert('_sourceXML: "' + _sourceXML.innerHTML + '"'); // returns string with xml source :-)
_sourceDOC = parser.parseFromString(_sourceXML.innerHTML,"text/xml");
alert('parseFromString: ' + _sourceDOC.xml); // returns 'undefined', neither '<parsererror…' nor parsed xml!
The first alert:
PS: On the other hand, this works as expected. But I use Firefox 17 and don't want to use ActiveX.
var xmlDocIE = new ActiveXObject("Msxml2.FreeThreadedDOMDocument.6.0");
xmlDocIE.async = false;
xmlDocIE.loadXML(_sourceXML.innerHTML);
PPS: Solution:
var parser = new DOMParser(),
_sourceDOC = null,
serializer = new XMLSerializer (),
_sourceDOC = parser.parseFromString(_sourceXML.innerHTML,"text/xml");
str = serializer.serializeToString (_sourceDOC);
alert('parseFromString: ' + str); // Result as expecded! :-)
As a consequence, I replaced the wrong code (resultDoc.xml) in my script:
_destination.innerHTML = resultDoc.xml;
by the correct code, and it works fine:
_destination.replaceChild(resultDoc, _destination.childNodes[0]);
Thanks, user1279647!
Upvotes: 1
Views: 953
Reputation: 511
I think this property is only for IE (http://help.dottoro.com/ljhwhicc.php). Maybe you should use XMLSerializer
Upvotes: 2