XmlWriterSettings.NewLineOnAttributes XmlWriterSettings.NewLineOnAttributes XmlWriterSettings.NewLineOnAttributes XmlWriterSettings.NewLineOnAttributes Property

定義

取得或設定值,指出是否將屬性寫在新行上。Gets or sets a value indicating whether to write attributes on a new line.

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

屬性值

true 表示將屬性寫在獨立的行上,否則為 falsetrue to write attributes on individual lines; otherwise, false. 預設為 falseThe default is false.

Indent 屬性值為 false 時,這項設定沒有影響。This setting has no effect when the Indent property value is false.

NewLineOnAttributes 設為 true 時,會在每個屬性之前加上新行和一個額外的縮排層級。When NewLineOnAttributes is set to true, each attribute is pre-pended with a new line and one extra level of indentation.

範例

下列範例會建立XmlWriter,寫入至 XML 檔案,並寫入新行上的每個屬性。The following example creates an XmlWriter that writes to an XML file and writes each attribute on a new line.

XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.OmitXmlDeclaration = true;
settings.NewLineOnAttributes = true;
       
writer = XmlWriter.Create(Console.Out, settings);

writer.WriteStartElement("order");
writer.WriteAttributeString("orderID", "367A54");
writer.WriteAttributeString("date", "2001-05-03");
writer.WriteElementString("price", "19.95");
writer.WriteEndElement();
	
writer.Flush();
Dim settings As XmlWriterSettings = New XmlWriterSettings()
settings.Indent = true
settings.OmitXmlDeclaration = true
settings.NewLineOnAttributes = true
       
writer = XmlWriter.Create(Console.Out, settings)

writer.WriteStartElement("order")
writer.WriteAttributeString("orderID", "367A54")
writer.WriteAttributeString("date", "2001-05-03")
writer.WriteElementString("price", "19.95")
writer.WriteEndElement()
	
writer.Flush()

此範例會產生下列輸出:The sample produces the following output:

<order  
  orderID="367A54"  
  date="2001-05-03">  
  <price>19.95</price>  
</order>  

備註

此屬性只適用於XmlWriter執行個體的輸出文字的內容; 否則會忽略此設定。This property only applies to XmlWriter instances that output text content; otherwise, this setting is ignored.

適用於