XmlWriterSettings.OmitXmlDeclaration Proprietà

Definizione

Ottiene o imposta un valore che indica se omettere una dichiarazione XML.

public:
 property bool OmitXmlDeclaration { bool get(); void set(bool value); };
public bool OmitXmlDeclaration { get; set; }
member this.OmitXmlDeclaration : bool with get, set
Public Property OmitXmlDeclaration As Boolean

Valore della proprietà

Boolean

true per omettere la dichiarazione XML; in caso contrario, false. Il valore predefinito è false (viene scritta una dichiarazione XML).

Esempio

Nell'esempio seguente viene scritto un frammento XML in un flusso di memoria.

XmlWriterSettings settings = new XmlWriterSettings();
settings.OmitXmlDeclaration = true;
settings.ConformanceLevel = ConformanceLevel.Fragment;
settings.CloseOutput = false;

// Create the XmlWriter object and write some content.
MemoryStream strm = new MemoryStream();
XmlWriter writer = XmlWriter.Create(strm, settings);
writer.WriteElementString("orderID", "1-456-ab");
writer.WriteElementString("orderID", "2-36-00a");
writer.Flush();
writer.Close();

// Do additional processing on the stream.
Dim settings As XmlWriterSettings = New XmlWriterSettings()
settings.OmitXmlDeclaration = true
settings.ConformanceLevel = ConformanceLevel.Fragment
settings.CloseOutput = false

' Create the XmlWriter object and write some content.
Dim strm as MemoryStream = new MemoryStream()
Dim writer As XmlWriter = XmlWriter.Create(strm, settings)
writer.WriteElementString("orderID", "1-456-ab")
writer.WriteElementString("orderID", "2-36-00a")
writer.Flush()
writer.Close()

' Do additional processing on the stream.

Commenti

Questa proprietà si applica solo alle XmlWriter istanze che generano contenuto di testo. In caso contrario, questa impostazione viene ignorata.

Se OmitXmlDeclaration è impostato su false, la dichiarazione XML viene scritta automaticamente

La dichiarazione XML viene sempre scritta se ConformanceLevel è impostata su Document, anche se OmitXmlDeclaration è impostata su true.

La dichiarazione XML non viene mai scritta se ConformanceLevel è impostata su Fragment. È possibile chiamare WriteProcessingInstruction per scrivere in modo esplicito una dichiarazione XML.

Si applica a