cxx1
Bob1
stars1
85
cxx2
Bob2
stars2
85
cxx3
Bob3
stars3
85
l;
import org.w3c.dom.*;
l.parsers.DocumentBuilder;
l.parsers.DocumentBuilderFactory;
/**
* @Author: cxx
* Dom操作xml
* @Date: 2018/5/29 20:19
*/
public class DomDemo {
/
/⽤Element⽅式
public static void element(NodeList list){
for (int i = 0; i
Element element = (Element) list.item(i);
NodeList childNodes = ChildNodes();
for (int j = 0; j
if (childNodes.item(j).getNodeType()==Node.ELEMENT_NODE) {
//获取节点
System.out.print(childNodes.item(j).getNodeName() + ":");
//获取节点值
System.out.println(childNodes.item(j).getFirstChild().getNodeValue()); }
}
}
}
public static void node(NodeList list){
for (int i = 0; i
Node node = list.item(i);
NodeList childNodes = ChildNodes();
for (int j = 0; j
if (childNodes.item(j).getNodeType()==Node.ELEMENT_NODE) {
System.out.print(childNodes.item(j).getNodeName() + ":");
java xml是什么System.out.println(childNodes.item(j).getFirstChild().getNodeValue());
}
}
}
}
public static void main(String[] args) {
//1.创建DocumentBuilderFactory对象
DocumentBuilderFactory factory = wInstance(); //2.创建DocumentBuilder对象
try {
DocumentBuilder builder = wDocumentBuilder();
Document d = builder.parse("src/main/l");
NodeList sList = d.getElementsByTagName("student");
//element(sList);
node(sList);
} catch (Exception e) {
e.printStackTrace();
}
}
}
推荐教程:《Java教程》
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论