import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
public class TestSoap {
static List<Node> totallist=new ArrayList<Node>();
public static List<Node> getChildrenList(NodeList a){
for (int i = 0; i < a.getLength(); i++) {
Node n = a.item(i);
if(!n.getNodeName().equals("#text")){
System.out.println("被添加到totallist的元素:"+n.getNodeName());
totallist.add(n);}
NodeList chNodeList = n.getChildNodes();
getChildrenList(chNodeList);
}
return totallist;
}
public static void xmlStr(String xmlStr) throws ParserConfigurationException, SAXException, IOException, TransformerException{
StringReader sr = new StringReader(xmlStr);
InputSource is = new InputSource(sr);
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder=factory.newDocumentBuilder();
Document doc = builder.parse(is);
Element root = doc.getDocumentElement();
NodeList nodelist = root.getChildNodes();
getChildrenList(nodelist);
for(int k=0;k<totallist.size();k++){
Node n = totallist.get(k);
System.out.println("元素名称 :" + n.getNodeName());
}
System.out.println("遍历结束");
}
}