选择一个节点我有一个XForm的文件使用XPath和JDOM
<?xml version="1.0" encoding="UTF-8"?><h:html xmlns:h="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/1999/xhtml"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:jr="http://openrosa.org/javarosa">
<h:head>
<h:title>Summary</h:title>
<model>
<instance>
<data vaultType="nsp_inspection.4.1">
<metadata vaultType="metadata.1.1">
<form_start_time type="dateTime" />
<form_end_time type="dateTime" />
<device_id type="string" />
<username type="string" />
</metadata>
<date type="date" />
<monitor type="string" />
</data>
</instance>
</model>
</h:head>
我想使用XPath和JDOM
XPath xpath = XPath.newInstance("h:html/h:head/h:title/");
似乎做工精细选择从XForm的数据元素和选择标题元素,但是
XPath xpath = XPath.newInstance("h:html/h:head/model");
不选择模型元素。 我想它与命名空间有关。
它看起来像默认的命名空间的问题。这是否有帮助:http://stackoverflow.com/a/6390494/10098?顺便说一句,你的默认命名空间可能是错误的,它应该是http://www.w3.org/2002/xforms如果我没有错误 – wds 2013-05-01 09:18:11
这似乎是做的勾号。 XPath xpath = XPath.newInstance(“// h:model”); tanx @wds为链接。 – zaki 2013-05-01 09:36:49