1
我有一个巨大的XML,我需要找到支付的金额。它位于2个单元远离与CELLTEXT =“量”xPath:得到父母和第二个兄弟姐妹
<TableRow>
<Cell>
<RowNo>4</RowNo>
<CellColNo>1</CellColNo>
<CellText>amount</CellText>
<CellAttribute/>
</Cell>
<Cell>
<RowNo>4</RowNo>
<CellColNo>2</CellColNo>
<CellText/>
<CellAttribute/>
</Cell>
<Cell>
<RowNo>4</RowNo>
<CellColNo>3</CellColNo>
<CellText>138</CellText>
<CellAttribute/>
</Cell>
这是我的代码,在那里我奋力如何构建expressionString细胞:
XPath xPath = XPathFactory.newInstance().newXPath();
String exprString = "//TableRow/Cell[CellText='amount:']/following-sibling::cell[2]CellText/text()";
XPathExpression expr = xPath.compile(exprString);
Object result = expr.evaluate(doc, XPathConstants.NODESET);
NodeList nodes = (NodeList) result;
for (int j = 0; j < nodes.getLength(); j++) {
System.out.println(nodes.item(j).getNodeValue());
}
怎么办我创建了正确的exprString?
,你可以使用
是正确的,它是下面的兄弟?还是应该是父母的以下兄弟姐妹? – Malin
也许如果你在混合大小写拼写'Cell'并添加了缺少的'/'它会起作用吗? '以下兄弟姐妹::单元格[2]/CellText' – Andreas
@Andreas你做了我的一天! 就这么简单;) – Malin