XmlWriterSettings.NewLineOnAttributes 属性

定义

获取或设置一个值,该值指示是否在新行上写入属性。

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

属性值

Boolean

如果将特性写入单独的行,则为 true;否则,为 false。 默认值为 false

示例

以下示例创建一个 XmlWriter 写入 XML 文件并在新行上写入每个属性。

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 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()

此示例生成以下输出:

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

注解

此属性仅适用于 XmlWriter 输出文本内容的实例;否则,将忽略此设置。

true设置为时NewLineOnAttributes,每个属性都以新行和一个额外的缩进级别为前面。

如果 Indent 属性值为 false,则此设置无效。

适用于