文中尽量用上所有的操作和属性,以做示范
![](https://i-blog.csdnimg.cn/blog_migrate/fc6bef40a64704bea2aa46c8ef17bfc9.png)
![](https://i-blog.csdnimg.cn/blog_migrate/fc6bef40a64704bea2aa46c8ef17bfc9.png)
![](https://i-blog.csdnimg.cn/blog_migrate/fc6bef40a64704bea2aa46c8ef17bfc9.png)
![](https://i-blog.csdnimg.cn/blog_migrate/fc6bef40a64704bea2aa46c8ef17bfc9.png)
![](https://i-blog.csdnimg.cn/blog_migrate/fc6bef40a64704bea2aa46c8ef17bfc9.png)
![](https://i-blog.csdnimg.cn/blog_migrate/fc6bef40a64704bea2aa46c8ef17bfc9.png)
![](https://i-blog.csdnimg.cn/blog_migrate/fc6bef40a64704bea2aa46c8ef17bfc9.png)
![](https://i-blog.csdnimg.cn/blog_migrate/fc6bef40a64704bea2aa46c8ef17bfc9.png)
![](https://i-blog.csdnimg.cn/blog_migrate/fc6bef40a64704bea2aa46c8ef17bfc9.png)
// 添加文件头
doc.appendChild(p);
![](https://i-blog.csdnimg.cn/blog_migrate/fc6bef40a64704bea2aa46c8ef17bfc9.png)
// 用于直接加载时获得根接点
// var root = doc.documentElement;
// 两种方式创建根接点
// var root = doc.createElement("students");
var root = doc.createNode(1,"students","");
![](https://i-blog.csdnimg.cn/blog_migrate/fc6bef40a64704bea2aa46c8ef17bfc9.png)
// 创建子接点
var n = doc.createNode(1,"ttyp","");
// 指定子接点文本
// n.text = " this is a test";
// 创建孙接点
var o = doc.createElement("sex");
o.text = "男"; // 指定其文本
// 创建属性
var r = doc.createAttribute("id");
r.value="test";
// 添加属性
n.setAttributeNode(r);
// 创建第二个属性
var r1 = doc.createAttribute("class");
r1.value="tt";
![](https://i-blog.csdnimg.cn/blog_migrate/fc6bef40a64704bea2aa46c8ef17bfc9.png)
// 添加属性
![](https://i-blog.csdnimg.cn/blog_migrate/fc6bef40a64704bea2aa46c8ef17bfc9.png)
![](https://i-blog.csdnimg.cn/blog_migrate/fc6bef40a64704bea2aa46c8ef17bfc9.png)
![](https://i-blog.csdnimg.cn/blog_migrate/fc6bef40a64704bea2aa46c8ef17bfc9.png)
![](https://i-blog.csdnimg.cn/blog_migrate/fc6bef40a64704bea2aa46c8ef17bfc9.png)
![](https://i-blog.csdnimg.cn/blog_migrate/fc6bef40a64704bea2aa46c8ef17bfc9.png)
![](https://i-blog.csdnimg.cn/blog_migrate/fc6bef40a64704bea2aa46c8ef17bfc9.png)
![](https://i-blog.csdnimg.cn/blog_migrate/fc6bef40a64704bea2aa46c8ef17bfc9.png)
![](https://i-blog.csdnimg.cn/blog_migrate/fc6bef40a64704bea2aa46c8ef17bfc9.png)
![](https://i-blog.csdnimg.cn/blog_migrate/fc6bef40a64704bea2aa46c8ef17bfc9.png)
![](https://i-blog.csdnimg.cn/blog_migrate/fc6bef40a64704bea2aa46c8ef17bfc9.png)
![](https://i-blog.csdnimg.cn/blog_migrate/fc6bef40a64704bea2aa46c8ef17bfc9.png)
![](https://i-blog.csdnimg.cn/blog_migrate/fc6bef40a64704bea2aa46c8ef17bfc9.png)
![](https://i-blog.csdnimg.cn/blog_migrate/fc6bef40a64704bea2aa46c8ef17bfc9.png)
![](https://i-blog.csdnimg.cn/blog_migrate/fc6bef40a64704bea2aa46c8ef17bfc9.png)
![](https://i-blog.csdnimg.cn/blog_migrate/fc6bef40a64704bea2aa46c8ef17bfc9.png)
![](https://i-blog.csdnimg.cn/blog_migrate/fc6bef40a64704bea2aa46c8ef17bfc9.png)
![](https://i-blog.csdnimg.cn/blog_migrate/fc6bef40a64704bea2aa46c8ef17bfc9.png)
![](https://i-blog.csdnimg.cn/blog_migrate/fc6bef40a64704bea2aa46c8ef17bfc9.png)
![](https://i-blog.csdnimg.cn/blog_migrate/fc6bef40a64704bea2aa46c8ef17bfc9.png)
![](https://i-blog.csdnimg.cn/blog_migrate/fc6bef40a64704bea2aa46c8ef17bfc9.png)
![](https://i-blog.csdnimg.cn/blog_migrate/fc6bef40a64704bea2aa46c8ef17bfc9.png)
![](https://i-blog.csdnimg.cn/blog_migrate/fc6bef40a64704bea2aa46c8ef17bfc9.png)
![](https://i-blog.csdnimg.cn/blog_migrate/fc6bef40a64704bea2aa46c8ef17bfc9.png)
![](https://i-blog.csdnimg.cn/blog_migrate/fc6bef40a64704bea2aa46c8ef17bfc9.png)
![](https://i-blog.csdnimg.cn/blog_migrate/fc6bef40a64704bea2aa46c8ef17bfc9.png)
![](https://i-blog.csdnimg.cn/blog_migrate/fc6bef40a64704bea2aa46c8ef17bfc9.png)
![](https://i-blog.csdnimg.cn/blog_migrate/fc6bef40a64704bea2aa46c8ef17bfc9.png)
![](https://i-blog.csdnimg.cn/blog_migrate/fc6bef40a64704bea2aa46c8ef17bfc9.png)
![](https://i-blog.csdnimg.cn/blog_migrate/fc6bef40a64704bea2aa46c8ef17bfc9.png)
![](https://i-blog.csdnimg.cn/blog_migrate/fc6bef40a64704bea2aa46c8ef17bfc9.png)
![](https://i-blog.csdnimg.cn/blog_migrate/fc6bef40a64704bea2aa46c8ef17bfc9.png)
![](https://i-blog.csdnimg.cn/blog_migrate/fc6bef40a64704bea2aa46c8ef17bfc9.png)
![](https://i-blog.csdnimg.cn/blog_migrate/fc6bef40a64704bea2aa46c8ef17bfc9.png)
![](https://i-blog.csdnimg.cn/blog_migrate/fc6bef40a64704bea2aa46c8ef17bfc9.png)
![](https://i-blog.csdnimg.cn/blog_migrate/fc6bef40a64704bea2aa46c8ef17bfc9.png)
![](https://i-blog.csdnimg.cn/blog_migrate/fc6bef40a64704bea2aa46c8ef17bfc9.png)
![](https://i-blog.csdnimg.cn/blog_migrate/fc6bef40a64704bea2aa46c8ef17bfc9.png)
![](https://i-blog.csdnimg.cn/blog_migrate/fc6bef40a64704bea2aa46c8ef17bfc9.png)
![](https://i-blog.csdnimg.cn/blog_migrate/fc6bef40a64704bea2aa46c8ef17bfc9.png)
![](https://i-blog.csdnimg.cn/blog_migrate/fc6bef40a64704bea2aa46c8ef17bfc9.png)
![](https://i-blog.csdnimg.cn/blog_migrate/c1be62dcfeb46bd20f26c51df364641f.png)
![](https://i-blog.csdnimg.cn/blog_migrate/56c3555dcf761f9aaa637c3e541728f5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/56c3555dcf761f9aaa637c3e541728f5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/c74abaa7bebef89a626fc8f62b4a922b.png)
![](https://i-blog.csdnimg.cn/blog_migrate/56c3555dcf761f9aaa637c3e541728f5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/26e2d2092d29264a2f926d82cc1127b9.png)
![](https://i-blog.csdnimg.cn/blog_migrate/8805d4451429f065120b774408ad0993.png)
![](https://i-blog.csdnimg.cn/blog_migrate/fc6bef40a64704bea2aa46c8ef17bfc9.png)
![](https://i-blog.csdnimg.cn/blog_migrate/fc6bef40a64704bea2aa46c8ef17bfc9.png)
![](https://i-blog.csdnimg.cn/blog_migrate/fc6bef40a64704bea2aa46c8ef17bfc9.png)
![](https://i-blog.csdnimg.cn/blog_migrate/fc6bef40a64704bea2aa46c8ef17bfc9.png)
![](https://i-blog.csdnimg.cn/blog_migrate/fc6bef40a64704bea2aa46c8ef17bfc9.png)
![](https://i-blog.csdnimg.cn/blog_migrate/fc6bef40a64704bea2aa46c8ef17bfc9.png)
![](https://i-blog.csdnimg.cn/blog_migrate/fc6bef40a64704bea2aa46c8ef17bfc9.png)
![](https://i-blog.csdnimg.cn/blog_migrate/fc6bef40a64704bea2aa46c8ef17bfc9.png)
![](https://i-blog.csdnimg.cn/blog_migrate/fc6bef40a64704bea2aa46c8ef17bfc9.png)
![](https://i-blog.csdnimg.cn/blog_migrate/fc6bef40a64704bea2aa46c8ef17bfc9.png)
![](https://i-blog.csdnimg.cn/blog_migrate/fc6bef40a64704bea2aa46c8ef17bfc9.png)
![](https://i-blog.csdnimg.cn/blog_migrate/fc6bef40a64704bea2aa46c8ef17bfc9.png)
![](https://i-blog.csdnimg.cn/blog_migrate/c1be62dcfeb46bd20f26c51df364641f.png)
![](https://i-blog.csdnimg.cn/blog_migrate/56c3555dcf761f9aaa637c3e541728f5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/8805d4451429f065120b774408ad0993.png)
![](https://i-blog.csdnimg.cn/blog_migrate/fc6bef40a64704bea2aa46c8ef17bfc9.png)
![](https://i-blog.csdnimg.cn/blog_migrate/fc6bef40a64704bea2aa46c8ef17bfc9.png)
![](https://i-blog.csdnimg.cn/blog_migrate/fc6bef40a64704bea2aa46c8ef17bfc9.png)