Reading XML files using JSTL

只谈情不闲聊 提交于 2019-12-25 08:48:19

问题


i have an xml file in below format and I need to read ref=1111111/0000000 and ref="2222222/0000000 using jstl.

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <TestDocument xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
      <Data>
        <ARUDD>
          <Header reportType="REFT1019" ></Header>
          <AddresseeInformation name="c company"></AddresseeInformation>
          <ServiceLicenseInformation userName="Muhammad" userNumber="785421"></ServiceLicenseInformation>
          <Advice>
            <OriginatingAccountRecords>
              <OriginatingAccountRecord>
                <OriginatingAccount name="My Account" ></OriginatingAccount>
                <ReturnedDebitItem ref="0000000" >
                </PayerAccount>
                </ReturnedDebitItem>
                <Totals numberOf="1" valueOf="500.00" currency="GBP"></Totals>
              </OriginatingAccountRecord>
              <OriginatingAccountRecord>
                <OriginatingAccount name="Originating account " number="000000" sortCode="00-00-00"></OriginatingAccount>
                <ReturnedDebitItem ref="xxxxxxx/0000000   " transCode="17" >
                **<PayerAccount number="aaaaaaa" **ref="1111111/0000000"**>**
                </PayerAccount></ReturnedDebitItem>
                <ReturnedDebitItem ref="yyyyyyy/0000000   " transCode="01" >
                **<PayerAccount number="bbbbbbb" **ref="2222222/0000000"** >**
                </PayerAccount></ReturnedDebitItem>
                <Totals numberOf="111" valueOf="2111" currency="GBP"></Totals>
              </OriginatingAccountRecord>
            </OriginatingAccountRecords>
          </Advice>
        </ARUDD>
      </Data>
      </BACSDocument>

the code I am using to read this (without any luck) is

  <c:import var="url" url="data.xml"/>
            <x:parse   xml="${url}"   var="doc" />  
            <x:forEach   var="n"  select="$doc/TestDocument/Data/ARUDD/Advice/OriginatingAccountRecords/OriginatingAccountRecord/OriginatingAccount/ReturnedDebitItem"> 
          <option> <x:out select="$n/ref" />  </option>

           </x:forEach> 

I have another file in the same location and I can read it without any problem.

 <?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
    <ISO_3166-1_List_en xml:lang="en">
       <ISO_3166-1_Entry>
          <ISO_3166-1_Country_name>AFGHANISTAN</ISO_3166-1_Country_name>
          <ISO_3166-1_Alpha-2_Code_element>AF</ISO_3166-1_Alpha-2_Code_element>
       </ISO_3166-1_Entry>
       <ISO_3166-1_Entry>
          <ISO_3166-1_Country_name>ÅLAND ISLANDS</ISO_3166-1_Country_name>
          <ISO_3166-1_Alpha-2_Code_element>AX</ISO_3166-1_Alpha-2_Code_element>
       </ISO_3166-1_Entry>
     </ISO_3166-1_List_en>


 <c:import var="url" url="countries.xml"/>
  <x:parse   xml="${url}"   var="doc" />  

   <x:forEach   var="n"  select="$doc/ISO_3166-1_List_en/ISO_3166-1_Entryy"> 
  <!--  select="$output/ISO_3166-1_List_en/ISO_3166-1_Entry[2]/ISO_3166-1_Country_name" -->

   <option> <x:out select="$n/ISO_3166-1_Country_name" />  </option>

 </x:forEach> 

please can you help?

thanks


回答1:


Use a different variable and a minimal path to see what the file contents are:

<x:set var="foo" select="$doc" /> 
<x:out select="$foo" />


来源:https://stackoverflow.com/questions/9621528/reading-xml-files-using-jstl

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!