JAXP解析命名空间示例以备将来查用

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true);//开启命名空间 DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse(new InputSource(new StringReader(result.toString())));//用xml串构造源 System.out.println(getAsipReturnString(doc)); private Node getSoapBody(Document doc) { NodeList bodyNodeList = doc.getElementsByTagNameNS(SOAP_NS, "Body"); int bodyNodeListLength = bodyNodeList.getLength(); Node body = null; // 找到body if (bodyNodeListLength > 0) { body = bodyNodeList.item(0); } return body; } private String getAsipReturnString(Document doc) { String asipReturnString = null; NodeList asipResponseNodeList = doc.getElementsByTagNameNS(ASIP_NS, "callResponse"); int asipResponseNodeListLength = asipResponseNodeList.getLength(); Node asipResponse = null; if (asipResponseNodeListLength > 0) { // 找到callResponse节点 asipResponse = asipResponseNodeList.item(0); if (asipResponse != null) { // 找到callReturn节点 Node asipCallReturn = asipResponse.getFirstChild(); asipReturnString = asipCallReturn.getTextContent(); } } return asipReturnString; }

你可能感兴趣的:(xml,SOAP)