[英]Parsing a SOAP response is returning null
String response = "<?xml version='1.0'?><soap:Envelope xmlns:soap='http://www.w3.org/2003/05/soap-envelope'><soap:Body><exch:Response xmlns:exch='http://applicant.ffe.org/exchange/1.0'>...</exch:Response></soap:Body></soap:Envelope>";
DocumentBuilderFactory dbf = null;
DocumentBuilder db = null;
org.w3c.dom.Document document = null;
try {
dbf = DocumentBuilderFactory.newInstance();
db = dbf.newDocumentBuilder();
InputSource is = new InputSource(new ByteArrayInputStream(response.getBytes("UTF-8")));
document = db.parse(is);
} catch(ParserConfigurationException e){}
catch(SAXException e){}
document is returning with null. 文档返回null。 I have tried different ways to pass to InputSource, but document is still returning null. 我尝试了多种方法传递给InputSource,但是文档仍返回null。 Any idea why this might be happening? 知道为什么会这样吗?
I just tried i could get the elements name and values . 我只是试着可以得到元素的名称和值。
try {
dbf = DocumentBuilderFactory.newInstance();
db = dbf.newDocumentBuilder();
InputSource is = new InputSource(new ByteArrayInputStream(response.getBytes("UTF-8")));
document = db.parse(is);
System.out.println(document);//here we get null;
System.out.println(document.getNodeName());//here we get document;
for(int i =0 ; i<document.getChildNodes().getLength();i++)
System.out.println(document.getChildNodes().item(i).getChildNodes().item(i).getNodeName());
}
Output :
[#document: null]
document
soap:Body
To parse SOAPResponse we can javax.xml.soap.*
it may take u to traverse the object xml tree. 要解析SOAPResponse,我们可以javax.xml.soap.*
可能需要u遍历对象xml树。 Anyway we may need parse the elements from SOAP Body . 无论如何,我们可能需要解析SOAP Body中的元素。 we could parse these very simple manner using DOM format . 我们可以使用DOM格式解析这些非常简单的方式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.