【发布时间】:2011-11-30 11:34:28
【问题描述】:
我有一个来自这种形式的 HTTP POST 的 XML 响应
<PaymentResponse><TransDate>301111</TransDate><TransTime>011505</TransTime><SourceID>0</SourceID><Balance>0</Balance><ResponseCode>06</ResponseCode><ResponseMessage>Error XXXX</ResponseMessage><ApprovalCode>DECL</ApprovalCode><ApprovalAmount>0</ApprovalAmount></PaymentResponse>
但我无法使用 Sax 解析器对其进行解析。请帮帮我。 问候
我正在使用此代码
public void endElement(String uri, String localName, String qName) throws SAXException {
if(localName.equalsIgnoreCase("TransDate"))
{
int tD = Integer.parseInt(currentValue);
tempResponse.setTDate(tD);
}
但是每次 localName 都带有空字符串。
【问题讨论】:
-
请更具体地说明为什么您无法解析此内容:您是否在某处遇到异常?您是否需要知道如何从 HTTP 请求中检索数据?如果是这样,您使用什么来执行发布请求 - URLConnection、Apache 的 HttpClient、...?
-
为什么不能?你试过什么?什么不起作用?
-
解决方案是修复代码中的错误。确保将它们全部修复。
-
为什么不能用 SAX 解析它?需要介绍吗?还是有什么异常/问题?
-
我正在使用此代码 'public void endElement(String uri, String localName, String qName) throws SAXException { if(localName.equalsIgnoreCase("TransDate")){ int tD = Integer.parseInt(currentValue ); tempResponse.setTDate(tD); }'
标签: java xml parsing post saxparser