Writing Attributes

You can write attributes immediately after writing a start element:


using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Xml;
using System.Xml.Linq;
using System.Text;
using System.IO;
class Program
{
    static void Main()
    {
        XmlWriterSettings settings = new XmlWriterSettings();
        settings.Indent = true;

        using (XmlWriter writer = XmlWriter.Create("foo.xml", settings))
        {

            writer.WriteStartElement("customer");
            writer.WriteAttributeString("id", "1");
            writer.WriteAttributeString("status", "archived");
        }
    }
}

The content of foo.xml

java2s.com  |  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.