Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何打印xml文件DOM4j库中可用的节点列表?_Java_Xml_Xml Parsing_Dom4j - Fatal编程技术网

Java 如何打印xml文件DOM4j库中可用的节点列表?

Java 如何打印xml文件DOM4j库中可用的节点列表?,java,xml,xml-parsing,dom4j,Java,Xml,Xml Parsing,Dom4j,我有一些xml文件,如下所示 <project> <modelVersion>4.0.0</modelVersion> <groupId>com.shutterfly</groupId> <artifactId>CodingChallenges</artifactId> <version>0.0.1-SNAPSHOT</version> <pa

我有一些xml文件,如下所示

<project>
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.shutterfly</groupId>
    <artifactId>CodingChallenges</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>
    <name>CodingChallenges</name>
</project>

4.0.0
com.shutterfly
编码挑战
0.0.1-快照
罐子
编码挑战
我希望输出如下所示:

输出为: 模型版本 groupId 人工的 .. 名称 我尝试的伪代码:

File inputFile = new File(inputFilePath);
SAXReader reader = new SAXReader();
Document document = reader.read(inputFile);
System.out.println("Root element :" + document.getRootElement().getName());
Element classElement = document.getRootElement();
@SuppressWarnings("unchecked")
List<Node> nodes = document.selectNodes("/project");
for (Node node : nodes) {
    System.out.println("\nCurrent Element :" + node.getName());
}
for (Iterator i = classElement.attributeIterator(); i.hasNext();) {
    Attribute attribute = (Attribute) i.next();
    System.out.println(attribute.getName());
}
File inputFile=新文件(inputFilePath);
SAXReader=新SAXReader();
文档=reader.read(inputFile);
System.out.println(“根元素:+document.getRootElement().getName());
Element classElement=document.getRootElement();
@抑制警告(“未选中”)
列表节点=文档。选择节点(“/project”);
用于(节点:节点){
System.out.println(“\n当前元素:+node.getName());
}
for(迭代器i=classElement.attributeIterator();i.hasNext();){
属性=(属性)i.next();
System.out.println(attribute.getName());
}

也许是这么简单:

    List<Node> nodes = document.selectNodes("/project/*");
    for (Node node : nodes) {
        System.out.println(node.getName() + "=" + node.getText());
    }
List nodes=document.selectNodes(“/project/*”);
用于(节点:节点){
System.out.println(node.getName()+“=”+node.getText());
}