[英]How to Parse XML Response of Http Post in Java
I have an XML response from HTTP POST of this form 我有来自这种形式的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>
But I am unable to parse it using Sax parser. 但是我无法使用Sax解析器进行解析。 Kindly help me out. 请帮我。 regards 问候
I am using this code 我正在使用此代码
public void endElement(String uri, String localName, String qName) throws SAXException {
if(localName.equalsIgnoreCase("TransDate"))
{
int tD = Integer.parseInt(currentValue);
tempResponse.setTDate(tD);
}
But every time localName comes with empty string. 但是每次localName都带有空字符串。
As to your specific question: have a look at 'qName' argument instead: local name is only populated when parser uses namespace-aware mode. 关于您的特定问题:请改用“ qName”参数:仅当解析器使用可识别名称空间的模式时才填充本地名称。 qName should contain "qualified" name, ie. qName应包含“限定”名称,即。 concatenation of prefix (if any) and local name; 前缀(如果有)和本地名称的串联; so something like "ns:element" (if there is a prefix), or "element" (if no prefix). 因此类似“ ns:element”(如果有前缀)或“ element”(如果没有前缀)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.