【发布时间】:2011-07-30 22:04:27
【问题描述】:
目前我正在使用 XPath 表达式解析 XML 消息。它工作得很好。但是我有以下问题:
我正在解析 XML 的全部数据,因此我为每次调用 xPath.evaulate 实例化一个新的 InputSource。
StringReader xmlReader = new StringReader(xml);
InputSource source = new InputSource(xmlReader);
XPathExpression xpe = xpath.compile("msg/element/@attribute");
String attribute = (String) xpe.evaluate(source, XPathConstants.STRING);
现在我想深入了解我的 XML 消息并评估更多信息。为此,我发现自己需要再次实例化源。这是必需的吗?如果我不这样做,我会收到 Stream closed Exceptions。
【问题讨论】: