Javascript 从XML文档中的特定命名空间获取所有元素
我需要通过前缀获取XML文件的元素。我的XML文件如下所示:Javascript 从XML文档中的特定命名空间获取所有元素,javascript,xml,Javascript,Xml,我需要通过前缀获取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"
<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,但在这种情况下它帮不了我。我想得到所有前缀依赖的元素
提前谢谢 好的,我找到了解决方案: GetElementsByTagnames(名称空间,“*”) 依赖项的名称空间在XML文件的顶部声明。您可以使用xPath
下面是一个查找任何属性以“poss”开头的元素的示例:
/*[以(@DependencyType,'poss')开头]
通过谷歌搜索XML按前缀获取元素
可能会让您开始。我做了。。但是我没有找到解决我问题的办法。他们只是展示了前缀和名称空间是如何设置的。。但永远不会知道如何搜索它。你用的是哪种编程语言?Javascript。你能帮我吗?