先构造一棵XML树如下,
public void CreatXmlTree(string xmlPath)
{
XElement xElement = new XElement(
new XElement("BookStore",
new XElement("Book",
new XElement("Name", "C#入门", new XAttribute("BookName", "C#")),
new XElement("Author", "Martin", new XAttribute("Name", "Martin")),
new XElement("Adress", "上海"),
new XElement("Date", DateTime.Now.ToString("yyyy-MM-dd"))
),
new XElement("Book",
new XElement("Name", "WCF入门", new XAttribute("BookName", "WCF")),
new XElement("Author", "Mary", new XAttribute("Name", "Mary")),
new XElement("Adress", "北京"),
new XElement("Date", DateTime.Now.ToString("yyyy-MM-dd"))
)
)
);
然后得到如下的XML树
<?xml version="1.0" encoding="utf-8"?>
<BookStore>
<Book>
<Name BookName="C#">C#入门</Name>
<Author Name="Martin">Martin</Author>
<Date>2013-10-11</Date>
<Adress>上海</Adress>
<Date>2013-10-11</Date>
</Book>
<Book>
<Name BookName="WCF">WCF入门</Name>
<Author Name="Mary">Mary</Author>
<Adress>北京</Adress>
<Date>2013-10-11</Date>
</Book>
</BookStore>