我需要通过前缀获取XML-File的元素。我的XML文件看起来像:
<dependency:COP xmi:id="5299" sofa="6" begin="291" end="294" Governor="4906" Dependent="4928" DependencyType="cop"/>
<dependency:POSS xmi:id="5306" sofa="6" begin="90" end="93" Governor="5313" Dependent="5322" DependencyType="poss"/>
<dependency:POSS xmi:id="5751" sofa="6" begin="133" end="136" Governor="5758" Dependent="5767" DependencyType="poss"/>
<dependency:POSS xmi:id="6385" sofa="6" begin="172" end="175" Governor="6361" Dependent="6352" DependencyType="poss"/>
<dependency:POSS xmi:id="6392" sofa="6" begin="203" end="206" Governor="6234" Dependent="6216" DependencyType="poss"/>
<dependency:POSS xmi:id="6399" sofa="6" begin="362" end="365" Governor="6406" Dependent="6415" DependencyType="poss"/>
<constituent:ADVP xmi:id="5808" sofa="6" begin="149" end="153" constituentType="ADVP" parent="5784" children="5819"/>
<constituent:ADVP xmi:id="4937" sofa="6" begin="295" end="301" constituentType="ADVP" parent="4894" children="4948"/>
<dependency:ADVCL xmi:id="6866" sofa="6" begin="31" end="35" Governor="5499" Dependent="5632" DependencyType="advcl"/>
我知道有函数getElementsByTagName,但在这种情况下它不会帮助我。我想获得具有前缀依赖性的所有元素。
提前致谢!
答案 0 :(得分:1)
好的,我找到了解决方案:
getElementsByTagNameNS(命名空间,&#34; *&#34);
依赖项的名称空间在XML-File的顶部声明。
答案 1 :(得分:0)
您可以使用xPath。
以下示例查找具有以'poss'开头的属性的任何元素://*[starts-with(@DependencyType,'poss')]