import org.dom4j.Document; import org.dom4j.DocumentException; import org.dom4j.DocumentHelper; import java.util.Iterator; import java.util.List; public class TestJsonClass { public static void main(String[] args) throws DocumentException { String url = "<?xml version='1.0'?><msg><location x='39.978649' y='116.307327' scale='16' label='北京市海淀区苏州街18号院1' maptype='0' poiname='长远天地大厦C座' /> </msg>"; String fristURL = url.replace("<", "<"); String secondURL = fristURL.replace(">", ">"); String thtURL = secondURL.replace("<br/>", ""); String fourURL = thtURL.replace("\n", ""); String lastURL = fourURL.replace("\t", ""); Document document = DocumentHelper.parseText(lastURL); org.dom4j.Element nodeElement = document.getRootElement(); //获得根目录下所有的孩子节点 List node = nodeElement.elements(); //取出每个孩子节点 for (Iterator it = node.iterator(); it.hasNext();) { org.dom4j.Element elm = (org.dom4j.Element) it.next(); System.out.println("取到的值是:x"+elm.attribute("x").getValue()); System.out.println("取到的值是:y"+elm.attribute("y").getValue()); System.out.println("取到的值是:lable"+elm.attribute("y").getValue()); System.out.println("取到的值是:poiname"+elm.attribute("y").getValue()); } }