SaveOptions Enum

Definition

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

This enumeration has a FlagsAttribute attribute that allows a bitwise combination of its member values.

public enum class SaveOptions
[System.Flags]
public enum SaveOptions
type SaveOptions = 
Public Enum SaveOptions
Inheritance
SaveOptions
Attributes

Fields

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.

Examples

下列範例顯示兩種序列化方式。The following example shows two ways to serialize. 第一個會在 XML 樹狀結構中保留無意義的空白字元。The first preserves insignificant white space in the XML tree. 第二個會使用格式來序列化 XElementThe 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>  

Remarks

如果您在序列化時停用格式化,則 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 Preserving White Space while Loading or Parsing XML and Preserving White Space While Serializing.

Applies to

See also