How to Parse XML Response of Http Post in Java
سؤال
I have an XML response from HTTP POST of this form
<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. 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.
المحلول
As to your specific question: have a look at 'qName' argument instead: local name is only populated when parser uses namespace-aware mode. qName should contain "qualified" name, ie. concatenation of prefix (if any) and local name; so something like "ns:element" (if there is a prefix), or "element" (if no prefix).
لا تنتمي إلى StackOverflow