我的XML如下:
<As>
<a>
<Bs>
<b>5</b>
<Bs>
</a>
<a>
<Bs>
<b>9</b>
<Bs>
</a>
<a></a>
<a>
<Bs>
<b>12</b>
<b>14</b>
<b>15</b>
</Bs>
</a>
我现在要删除选定的行文。 Sayuser已经选定了Node <b>14</b>
。
我的发言如下:
String expression = "/As/a[4]/Bs/b[2]";
Node node = (Node) xpath.evaluate(expression, doc, XPathConstants.NODE);
node.getParentNode().removeChild(node);
它是例外:
javax.xml.transform.TransformerException: Extra illegal tokens: health-history-questions , / , health-history-question , [ , 3 , ]
at org.apache.xpath.compiler.XPathParser.error(XPathParser.java:610)
at org.apache.xpath.compiler.XPathParser.initXPath(XPathParser.java:145)
at org.apache.xpath.XPath.<init>(XPath.java:178)
at org.apache.xpath.XPath.<init>(XPath.java:266)
at org.apache.xpath.jaxp.XPathImpl.eval(XPathImpl.java:195)
at org.apache.xpath.jaxp.XPathImpl.evaluate(XPathImpl.java:281)