如何使用 XPath 通过另一个属性值获取属性内容? [英] How get attribute content by another attribute value with XPath?
本文介绍了如何使用 XPath 通过另一个属性值获取属性内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有像这样的 XML:
I have XML like:
<?xml version='1.0' encoding='UTF-8'?>
<ClinicalDocument xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xmlns='urn:hl7-org:v3'
xmlns:ext='urn:hl7-RU-EHR:v1'
xsi:schemaLocation='urn:hl7-org:v3'>
<author>
<time value='20160809000000+0300'/>
<assignedAuthor>
<id root='1.2.643.5.1.13.3.25.1.1.100.1.1.70' extension='1'/>
<id root='1.2.643.100.3' extension='03480134121'/>
<id nullFlavor='NI'/>
</assignedAuthor>
</author>
</ClinicalDocument>
我必须在 id
中获取 extension
,root
的值 = 1.2.643.100.3
.我必须使用 XPath 2.0.我试过了:
I have to get extension
in id
with root
's value = 1.2.643.100.3
.
I must use XPath 2.0.
I have tried:
*[name()='ClinicalDocument']/*[name()='author']/*[name()='assignedAuthor']/*[name()='id' and @id='1.2.643.100.3']/@extension
.不工作/*[name()='ClinicalDocument']/*[name()='author']/*[name()='assignedAuthor']/*[name()='id'][2]/@extension
,但是id
的顺序可以混合.所以,我应该通过id
的值来检索
*[name()='ClinicalDocument']/*[name()='author']/*[name()='assignedAuthor']/*[name()='id' and @id='1.2.643.100.3']/@extension
. Not working/*[name()='ClinicalDocument']/*[name()='author']/*[name()='assignedAuthor']/*[name()='id'][2]/@extension
, but order ofid
s can mixed. So that, I should retrieve byid
's value
我需要通过 Java 的 XPathExpression 检索值
It's needed to me for retrieving value by Java's XPathExpression
推荐答案
Correct XPath: /*[name()='ClinicalDocument']/*[name()='author']/*[name()='assignedAuthor']/*[local-name()='id' and @root='1.2.643.100.3']/@extension
Correct XPath: /*[name()='ClinicalDocument']/*[name()='author']/*[name()='assignedAuthor']/*[local-name()='id' and @root='1.2.643.100.3']/@extension
这篇关于如何使用 XPath 通过另一个属性值获取属性内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文