2014-04-20 114 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

相關問題