使用JSTL读取XML文件 [英] Reading XML files using JSTL

查看:69
本文介绍了使用JSTL读取XML文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下格式的xml文件,我需要阅读 ref = 1111111/0000000和 ref ="2222222/0000000 使用jstl.

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> 

请您帮忙?

谢谢

推荐答案

使用其他变量和最小路径来查看文件内容:

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" />

这篇关于使用JSTL读取XML文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆