[实习记录]dom4j读取xml文件

        SAXReader reader = new SAXReader();
        Document document = null;

        {
            try {
                document = reader.read(new File(path));
            } catch (DocumentException e) {
                e.printStackTrace();
            }
        }

        Element rootElement = document.getRootElement();
        Iterator objectElements = rootElement.elements("object").iterator();

        while (objectElements.hasNext()) {
            Element objectElement = objectElements.next();
            Element nameElement = objectElement.element("name");
            System.out.println(nameElement.getName() + nameElement.getText());
//getName:标签名 getText:标签内容

            Element poseElement = objectElement.element("pose");
            System.out.println(poseElement.getName() + poseElement.getText());

你可能感兴趣的:([实习记录]dom4j读取xml文件)