xml-----------node 与 element
来源:互联网 发布:淘宝爆款打造方法2016 编辑:程序博客网 时间:2024/05/16 00:46
node 包含xml的全部内容
比如<book>算法入门</book>
算法入门也相当于一个 节点 node,类型是text
而book可以称为元素
.net中的定义
继承层次结构
Element:
System.Object
System.Xml.XmlNode
System.Xml.XmlLinkedNode
System.Xml.XmlElement
System.Xml.XmlNode
System.Xml.XmlLinkedNode
System.Xml.XmlElement
Node:
System.Xml.XmlNode
System.Xml.XmlAttribute
System.Xml.XmlDocument
System.Xml.XmlDocumentFragment
System.Xml.XmlEntity
System.Xml.XmlLinkedNode
System.Xml.XmlNotation
在W3C中node 有各种类型。。。。。。。。。。。。。。。。。。。。
节点类型
下面的表格列出了不同的 W3C 节点类型,以及它们可拥有的子元素:
- Element (max. one)
- ProcessingInstruction
- Comment
- DocumentType
- ProcessingInstruction
- Comment
- Text
- CDATASection
- EntityReference
- ProcessingInstruction
- Comment
- Text
- CDATASection
- EntityReference
- Text
- Comment
- ProcessingInstruction
- CDATASection
- EntityReference
- Text
- EntityReference
- ProcessingInstruction
- Comment
- Text
- CDATASection
- EntityReference
综上这样遍历时会获得 元素 文本,注释节点 (属性获取不到)
//利用递归获取xml的所有节点(元素也是节点) public void RecurseXml(XmlNode root,int index) { if (root == null) { return; } if (root is XmlElement) { tbxContent.Text += root.Name.PadLeft(root.Name.Length + index)+Environment.NewLine;//换行 if (root.HasChildNodes) { RecurseXml(root.FirstChild,index+1); } if(root.NextSibling!=null) { RecurseXml(root.NextSibling,index+2); } } else if(root is XmlText) { string text=((XmlText)root).Value; tbxContent.Text+=text.PadLeft(text.Length+index)+Environment.NewLine; } else if (root is XmlAttribute) { string text = ((XmlAttribute)root).Value; tbxContent.Text += text.PadLeft(text.Length + index) + Environment.NewLine; } else if (root is XmlComment) { string text = ((XmlComment)root).Value; tbxContent.Text += text.PadLeft(text.Length + index) + Environment.NewLine; } }
<?xml version="1.0" encoding="UTF-8"?>-<phone> -<xphone name="motox"> <price>$200</price> <color>black</color> -<test><!--this is comment --></test> </xphone> <xiaomi name="xiaomi" price="1999"/> -<mx3> <color>green</color> <price>$350</price> </mx3> -<motox> <xx>sssssssssssss</xx> <xxx>KKK</xxx> </motox> </phone>
结果:
phone
xphone
price
$200
color
black
test
this is comment
xiaomi
mx3
color
green
price
$350
motox
xx
sssssssssssss
xxx
KKK
0 0
- xml-----------node 与 element
- xml中Element与Node区别
- java解析XML Node与Element的区别
- node与element
- xml中Node和Element的区别
- xml中Node和Element的区别
- XML中Node和Element的区别
- XML中node和element的区别
- XML中node和element的区别
- XML中Element和Node的区别
- xml中Node和Element的区别
- DOM Node Element 的联系与区别
- 关于Node 与 Element 的常用总结
- DOM4J学习笔记 --- Node与Element区别
- LINQ To XML:修改element, a comment, text node
- xml中的元素(element)和节点(node)——C#
- XML中Element,Node,Attr的区别和联系
- XML(一) ---节点node和元素element的区别
- DML、DDL、DCL区别
- hdu 1596 find the safest road
- BOOL和bool的区别
- 求职季!50份简历设计,助你找到梦寐以求的工作
- new和delete的使用
- xml-----------node 与 element
- java 第五天 面向对象(基础篇之this关键字)
- NGUI -- UIWidget
- Spring MVC 原理 - DispatcherServlet调用完整过程(上)
- Windows Phone 8开发知识笔记
- IntelliJ IDEA 工具
- 信息增益(information gain)
- CareerCup Given preorder traversal array of a BST, recontruct the BST.
- 激光打印机的工作原理2