我正在尝试读取节点的内容,并验证其是否为空或值为“ TBD”。
我正在使用selectSingleNode,但是即使打印出currNode.text时,if语句似乎始终会导致null,即使看到了文本也是如此。
var xmlDoc = new ActiveXObject("Msxml2.DOMDocument");
xmlDoc.async = false;
xmlDoc.resolveExternals = false;
xmlDoc.loadXML(xmlString);
if (xmlDoc.parseError.errorCode > 0)
{
var myErr = xmlDoc.parseError;
g_ASILog.print(3,"Parse Error=" + myErr);
return(0);
}
else
{
xmlDoc.setProperty("SelectionLanguage", "XPath");
}
currNode = xmlDoc.selectSingleNode("//Classification/"+activity);
var currNodeString = new String(null);
currNodeString = ToString(currNode.text);
g_ASILog.print(3,"Checking attribute " + checkValue +" = "+ currNodeString);
if (currNodeString == null || "TBD")
{
g_ASILog.print(3,"Failed to find " + checkValue + currNodeString);
return(1);
}
else
{
g_ASILog.print(3,checkValue + " has passed");
return(0);
}
XML示例:
<Classification>
<id>-99999</id>
<name>ERDPRESS 006</name>
<dataset_id />
<temp_dataset_id>1</temp_dataset_id>
<study_id>110</study_id>
<temp_study_id />
<document_id>20001</document_id>
<format />
<type>PROCESSED</type>
<activity>UNK</activity>
<category>DESCRIPTIONS</category>
</Classification>
只是不确定我在做什么错。 谢谢。