如何使用 XPath 通过另一个属性值获取属性内容? [英] How get attribute content by another attribute value with XPath?

查看:39
本文介绍了如何使用 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 中获取 extensionroot 的值 = 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:

  1. *[name()='ClinicalDocument']/*[name()='author']/*[name()='assignedAuthor']/*[name()='id' and @id='1.2.643.100.3']/@extension.不工作
  2. /*[name()='ClinicalDocument']/*[name()='author']/*[name()='assignedAuthor']/*[name()='id'][2]/@extension,但是id的顺序可以混合.所以,我应该通过 id 的值来检索
  1. *[name()='ClinicalDocument']/*[name()='author']/*[name()='assignedAuthor']/*[name()='id' and @id='1.2.643.100.3']/@extension. Not working
  2. /*[name()='ClinicalDocument']/*[name()='author']/*[name()='assignedAuthor']/*[name()='id'][2]/@extension, but order of ids can mixed. So that, I should retrieve by id'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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆