操作XML文件

来源:互联网 发布:人工智能会议参会人员 编辑:程序博客网 时间:2024/06/05 17:09

1)操作XML文件的类库位于System.xml命名空间下

2)同XML操作相关的几个重要的类:

XMLNode:是一个抽象类,代表一个节点。其中document,element,attribute,text 等都是特定的节点类型。注意其实现的几个接口。XmlNodeList是一个比较有用的集合类

XmlDocument:代表一个DOM文档。

XmlLinkedNode: Gets the node immediately preceding or following this node。 表示Node之间的关联性

XmlElement:代表一个元素。他可以包含子元素和属性。 元素是一种特殊的node节点。

XmlCharacterData:Provides text manipulation methods that are used by several classes

XmlReader:Represents a reader that provides fast, non-cached, forward-only access to XML data.

XmlWriter:Represents a writer that provides a fast, non-cached, forward-only means of generating streams or files containing XML data.

3)各个类的主要作用。

XmlDocument 主要方法有:Load(),LoadXml(),CreateElement(),SelectSingleNode(),Save()等。分别用来打开一个文档,生成一个元素,选定特定元素,保存等。其中CreateElement()仅返回一个node对象,并不会把它加入到当前文档中。需要调用AppendChild()来加入到文档中

XmlNode及其子类:AppendChild(),RemoveChild(),InsertBefore(),InsertAfter,SelectSingleNode,SelectNode(),RemoveAll()等。属性:InnerText(去掉所有标签),InnerXml,OuterXml等。本身不能生成一个新的节点,但可以把一个节点对象添加为自己的子对象或者查找节点,删除等

XmlElement:在XmlNode的基础上提供一些Element特有的方法,如SetAttribute(),RemoveAttribute()等

 

 

http://www.cnblogs.com/dreamof/archive/2008/08/14/1268096.html

 

 

 

 

原创粉丝点击