JAVAXML在不知道父节点的情况下查找节点



JAVA&XML

我有一个像这样的xml文档:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<elezione>
  <codice>6</codice>
  <descrizione>EUROPEE</descrizione>
  <data>25 MAGGIO 2014</data>
  <enti-partecipanti>
    <italia>
      <circ-europea>
        <codice>2</codice>
        <nome>II : ITALIA NORD-ORIENTALE</nome>
        <regione> ..... </regione>
        <regione> ..... </regione>
        <regione>
          <codice>4</codice>
          <nome>TRENTINO-ALTO ADIGE</nome>
          <provincia> 
            <codice>14</codice>
            <nome>BOLZANO</nome>
            .. Whole load of sub nodes and stuff
          </provincia>
          <provincia> 
            <codice>14</codice>
            <nome>BOLZANO</nome>
            .. Whole load of sub nodes and stuff
          </provincia>
          ..
          ..
        </regione>
        <regione> ... </regionr>
      </circ-europea>
    </italia>
  </enti-partecipanti>
</elezione>

我需要从<regione>节点开始检查,"codice"=14

不幸的是,"<regione>"节点列表上方的结构不断变化(xml的供应商非常疯狂),但在该节点下方,情况非常标准。

目前我使用的是经典的"DocumentBuilder…"代码。

主要的问题是,我从<elezione>节点内部开始搜索regione,而不是从文档本身开始,所以我不知道如何使用从节点而不是文档开始的xPath!

使用以"//"开头的xpath。

"//regione"将匹配所有"regione"节点。

相关内容

最新更新