【问题标题】:Parse XML containing namespace using JSTL使用 JSTL 解析包含命名空间的 XML
【发布时间】:2014-06-04 16:16:30
【问题描述】:

我想使用 JSTL 从 Web 服务解析 XML。 XML 包含导致解析和输出结果出现问题的命名空间

XML 字符串:

<MonthlyPayments:paymentsSummary xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:MonthlyPayments="http://www.zillow.com/static/xsd/MonthlyPayments.xsd" xsi:schemaLocation="http://www.zillow.com/static/xsd/MonthlyPayments.xsd http://www.zillowstatic.com/vstatic/LATEST/static/xsd/MonthlyPayments.xsd">
  <request>
    <price>100000</price>
    <down>15</down>
    <zip>98104</zip>
  </request>
  <payment loanType="thirtyYearFixed">
    <rate>4.2</rate>
    <monthlyPrincipalAndInterest>416</monthlyPrincipalAndInterest>
    <monthlyMortgageInsurance>31</monthlyMortgageInsurance>
  </payment>
</MonthlyPayments:paymentsSummary>

JSP 文件(resultString 包含 XML):

<c:set var="xmldocument">${map.resultString}</c:set>    
<x:parse var="doc" xml="${xmldocument}"  />
 ...
<x:out select="$doc/MonthlyPayments/request/price" /> 

删除 XML 中的 paymentSummary 部分时,输出正确为 1000000。我需要能够解析包含命名空间的 XML。请帮忙?

【问题讨论】:

标签: java xml parsing namespaces jstl


【解决方案1】:

我设法找到了适合我的解决方案。

<b>MonthlyPayments > request > Price </b>:                 
<x:out select="$doc//*[name()='request']/*[name()='price']"/>
<br>    

MonthlyPayments > request > Price : 100000

<b>MonthlyPayments > response > payment > rate </b>:                 
<x:out select="$doc//*[name()='response']/*[name()='payment']/*[name()='rate']"/>
<br>                     

MonthlyPayments > 响应 > 付款:4.2

<b>MonthlyPayments > response > payment > loantype </b>:                         
<x:out select="$doc//*[name()='response']/*[name()='payment']/@loanType"/>

MonthlyPayments > 响应 > 付款 > 贷款类型:三十年固定

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-12-30
    • 1970-01-01
    • 2021-05-03
    • 2014-01-10
    • 1970-01-01
    • 2010-11-16
    相关资源
    最近更新 更多