【发布时间】: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。请帮忙?
【问题讨论】:
-
在这里查看类似问题:stackoverflow.com/questions/17580051/…
标签: java xml parsing namespaces jstl