我需要通过前缀获取XML文件的元素。我的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,但是在这种情况下它不会帮助我。我想获取所有带有前缀依赖项的元素。
提前致谢!
最佳答案
好的,我找到了解决方案:
getElementsByTagNameNS(Namespace,“*”);
依赖的 namespace 在XML文件的顶部声明。
关于javascript - 从XML文档中的特定 namespace 获取所有元素,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30727806/