• 您的位置我爱Aspx >> XML/XLST >> 在.NET Framework中轻松处理XML数据(五)
  • 在.NET Framework中轻松处理XML数据(五)

  • 作者:aspxer  来源:internet  日期:2007-5-6 11:38:44  关键字:.net,xml,数据
  • 我的XmlTextReadWriter类并没有从XmlReader或者XmlWriter类中继承。取而代之的是另外两个类,一个是基于只读流(stream)的操作类,另一个是基于只写流的操作类。XmlTextReadWriter类的方法用Reader对象读数据,写入到Writer对象。为了适应不同的需求,内部的Reader和Writer 对象分别通过只读的Reader和Writer属性公开。图十一列出了该类的一些方法:

    Figure 11 XmlTextReadWriter Class Methods

    Method

    Description

    AddAttributeChange

    Caches all the information needed to perform a change on a node attribute. All the changes cached through this method are processed during a successive call to WriteAttributes.

    Read

    Simple wrapper around the internal reader's Read method.

    WriteAttributes

    Specialized version of the writer's WriteAttributes method, writes out all the attributes for the given node, taking into account all the changes cached through the AddAttributeChange method.

    WriteEndDocument

    Terminates the current document in the writer and closes both the reader and the writer.

    WriteStartDocument

    Prepares the internal writer to output the document and add a default comment text and the standard XML prolog.

    这个新类有一个Read方法,它是对Reader的read方法的一个简单的封装。另外,它提供了WriterStartDocument和WriteEndDocument方法。它们分别初始化/释放(finalize)了内部Reader和writer对象,还处理所有I/O操作。在循环读节点的同时,我们就可以直接的修改节点。出于性能的原因,要修改属性必须先用AddAttributeChange方法声明。对一个节点的属性所作的所有修改都会存放在一个临时的表中,最后,通过调用WriteAttribute方法提交修改,清除临时表。

    [1] [2] 下一页 我对这篇文章有话说?
  • 广告位招租,广告代号:content_468_15
  • 上一篇:一个简单的XML Schema的例子
    下一篇:在.NET Framework中轻松处理XML数据(四)