---
title: "JAXP解析命名空间示例以备将来查用"
author: "showcup"
date: "2010-09-03T11:00:42Z"
tags: []
categories: ["编程语言"]
slug: "jaxp"
draft: false
lastmod: "2010-09-03T14:57:28Z"
id: 754310
url: "https://showcup.iteye.com/blog/754310"
---

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 &gt; 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 &gt; 0) { // 找到callResponse节点 asipResponse = asipResponseNodeList.item(0); if (asipResponse != null) { // 找到callReturn节点 Node asipCallReturn = asipResponse.getFirstChild(); asipReturnString = asipCallReturn.getTextContent(); } } return asipReturnString; }