如何使用java xml获取最后一个子节点

时间:2017-05-30 18:02:41

标签: java xml

<section id="section1">
  <desc>Intestinal infectious diseases (A00-A09)</desc>
  <diag>
    <name>name1</name>
    <desc>Cholera</desc>
    <diag>
      <name>name1.1</name>
      <desc>Cholera due to Vibrio cholerae 01, biovar cholerae</desc>
      <inclusionTerm>
        <note>Classical cholera</note>
      </inclusionTerm>
    </diag>
    <diag>
      <name>name1.2</name>
      <desc>Cholera due to Vibrio cholerae 01, biovar eltor</desc>
      <inclusionTerm>
        <note>Cholera eltor</note>
      </inclusionTerm>
    </diag>
    <diag>
      <name>name1.3</name>
      <desc>Cholera, unspecified</desc>
    </diag>
  </diag>
  <diag>
      <name>name2</name>
      <desc>Other thrombophilia</desc>
      <inclusionTerm>
        <note>Other hypercoagulable states</note>
      </inclusionTerm>
      <excludes1>
        <note>diffuse or disseminated intravascular coagulation [DIC] (D65)</note>
        <note>heparin induced thrombocytopenia (HIT) (D75.82)</note>
        <note>hyperhomocysteinemia (E72.11)</note>
      </excludes1>
      <diag>
        <name>name2.1</name>
        <desc>Antiphospholipid syndrome</desc>
        <inclusionTerm>
          <note>Anticardiolipin syndrome</note>
          <note>Antiphospholipid antibody syndrome</note>
        </inclusionTerm>
        <excludes1>
          <note>anti-phospholipid antibody, finding without diagnosis (R76.0)</note>
          <note>anti-phospholipid antibody with hemorrhagic disorder (D68.312)</note>
          <note>lupus anticoagulant syndrome (D68.62)</note>
        </excludes1>
      </diag>          
    </diag>

大家好,

从abive xml我需要从每个主'diag'节点获取最后一个节点。 例如,第一个diag标签有名称,desc有三个子'diag'节点。 如果节点包含子节点名称,如'inclusionTerm',我需要得到子三'diag'。

所以,最后我需要输出,如

Name - name1.1
note - Classical cholera
Name - name1.2
note - Cholera eltor
朋友们,请帮我解决这个问题。 提前谢谢。

0 个答案:

没有答案