解析xml 推荐dom4j

public List getInfoFromXML() {
		List list = new ArrayList();
		SAXReader reader = new SAXReader();
		try {
			Document doc = reader.read(new File("d://tt.xml"));

			List projects = doc.selectNodes("/imClientConfig/contactList");

			Iterator it = projects.iterator();

			while (it.hasNext()) {
				Element elm = (Element) it.next();
				System.out.println(elm.getText());
			}

		} catch (Exception ex) {
			ex.printStackTrace();
		}

		return list;
	}


定位node要用到jaxen.jar
方便好用~
拿到element之后能取到它的各种属性~

你可能感兴趣的:(xml)