2014-04-20 75 views
1

我想使用JSTL解析来自Web服务的XML。 XML包含导致具有分析问题的命名空间,并输出结果使用JSTL解析包含名称空间的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" /> 

在拆除中的paymentSummary部分XML的输出是正确的1000000.我需要能够解析包含命名空间的XML。请帮忙?

+0

检查类似的问题这里:http://stackoverflow.com/questions/17580051/accessing-imported-xml-element-attri弼与-A-给定名称空间中-A-JSP – Prasad

回答

0

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

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

MonthlyPayments>请求>价格: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>响应>付款> loantype:thirtyYearFixed

相关问题