我想使用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。请帮帮忙?
答案 0 :(得分:0)
我设法找到适合我的解决方案。
<b>MonthlyPayments > request > Price </b>:
<x:out select="$doc//*[name()='request']/*[name()='price']"/>
<br>
MonthlyPayments&gt;请求&gt;价格:100000
<b>MonthlyPayments > response > payment > rate </b>:
<x:out select="$doc//*[name()='response']/*[name()='payment']/*[name()='rate']"/>
<br>
MonthlyPayments&gt;回应&gt;付款:4.2
<b>MonthlyPayments > response > payment > loantype </b>:
<x:out select="$doc//*[name()='response']/*[name()='payment']/@loanType"/>
MonthlyPayments&gt;回应&gt;付款&gt; loantype:threeYearFixed