如何生成类似于下面这个xml文档,请各位高手帮下忙~~~<?xml version="1.0" >
<bookstore>
<book genre="fantasy" ISBN="2-3631-4">
<title>Oberon's Legacy</title>
<author>Corets, Eva</author>
<price>5.95</price>
</book>
<book genre="李红" ISBN="2-3631-4">
<title>C# 从入门到精通</title>
<author>候捷</author>
<price>58</price>
</book>
</bookstore>
数据都是从数据库里读取的,生成的文档的元素和属性有可能不是上面那些,但是大致就是上面那个意思,应该如何做呢?
<bookstore>
<book genre="fantasy" ISBN="2-3631-4">
<title>Oberon's Legacy</title>
<author>Corets, Eva</author>
<price>5.95</price>
</book>
<book genre="李红" ISBN="2-3631-4">
<title>C# 从入门到精通</title>
<author>候捷</author>
<price>58</price>
</book>
</bookstore>
数据都是从数据库里读取的,生成的文档的元素和属性有可能不是上面那些,但是大致就是上面那个意思,应该如何做呢?
Sqldataadapter ada = new (sqlcommand);
ada.fill(dataset);
dataset.writeXML();
dateset.Writexml(),最为简单,也最接近楼主的需要
bookstore 是一个 List<book> 实例。public class book
{
[XmlAttribute]
public string genre {get; set;}
[XmlAttribute]
public string ISBN {get; set;}
public string title {get; set;}
public string author {get; set;}
public string price {get; set;}
}