Error caused by Microsoft.XMLDOM XML parser in Edge with XML string content

I am getting the following error with Microsoft.XMLDOM XML Parser in Microsoft EDGE:

Script(1,1)

Sometimes he talks start tag does not match end tag

. And in other cases, it gives another error. I wish I could imagine the actual error messages, but I am far from a Windows machine and this is what I remember from memory.

The same XML content works in Firefox and other browsers. Can anyone see what's going on? This could be an easy fix, but again I don't have a Windows computer.

Here is my XML:

<s:RichText x="118" visible="true" y="238" text="Text" fontSize="58.73271028037384">
    <s:filters>
        <BorderStrokeFilter alpha="1" angle="45" blurX="3" blurY="3" color="#FFFFFF" distance="0" hideObject="false" inner="false" knockout="false" multiplier="6" quality="3" strength="30" weight="3" xmlns="library://ns.flexcapacitor.com/flex"/>
        <BorderStrokeFilter alpha="1" angle="45" blurX="3" blurY="3" color="#000000" distance="0" hideObject="false" inner="false" knockout="false" multiplier="6" quality="3" strength="30" weight="3" xmlns="library://ns.flexcapacitor.com/flex"/>
    </s:filters>
    <s:textFlow>
        <s:TextFlow whiteSpaceCollapse="preserve" version="3.0.0" xmlns:s="library://ns.adobe.com/flex/spark"><s:p><s:span s:fontWeight="bold">Here is some text</s:span></s:p></s:TextFlow>
    </s:textFlow>
</s:RichText>

      

Here is my verification method:

function validateXML(txt) {

    // code for IE
    if (window.ActiveXObject) {
        var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
        xmlDoc.async = "false";
        xmlDoc.loadXML(txt);

        if (xmlDoc.parseError.errorCode != 0) {
            txt = "Error Code: " + xmlDoc.parseError.errorCode + "\\n";
            txt = txt + "Error Reason: " + xmlDoc.parseError.reason;
            txt = txt + "Error Line: " + xmlDoc.parseError.line;
            return txt;
        }
        else {
            return "No errors found";
        }
    }
    // Mozilla, Firefox, Opera, etc.
    else if (document.implementation.createDocument) {
        var parser = new DOMParser();
        var xmlDoc = parser.parseFromString(txt, "text/xml");

        if (xmlDoc.getElementsByTagName("parsererror").length > 0) {
            return xmlDoc.getElementsByTagName("parsererror")[0];
        }
        else {
            return "No errors found";
        }
    }
    else {
        return "Your browser does not support XML validation";
    }
}


var xml = '<s:RichText x="118"></s:RichText>';
var result = validateXML(xml);

      

Can someone with Windows 10 run this? I created a codepen here .

0


source to share


1 answer


There was an error in my other code that was causing the error I was facing, but I also found out that when an error occurs in Edge or IE, they will log the error to the console.

In addition, IE 10 or 11 DOMParser support is supported. The solution is to toggle the conditions of the if statement to check the Domparser

if (window.DOMParser || document.implementation.createDocument)

and then put a try catch block around the parse method.



Although it doesn't seem like IE is giving row or column error information. I have not been able to test it extensively.

Updated codepen :

function validateXML(txt) {


    // Mozilla, Firefox, Opera, newer IE and Edge, etc.
    if (document.implementation.createDocument) {
        console.log("Before creating domparser");
        var parser = new DOMParser();
        try {
            var xmlDoc = parser.parseFromString(txt, "text/xml");
        } catch(error) {
            console.log(error);
        };

        console.log("After DomParser instance. Errors: "+ xmlDoc.getElementsByTagName("parsererror").length);
        if (xmlDoc.getElementsByTagName("parsererror").length > 0) {
            return xmlDoc.getElementsByTagName("parsererror")[0];
        }
        else {
            return "No errors found";
        }
    }
    // code for older IE
    else if (window.ActiveXObject) {
        var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
        xmlDoc.async = "false";
        xmlDoc.loadXML(txt);

        if (xmlDoc.parseError.errorCode != 0) {
            txt = "Error Code: " + xmlDoc.parseError.errorCode + "\\n";
            txt = txt + "Error Reason: " + xmlDoc.parseError.reason;
            txt = txt + "Error Line: " + xmlDoc.parseError.line;
            console.log("I work in Windows IE");
            return txt;
        }
        else {
            return "No errors found";
        }
    }
    else {
        return "Your browser does not support XML validation";
    }
}


var xml = '<s:RichText x="118" xmlns:s="f">test</f/></s:RichText>';
var result = validateXML(xml);
console.log(result); 
if (typeof result == "string") {
  document.body.innerHTML = "<pre>"+result+"</pre>";
}
else {
  document.body.innerHTML = "<pre>"+result.outerHTML+"</pre>";
}

      

0


source







All Articles