大家,Dom4j采用递归遍历XML为什么会额外出现好多NULL,怎么改?
package com.dom4j;import
import
import
import java.util.Iterator;
import java.util.List;
import org.dom4j.Attribute;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.Node;
import org.
import org.
import org.
public class Dom4jDg {
public static void main(String args[]) throws DocumentException{
SAXReader reader=new SAXReader();
Document docement=reader.read(new File("wpc.xml"));
Element rootElement=docement.getRootElement();
System.out.println(rootElement.getName());
Dom4jDg test=new Dom4jDg();
test.treeWalk(rootElement);
}
public void treeWalk(Element element) {
for (int i = 0, size = element.nodeCount(); i < size; i++){
Node node = element.node(i);
System.out.println(node.getName()+node.getText());
if (node instanceof Element) {
treeWalk((Element)node);
} else {
}
}
}
}