SaveOptions 列舉

定義

指定序列化選項。Specifies serialization options.

此列舉有 FlagsAttribute 屬性,因此其成員值可進行位元組合。

public enum class SaveOptions
[System.Flags]
public enum SaveOptions
[<System.Flags>]
type SaveOptions = 
Public Enum SaveOptions
繼承
SaveOptions
屬性

欄位

DisableFormatting 1

當序列化時保留所有不重要的泛空白字元。Preserve all insignificant white space while serializing.

None 0

當序列化時格式化 (縮排) XML。Format (indent) the XML while serializing.

OmitDuplicateNamespaces 2

當序列化時移除重複的命名空間宣告。Remove the duplicate namespace declarations while serializing.

範例

下列範例顯示兩個序列化方式。The following example shows two ways to serialize. 第一個會保留 XML 樹狀結構中的無意義空白字元。The first preserves insignificant white space in the XML tree. 第二個會 XElement 使用格式來序列化。The second serializes the XElement with formatting.

string str;  
XElement root = XElement.Parse(@"<Root> <Child> Text </Child> </Root>");  

root.Save("Root.xml", SaveOptions.DisableFormatting);  
str = File.ReadAllText("Root.xml");  
Console.WriteLine(str);  

Console.WriteLine("=====");  

root.Save("Root.xml", SaveOptions.None);  
str = File.ReadAllText("Root.xml");  
Console.WriteLine(str);  
Dim str As String  
Dim root As XElement = <Root><Child> Text </Child></Root>  

root.Save("Root.xml", SaveOptions.DisableFormatting)  
str = File.ReadAllText("Root.xml")  
Console.WriteLine(str)  

Console.WriteLine("=====")  

root.Save("Root.xml", SaveOptions.None)  
str = File.ReadAllText("Root.xml")  
Console.WriteLine(str)  

這個範例會產生下列輸出:This example produces the following output:

<?xml version="1.0" encoding="utf-8"?><Root><Child> Text </Child></Root>  
=====  
<?xml version="1.0" encoding="utf-8"?>  
<Root>  
  <Child> Text </Child>  
</Root>  

備註

如果您在序列化時停用格式,則 XML 樹狀結構中的所有無意義空白字元都會依原樣序列化。If you disable formatting when serializing, all insignificant white space in the XML tree is serialized as is. 如果您未停用格式設定,則會捨棄 XML 樹狀結構中的所有無意義空白字元,並且會將 XML 格式化 (在序列化時) 縮排。If you do not disable formatting, then all insignificant white space in the XML tree is discarded, and the XML is formatted (indented) as it is serialized.

此類型可讓您控制 LINQ to XML 在序列化時如何處理空白字元。This type allows you to control how LINQ to XML handles white space when serializing. 如需詳細資訊,請參閱 在載入或剖析 XML 時保留空白字元 ,以及序列化 時保留空白字元For more information, see Preserve white space while loading or parsing XML and Preserve white space while serializing.

適用於

另請參閱