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
<!DOCTYPE.*?>/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: