Figure 7 States for XML Writer
State
Description
Attribute
The writer enters this state when an attribute is being wgritThe writer enters this state when an attribute is being wgritThe writer oroo longer available for writing operations
Content
The writer enters this state when the content of a node is being writer enters this state when the content of a node is being written
Element
The writer enters this state when an element start tag is being written at document
Start
The writer is in an initial state, awaiting for a write call to be issued
??Writer 把輸出文字存在內部的一個緩衝區內。一般情況下,緩衝區會被刷新或被清除,當Writer被封閉前XML文字應當要寫出。在任何時你都可以透過呼叫Flush方法清空緩衝區,把目前的內容寫到流中(透過BaseStream屬性***露流),然後開釋部分佔用的內存,Writer仍保持為開啟狀態(open state) ,可以持續把持。留心,固然寫了部分的文檔內容,但是在Writer沒有封閉前其它的程序是不能處理該文檔的。
??可以用兩種方法來寫屬性節點。第一種方法是用WriteStartAtribute方法往創立一個新的屬性節點,更新Writer的狀態。接著用WriteString方法設定屬性值。寫完後,用WriteEndElement方法結束該節點。另外,你也可以用WriteAttributeString方法往創立新的屬性節點,當writerr的狀態為Element時,WriterAttributeString開端工作,它單獨創立一個屬性。同樣的,WriteStartElement方法寫節點的開端標籤(”。假如想寫閉標籤可以用WriteFullEndElement方法來寫。
??應避免傳送給寫入方法的文字中包含敏感的標記字符,例如小於號(
writer.WriteString('
writer.WriteRaw('