【发布时间】:2013-03-22 13:52:21
【问题描述】:
我正在尝试关注http://www.ibm.com/developerworks/xml/library/x-nmspccontext/index.html
UniversalNamespaceResolver
针对 XML 解析 XPath 评估的命名空间的示例。我遇到的问题是下面的lookupNamespaceURI调用在XML上返回null,我在下面给出:
DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = domFactory.newDocumentBuilder();
Document dDoc = builder.parse(new InputSource(new StringReader(xml)));
String nsURI = dDoc.lookupNamespaceURI("h");
XML:
<?xml version="1.0"?>
<h:root xmlns:h="http://www.w3.org/TR/html4/">
<h:table>
<h:tr>
<h:td>Apples</h:td>
<h:td>Bananas</h:td>
</h:tr>
</h:table>`
</h:root>
虽然我希望它返回“http://www.w3.org/TR/html4/”。
【问题讨论】:
标签: java dom namespaces