想跳过标签并按索引获取

时间:2011-03-25 15:43:29

标签: xpath

鉴于此XML:

<mets:mets>
 <mets:fileSec>
   <mets:fileGrp ID="fileGrp001" USE="image/dynamic">
  <mets:file ID="filebib4112678_18760203_1_24_0001_m.jp2" MIMETYPE="image/jp2" SIZE="5308416"
    CREATED="2009-11-10T00:00:00" USE="image/dynamic" ADMID="techMD001"
    CHECKSUM="c07f516d77d8a5ca452775d489ffe78c" CHECKSUMTYPE="MD5">
    <mets:FLocat LOCTYPE="URL" xlink:type="simple"
      xlink:href="file:bib4112678_18760203_1_24_0001_m.jp2"/>
  </mets:file>
  <mets:file ID="filebib4112678_18760203_1_24_0002_m.jp2" MIMETYPE="image/jp2" SIZE="5308416"
    CREATED="2009-11-10T00:00:00" USE="image/dynamic" ADMID="techMD002"
    CHECKSUM="6497ceb7a8477fbe9ba4ff9e6e57999f" CHECKSUMTYPE="MD5">
    <mets:FLocat LOCTYPE="URL" xlink:type="simple"
      xlink:href="file:bib4112678_18760203_1_24_0002_m.jp2"/>
  </mets:file>

</mets:fileGrp>
<mets:fileGrp ID="fileGrp002" USE="text/alto">
  <mets:file ID="filebib4112678_18760203_1_24_0001_alto.xml" MIMETYPE="text/xml" SIZE="1114112"
    CREATED="2009-11-10T00:00:00" USE="text/alto" ADMID="techMD005"
    CHECKSUM="e391852693f78d2eb024caf6dbdb97c6" CHECKSUMTYPE="MD5">
    <mets:FLocat LOCTYPE="URL" xlink:type="simple"
      xlink:href="file:bib4112678_18760203_1_24_0001_alto.xml"/>
  </mets:file>
  <mets:file ID="filebib4112678_18760203_1_24_0002_alto.xml" MIMETYPE="text/xml" SIZE="1114112"
    CREATED="2009-11-10T00:00:00" USE="text/alto" ADMID="techMD006"
    CHECKSUM="e391852693f78d2eb024caf6dbdb97c6" CHECKSUMTYPE="MD5">
    <mets:FLocat LOCTYPE="URL" xlink:type="simple"
      xlink:href="file:bib4112678_18760203_1_24_0002_alto.xml"/>
  </mets:file>

   </mets:fileGrp>
  </mets:fileSec>
</mets:mets>

这个表达式:

/ METS / fileSec / fileGrp [2] /文件[2] / @ ADMID

给出结果“techMD006”

但是,我希望使用类似这样的表达式/查询来获得相同的结果:

/ METS / fileSec //文件[4] / @ ADMID

I。我不想打扰fileGrp元素,因为它使事情变得更复杂。不幸的是,上面的表达不起作用..

有谁知道怎么做这样的表达?

感谢名单!

1 个答案:

答案 0 :(得分:1)

您的表达式检索所有file元素,这些元素是/mets/fileSec的后代,并且是其父级的第四个子元素:

/mets/fileSec//file[4]/@ADMID

但你没有这样的元素。你想要的是检索作为file的后代的所有/mets/fileSec元素,然后获取第四个元素。使用此:

(/mets/fileSec//file)[4]/@ADMID