开发者

How to evaluate Xpath when DOCTYPE present in XML declaration

I have problem with evaluation XPath expression in Windows Script Host using JScript when is present on top of document. When I remove DOCTYPE parsing doesnt break. Here is sample of code that I am using to parse and load xml. Is there any way to parse this kind of XML witout removing DOCTYPE declaration.

I dont want to delete DOCTYPE while processing. Solution could be to remove DOCTYPE using Regex <!DOCTYP开发者_StackOverflow中文版E.*?>/gm; but I dont want solution like that.

var XmlDocument;
    try {
        XmlDocument = new ActiveXObject("msxml2.DOMDocument.6.0");
        XmlDocument.async = false;
        XmlDocument.resolveExternals = false;
        XmlDocument.validateOnParse = false;
    } catch(e) {
        if(debug == true)
            WScript.echo("***ERROR while creating DOM Object: " + e.description);
    }
    // Load an XML file into the DOM instance
    try {
        XmlDocument.load(filePath);
    } catch(e) {
        if(debug == true)
            WScript.echo("***ERROR LOADING FILE: " + e.description);
    }
    var Node;
    try {
        Node = XmlDocument.selectSingleNode("//metadata/url");
    } catch(e) {
        if(debug == true)
            WScript.echo("***ERROR RESOLVING NODE: " + e.description);
    }
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE rightinclude SYSTEM "http://localhost/iw/aa.dtd">
<a>
    <b>
        <c>/someurl.html</c>
    </b>
</a>


Have you tried it when the DOCTYPE element is closed - some parsers will take the document in this case.

e.g:

<!DOCTYPE rightinclude SYSTEM "http://localhost/iw/aa.dtd" />


No need to modify any thing in the XML File, instead use this manner to parse your file and everything would be good to go.

Here's a link with description and details regarding:

  • Java XPath Parser
  • Parse XML Document
  • Query XML Document
  • Create XML Document
  • Modify XML Document

Cheers ;-)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜