我有一些xml字符串,我喜欢在asp VBscript中转换为XML对象。 然后我喜欢根据父项的id属性访问子项:
final InputStream inputStream = Signer.class.getClassLoader().getResourceAsStream("opensc-java.cfg");
final SunPKCS11 pkcs11 = new SunPKCS11(inputStream);
final KeyStore ks = KeyStore.getInstance("PKCS11", pkcs11);
ks.load(null, "*****".toCharArray());
例如,我想获取信息id =“dat2”new_val值。
…
<subset>
<subtitle>DEMAND</subtitle>
<information id="dat1" timestamp="2017-01-26T10:00:00.000-05:00">
<info_title>Market Demand</info_title>
<new_val>19887.4</new_val>
<old_val>19584.3</old_val>
</information>
<information id="dat2" timestamp="2017-01-26T10:45:00.000-05:00">
<info_title>5-Minute Market Demand</info_title>
<new_val>19742.2</new_val>
<old_val>19712.7</old_val>
</information>
<information id="dat3" timestamp="2017-01-26T10:00:00.000-05:00">
<info_title>Ontario Demand</info_title>
<new_val>17204.7</new_val>
<old_val>17076.4</old_val>
</information>
</subset>
…
此代码段为我提供了第一个new_val的值,但是如何指定获取信息的值id =“dat2”?
答案 0 :(得分:2)
您可以使用xpath执行selectSingleNode method查询。
这样的事情:
objXML.setProperty "SelectionLanguage", "XPath"
set objNode = objXML.selectSingleNode("/subset/information[@id='dat2']/new_val")
if not objNode is nothing then
MsgBox objNode.text
end if