0
다음과 같이 특정 String 응답이 있습니다.doc 요소가 문자열을 XML로 변환 할 때 null을 반환합니다.
<?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><ns:listUsersResponse xmlns:ns="http://org.apache.axis2/xsd" xmlns:ax2754="http://common.mgt.user.carbon.wso2.org/xsd"><ns:return>admin</ns:return><ns:return>[email protected]</ns:return><ns:return>[email protected]</ns:return><ns:return>[email protected]</ns:return><ns:return>[email protected]</ns:return><ns:return>[email protected]</ns:return><ns:return>[email protected]</ns:return><ns:return>[email protected]</ns:return><ns:return>[email protected]</ns:return><ns:return>[email protected]</ns:return><ns:return>[email protected]</ns:return><ns:return>[email protected]</ns:return><ns:return>[email protected]</ns:return><ns:return>[email protected]</ns:return><ns:return>[email protected]</ns:return><ns:return>user1</ns:return><ns:return>user1234</ns:return><ns:return>[email protected]</ns:return><ns:return>user2</ns:return><ns:return>[email protected]</ns:return><ns:return>[email protected]</ns:return><ns:return>[email protected]</ns:return><ns:return>ushani01</ns:return></ns:listUsersResponse></soapenv:Body></soapenv:Envelope>
이 문자열을 XML로 변환해야합니다.
아래 코드는 이전에 사용한 코드입니다.
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder;
try
{
builder = factory.newDocumentBuilder();
Document doc = builder.parse(new InputSource(new StringReader(outputString)));
System.out.println(" doc >>>");
System.out.println(doc);
NodeList nodeList = doc.getElementsByTagName("ns:listUsersResponse xmlns:ns=\"http://org.apache.axis2/xsd\" xmlns:ax2754=\"http://common.mgt.user.carbon.wso2.org/xsd");
System.out.println(" nodeList >>>");
System.out.println(nodeList);
if (nodeList.getLength() > 0) {
Element element = (Element)nodeList.item(0);
System.out.println(element.getElementsByTagName("ns:return")
.item(0).getTextContent());
} else {
System.out.println(" crazy >>>");
}
} catch (Exception e) {
e.printStackTrace();
}
다음은 제 출력물입니다.
outputString >>>
<?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><ns:listUsersResponse xmlns:ns="http://org.apache.axis2/xsd" xmlns:ax2754="http://common.mgt.user.carbon.wso2.org/xsd"><ns:return>admin</ns:return><ns:return>[email protected]</ns:return><ns:return>[email protected]</ns:return><ns:return>[email protected]</ns:return><ns:return>[email protected]</ns:return><ns:return>[email protected]</ns:return><ns:return>[email protected]</ns:return><ns:return>[email protected]</ns:return><ns:return>[email protected]</ns:return><ns:return>[email protected]</ns:return><ns:return>[email protected]</ns:return><ns:return>[email protected]</ns:return><ns:return>[email protected]</ns:return><ns:return>[email protected]</ns:return><ns:return>[email protected]</ns:return><ns:return>user1</ns:return><ns:return>user1234</ns:return><ns:return>[email protected]</ns:return><ns:return>user2</ns:return><ns:return>[email protected]</ns:return><ns:return>[email protected]</ns:return><ns:return>[email protected]</ns:return><ns:return>ushani01</ns:return></ns:listUsersResponse></soapenv:Body></soapenv:Envelope>
doc >>>
[#document: null]
nodeList >>>
[email protected]
crazy >>>
내가 여기에있는 실수는 무엇입니까? 내 의사가 null을 반환하기 때문입니다. 도움말에 감사드립니다.
감사
모든