XmlWriterSettings.OmitXmlDeclaration Właściwość

Definicja

Pobiera lub ustawia wartość wskazującą, czy pominąć deklarację 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

Wartość właściwości

true pomijanie deklaracji XML; w przeciwnym razie , false. Wartość domyślna to false, jest zapisywana deklaracja XML.

Przykłady

Poniższy przykład zapisuje fragment XML w strumieniu pamięci.

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.

Uwagi

Ta właściwość ma zastosowanie tylko do XmlWriter wystąpień wyjściowych zawartości tekstowej. W przeciwnym razie to ustawienie jest ignorowane.

Jeśli OmitXmlDeclaration jest ustawiona wartość false, deklaracja XML jest zapisywana automatycznie

Deklaracja XML jest zawsze zapisywana, jeśli ConformanceLevel jest ustawiona na Documentwartość , nawet jeśli OmitXmlDeclaration jest ustawiona na truewartość .

Deklaracja XML nigdy nie jest zapisywana, jeśli ConformanceLevel jest ustawiona na Fragmentwartość . Można wywołać WriteProcessingInstruction metodę jawnego zapisania deklaracji XML.

Dotyczy