myXML =
<dgInfoList><DGRec0 desc="Analog Input 'AI 1 Slot2'" type="AI" dgType="AI" ordinal="25" facility="BRW_08_09_EFM" visible="1" webEnabled="0" dbKey="0000001510B0000043" device="BRW_08_09_EFM"/><DGRec1 desc="Analog Input 'Brown 8TBG'" type="AI" dgType="AI" ordinal="26" facility="BRW_08_09_EFM" visible="1" webEnabled="0" dbKey="0000001510B0000044" device="BRW_08_09_EFM"/><DGRec2 desc="Analog Input 'Brown 8CSG'" type="AI" dgType="AI" ordinal="27" facility="BRW_08_09_EFM" visible="1" webEnabled="0" dbKey="0000001510B0000045" device="BRW_08_09_EFM"/><DGRec3 desc="Analog Input 'Brown 9TBG'" type="AI" dgType="AI" ordinal="28" facility="BRW_08_09_EFM" visible="1" webEnabled="0" dbKey="0000001510B0000046" device="BRW_08_09_EFM"/><DGRec4 desc="Analog Input 'Brown 9CSG'" type="AI" dgType="AI" ordinal="29" facility="BRW_08_09_EFM" visible="1" webEnabled="0" dbKey="0000001510B0000047" device="BRW_08_09_EFM"/><DGRec5 desc="Basic Poll" type="BasicPoll" dgType="BasicPoll" ordinal="0" facility="BRW_08_09_EFM" visible="1" webEnabled="0" dbKey="0000001510B0000007" device="BRW_08_09_EFM"/><DGRec6 desc="Time / Date" type="DateTime" dgType="DateTime" ordinal="0" facility="BRW_08_09_EFM" visible="1" webEnabled="0" dbKey="0000001510B0000008" device="BRW_08_09_EFM"/><DGRec7 desc="GenTLP-Tbg Csg/BatVolt/BasicPoll" type="GenTLP" dgType="GenTLP" ordinal="3" facility="BRW_08_09_EFM" visible="1" webEnabled="0" dbKey="0000001510B0000048" device="BRW_08_09_EFM"/><DGRec8 desc="History Point List" type="HistPtCfg" dgType="HistPtCfg" ordinal="0" facility="BRW_08_09_EFM" visible="1" webEnabled="0" dbKey="0000001510B0000021" device="BRW_08_09_EFM"/><DGRec9 desc="I/O Point List" type="IoPntCfg" dgType="IoPntCfg" ordinal="0" facility="BRW_08_09_EFM" visible="1" webEnabled="0" dbKey="0000001510B0000042" device="BRW_08_09_EFM"/><DGRec10 desc="ROC Config" type="RtuConfig" dgType="RtuConfig" ordinal="1" facility="BRW_08_09_EFM" visible="1" webEnabled="0" dbKey="0000001510B0000022" device="BRW_08_09_EFM"/><DGRec11 desc="System Variables" type="SysVars" dgType="SysVars" ordinal="0" facility="BRW_08_09_EFM" visible="1" webEnabled="0" dbKey="0000001510B0000026" device="BRW_08_09_EFM"/><DGRec12 desc="AGA Flow Calc Values" type="AGAFlowVal" dgType="AGAFlowVal" ordinal="1" facility="BRW_08_09_TS_GM01" visible="1" webEnabled="0" dbKey="0000001510B0000001" device="BRW_08_09_EFM"/><DGRec13 desc="AGA Gas/Flow Parms '0624040002'" type="AGAParams" dgType="AGAParams" ordinal="1" facility="BRW_08_09_TS_GM01" visible="1" webEnabled="0" dbKey="0000001510B0000004" device="BRW_08_09_EFM"/><DGRec14 desc="GMR Configuration Send Data" type="GmrCfgSend" dgType="GmrCfgSend" ordinal="1" facility="BRW_08_09_TS_GM01" visible="1" webEnabled="0" dbKey="0000001510B0000009" device="BRW_08_09_EFM"/><DGRec15 desc="GMR Configuration Data" type="GmrConfig" dgType="GmrConfig" ordinal="1" facility="BRW_08_09_TS_GM01" visible="1" webEnabled="0" dbKey="0000001510B0000012" device="BRW_08_09_EFM"/><DGRec16 desc="GMR Events Data" type="GmrEvent" dgType="GmrEvent" ordinal="1" facility="BRW_08_09_TS_GM01" visible="1" webEnabled="0" dbKey="0000001510B0000015" device="BRW_08_09_EFM"/><DGRec17 desc="GMR History Data" type="GmrHist" dgType="GmrHist" ordinal="1" facility="BRW_08_09_TS_GM01" visible="1" webEnabled="0" dbKey="0000001510B0000018" device="BRW_08_09_EFM"/><DGRec18 desc="Meter Config Params (Basic)" type="MetCfg" dgType="MetCfg" ordinal="1" facility="BRW_08_09_TS_GM01" visible="1" webEnabled="0" dbKey="0000001510B0000031" device="BRW_08_09_EFM"/><DGRec19 desc="Meter Config Params (Extra 107)" type="MetCfg107" dgType="MetCfg107" ordinal="1" facility="BRW_08_09_TS_GM01" visible="1" webEnabled="0" dbKey="0000001510B0000033" device="BRW_08_09_EFM"/><DGRec20 desc="Meter Flow Values (Basic)" type="MetFlow" dgType="MetFlow" ordinal="1" facility="BRW_08_09_TS_GM01" visible="1" webEnabled="0" dbKey="0000001510B0000035" device="BRW_08_09_EFM"/><DGRec21 desc="Meter Flow Values (Extra 107)" type="MetFlowE" dgType="MetFlowE" ordinal="1" facility="BRW_08_09_TS_GM01" visible="1" webEnabled="0" dbKey="0000001510B0000037" device="BRW_08_09_EFM"/><DGRec22 desc="Run Parameters '0624040002'" type="RunParm" dgType="RunParm" ordinal="1" facility="BRW_08_09_TS_GM01" visible="1" webEnabled="0" dbKey="0000001510B0000023" device="BRW_08_09_EFM"/><DGRec23 desc="Extra Run Parameters '0624040002" type="XRunParm" dgType="XRunParm" ordinal="1" facility="BRW_08_09_TS_GM01" visible="1" webEnabled="0" dbKey="0000001510B0000027" device="BRW_08_09_EFM"/></dgInfoList>
对于DGRec#
中的每一个,我希望得到dgType
的值。
似乎无法弄清楚如何使用XMLDOM来实现这一目标。
Set xmlDoc1 = CreateObject("Msxml2.DOMDocument")
xmlDoc1.setProperty "SelectionLanguage", "XPath"
xmlDoc1.loadXML(myXML)
答案 0 :(得分:1)
只需使用XPath expression
选择属性(@dgType
)
myXML = "<dgInfoList><DGRec0 ... device=""BRW_08_09_EFM""/></dgInfoList>"
Set xml = CreateObject("Msxml2.DOMDocument.6.0")
xml.async = False
xml.loadXML myXML
If xml.ParseError <> 0 Then
WScript.Echo xml.ParseError.Reason
WScript.Quit 1
End If
For Each node In xml.SelectNodes("//*[@dgType='GmrHist']")
WScript.Echo node.getAttribute("dgType")
WScript.Echo node.getAttribute("ordinal")
Next
请记住,XPath表达式区分大小写。