操作XML
操作XML
using System;
using System.IO;
using System.Xml;
using System.Text;
public class xml
{
public static void Main(String [] Args)
{
try
{
string fileName="booknew.xml";
XmlTextWriter tw=new XmlTextWriter(fileName,null);
tw.Formatting=Formatting.Indented;
tw.WriteStartDocument();
tw.WriteStartElement("book");
tw.WriteAttributeString("genre","Mystery");
tw.WriteAttributeString("ISBN","123456789");
tw.WriteElementString("title","Case of the Missing Cookie");
tw.WriteStartElement("author");
tw.WriteElementString("name","Cookie Monster");
tw.WriteEndElement();
tw.WriteElementString("price","9.99");
tw.WriteEndElement();
tw.WriteEndDocument();
tw.Flush();
tw.Close();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
Console.ReadLine();
}
}
using System.IO;
using System.Xml;
using System.Text;
public class xml
{
public static void Main(String [] Args)
{
try
{
string fileName="booknew.xml";
XmlTextWriter tw=new XmlTextWriter(fileName,null);
tw.Formatting=Formatting.Indented;
tw.WriteStartDocument();
tw.WriteStartElement("book");
tw.WriteAttributeString("genre","Mystery");
tw.WriteAttributeString("ISBN","123456789");
tw.WriteElementString("title","Case of the Missing Cookie");
tw.WriteStartElement("author");
tw.WriteElementString("name","Cookie Monster");
tw.WriteEndElement();
tw.WriteElementString("price","9.99");
tw.WriteEndElement();
tw.WriteEndDocument();
tw.Flush();
tw.Close();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
Console.ReadLine();
}
}