如何编写比较两个属性或节点的Xpath表达式

时间:2013-03-30 23:57:41

标签: xpath attributes xmlnode

给出以下样本:

<?xml version="1.0" encoding="UTF-8"?>
<Patients>
  <patientRole>
    <id extension="996-756-495" root="2.16.840.1.113883.19.5"/>
    <id extension="775-756-495" root="2.16.840.1.113883.14.6"/>
    <patient>
      <name>
        <given>Henry</given>
        <family>Levin</family>
      </name>
      <administrativeGenderCode code="M" codeSystem="2.16.840.1.113883.5.1"/>
      <birthTime value="19320924"/>
    </patient>
    <providerOrganization>
      <id root="2.16.840.1.113883.19.5"/>
      <name>Good Health Clinic</name>
    </providerOrganization>
    <admissionTime value="2012030111:32"/>
  </patientRole>
  <patientRole>
    <id extension="65" root="2.16.840.1.113883.3.933"/>
    <patient>
      <name>
        <given>Paul</given>
        <family>Pappel</family>
      </name>
      <administrativeGenderCode code="M" codeSystem="2.16.840.1.113883.5.1"/>
      <birthTime value="19551217"/>
    </patient>
    <providerOrganization>
      <id extension="84756-11241-283-OPTD-3322" root="1.2.3.4.5.6.1.8.9.0"/>
      <name> Dr.med. Hans Topp-Glucklich</name>
    </providerOrganization>
    <admissionTime value="201201152200"/>
  </patientRole>
  <patientRole>
    <id extension="800001" root="2.16.840.1.113883.19.5"/>
    <patient>
      <name>
        <given>JEANNE</given>
        <family>PETIT</family>
      </name>
      <administrativeGenderCode code="F" codeSystem="2.16.840.1.113883.5.1"/>
      <birthTime value="19480105"/>
    </patient>
    <providerOrganization>
      <id root="2.16.840.1.113883.19.5"/>
      <name>Good Health Clinic</name>
    </providerOrganization>
    <admissionTime value="20120101T22:00"/>
  </patientRole>
</Patients>

我如何为以下内容编写X-Path表达式:

男性患者的姓氏(性别代码=“M”)

我非常感谢任何帮助我是XML / Xpath的新手,我尝试了多种方法,但却没有产生我需要的东西。

1 个答案:

答案 0 :(得分:3)

这应该有效:

/Patients/patientRole/patient[administrativeGenderCode/@code='M']/name/family