【发布时间】:2013-12-13 17:19:04
【问题描述】:
我知道这与很多问题有关,但我找不到像我这样使用 xml 布局的示例。
<product name="ANALYTICS" count="24" occurred_at_time="1386648300000">
<user_type name="Unknown" count="24" occurred_at_time="1386648300000">
<session_source name="Web" count="24" occurred_at_time="1386648300000"/>
</user_type>
</product>
<product name="CARSWELL" count="492" occurred_at_time="1386651900000">
<user_type name="External" count="492" occurred_at_time="1386651900000">
<session_source name="Web" count="492" occurred_at_time="1386651900000"/>
</user_type>
<user_type name="Internal" count="19" occurred_at_time="1386622200000">
<session_source name="UNKNOWN" count="12" occurred_at_time="1386624300000" />
<session_source name="Web" count="10" occurred_at_time="1386604200000" />
</user_type>
</product>
我正在遍历一个属性文件,该文件指定了我们在 xml 中感兴趣的产品,并且很难创建正确的表达式。
for (int j = 0; j < Products.length; j++) {
XPathFactory xPathfactory = XPathFactory.newInstance();
XPath xpath = xPathfactory.newXPath();
try {
XPathExpression expr = xpath.compile("product[@name=" + Products[j] + "]attribute::count");
CompareNextWeb = expr.evaluate(doc);
System.out.println(CompareNextWeb);
} catch (XPathExpressionException ex) {
Logger.getLogger(NextReport.class.getName()).log(Level.SEVERE, null, ex);
}
}
所以我希望能够选择计数,并且在将来,发生_at_time,使用此表达式“product[@name=" + Products[j] + "]attribute::count"。真的,我只需要知道在这种情况下这是否可能,或者我需要以不同的方式来解决这个问题。
【问题讨论】: