java解析XML有很多方式,dom4j jdom等等
今天发现org.w3c.dom 是java自带的类包。而且比较简单
import java.io.ByteArrayInputStream;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
String value = "";
try {
DocumentBuilder db = factory.newDocumentBuilder();
ByteArrayInputStream is = new ByteArrayInputStream(ele.getXML().getBytes());
Document document = db.parse(is);//InputStream or File Object
NodeList nodeList = document.getElementsByTagName("SYSTYPE");
String value = "";
for(int i=0; i<nodeList.getLength(); i++) {
Element tyes = (Element)nodeList.item(i);
value = tyes.getNodeValue();
System.out.print(value);
}
} catch (ParserConfigurationException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}