XmlDocument xmlDoc = new XmlDocument();
//创建根节点
XmlElement root = xmlDoc.CreateElement("Books");
xmlDoc.AppendChild(root);
XmlNode book;
for (int i = 0; i < 10; i++)
{
book = xmlDoc.CreateElement("file");
book.InnerText = string.Concat("file", i.ToString());
root.AppendChild(book);
}
StringWriter sw =new StringWriter();
XmlTextWriter xw =new XmlTextWriter(sw);
// Save Xml Document to Text Writter.xmlDoc.WriteTo(xw);
System.Text.ASCIIEncoding encoding =new System.Text.ASCIIEncoding();
// Convert Xml Document To Byte Array.byte[] docAsBytes = encoding.GetBytes(sw.ToString());
//from stream of xmldocument ,out put element.
Stream st = (Stream)xmlstream;
XDocument xd = XDocument.Load(st);
//var aa=from aa in xd.n
var aa = from bb in xd.Descendants("file")
select bb.Value;
foreach (var item in aa)
{
str += item.ToString();
}