■ XmlTextWriter 클래스 : XML 문서 생성하기

----------------------------------------------------------------------------------------------------

using System.Xml;

 

string targetFilePath = "c:\\sample.xml";

 

XmlTextWriter xmlTextWriter = new XmlTextWriter(targetFilePath, null);

 

xmlTextWriter.Formatting = Formatting.Indented;

 

xmlTextWriter.WriteStartDocument(false);

 

xmlTextWriter.WriteDocType("bookstore", null, "books.dtd", null);

 

xmlTextWriter.WriteComment("This file represents another fragment of a book store inventory database");

 

xmlTextWriter.WriteStartElement("book", null);

 

    xmlTextWriter.WriteAttributeString("genre"          , "autobiography");

    xmlTextWriter.WriteAttributeString("publicationdate", "1979"         );

    xmlTextWriter.WriteAttributeString("ISBN"           , "0-7356-0562-9");

 

    xmlTextWriter.WriteElementString("title", null, "The Autobiography of Mark Twain");

 

    xmlTextWriter.WriteStartElement("Author", null);

 

        xmlTextWriter.WriteElementString("first-name", "Mark");

        xmlTextWriter.WriteElementString("last-name", "Twain");

 

    xmlTextWriter.WriteEndElement();

 

    xmlTextWriter.WriteElementString("price", "7.99");

 

xmlTextWriter.WriteEndElement();

 

xmlTextWriter.Flush();

 

xmlTextWriter.Close();

----------------------------------------------------------------------------------------------------

Posted by 사용자 icodebroker

댓글을 달아 주세요