`
showcup
  • 浏览: 24019 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

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; }

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics