在使用我org.dom4j解析XML文檔,我使用XPath在一個節點如下:dom4j的閱讀XPath的子節點是不正確的
<JobDescription>
<Formats Description="">
<Format Refed="format_0" Name="MOV" >
<TranscodeParam VideoOutputParamRef="vo_para_28" />
<EnhancementParam VideoEnhancementRef="ve_para_31" />
</Format>
<Format Refed="format_1" Name="WMV" >
<TranscodeParam VideoOutputParamRef="vo_para_32" />
<EnhancementParam VideoEnhancementRef="ve_para_35" />
</Format>
</Formats>
</JobDescription>
Node formatsNode = document.selectSingleNode("//JobDescription/Formats");
if (formatsNode != null) {
for (Node formatNode :
formatsNode.selectNodes("//Format")) {
Node transcodeParaNode = node.selectSingleNode("//TranscodeParam"); //the node always get the first node(Which VideoOutputParamRef="vo_para_28")
}
}
結果是不對的formatNode
的TranscodeParam
總是第一個<Format>
元素,從來沒有到第二個。
如何解決問題?