dom4j 讀取網路的xml

faicm發表於2015-07-29

==

public class Dom4J {
	public static void main(String[] args) throws DocumentException,
			MalformedURLException {
		URL url = null;
		url = new URL("http://115.28.209.21:8888/sms.aspx");
		SAXReader saxReader = new SAXReader();
		Document document = saxReader.read(url);
		Element messageElement = document.getRootElement();

		System.out.println(messageElement.getName() + ":"
				+ messageElement.getTextTrim());

		Iterator<Element> oneLevelElementItor = messageElement
				.elementIterator();
		while (oneLevelElementItor.hasNext()) {
			Element e1 = oneLevelElementItor.next();
			System.out.println(e1.getName() + " :" + e1.getText());
		}
	}
}


==

相關文章