dom4j解析xml重复节点
答案:1 悬赏:30 手机版
解决时间 2021-11-27 06:35
- 提问者网友:容嬷嬷拿针来
- 2021-11-27 02:42
dom4j解析xml重复节点
最佳答案
- 五星知识达人网友:迟山
- 2021-11-27 03:05
import java.io.File;
import java.util.List;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Node;
import org.dom4j.io.SAXReader;
public class XmlTest2 {
public static void main(String[] args) {
SAXReader reader = new SAXReader();
reader.setEncoding("UTF-8");
Document doc = null;
try {
File file = new File("test2.xml");
doc = reader.read(file);
printNode(doc.selectNodes("DSExport/Job"));
}
catch (DocumentException e) {
e.printStackTrace();
}
}
public static void printNode(List nodeList) {
for (Node jobNode : nodeList) {
printProperty(jobNode.selectNodes("Record/Property"));
printProperty(jobNode.selectNodes("Record/Collection/SubRecord/Property"));
}
}
public static void printProperty(List propertyNodeList) {
for (Node propertyNode : propertyNodeList) {
System.out.println(propertyNode.getUniquePath() + ">>" + propertyNode.selectSingleNode("@Name").getText() + ":" + propertyNode.getText());
}
}
}
import java.util.List;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Node;
import org.dom4j.io.SAXReader;
public class XmlTest2 {
public static void main(String[] args) {
SAXReader reader = new SAXReader();
reader.setEncoding("UTF-8");
Document doc = null;
try {
File file = new File("test2.xml");
doc = reader.read(file);
printNode(doc.selectNodes("DSExport/Job"));
}
catch (DocumentException e) {
e.printStackTrace();
}
}
public static void printNode(List
for (Node jobNode : nodeList) {
printProperty(jobNode.selectNodes("Record/Property"));
printProperty(jobNode.selectNodes("Record/Collection/SubRecord/Property"));
}
}
public static void printProperty(List
for (Node propertyNode : propertyNodeList) {
System.out.println(propertyNode.getUniquePath() + ">>" + propertyNode.selectSingleNode("@Name").getText() + ":" + propertyNode.getText());
}
}
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯