XmlDocument to Byte[] and bytes[] to xmldocument or xdocument.
来源:互联网 发布:no sleep mac下载 编辑:程序博客网 时间:2024/06/11 07:44
一 、 XmlDocument to Byte[]
//create xmldocument
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(); }
二 byte[] to xmldocument or XDocument
byte[]stream =new byte[1000]
.
.
. 中间操作是把xmldocument 流写入到 stream 中 或是从别处传来的已有值的 byte[]。
MemoryStream memoryStream=new MemoryStream(stream);
XmlReader xmlreader = new XmlTextReader(memoryStream); XmlDocument xmldocumet = new XmlDocument(); xmldocumet.Load(xmlreader); (或 XDocument xd = new XDocument();
xd.load(xmlreader)
)
- XmlDocument to Byte[] and bytes[] to xmldocument or xdocument.
- XmlDocument to Byte[] and bytes[] to xmldocument or xdocument.
- Emgu Image[Bgr, Byte] image to XmlDocument
- XmlDocument转换为XDocument
- XmlDocument,XDocument相互转换
- XmlDocument与XDocument
- DataSet To XmlDocument
- XmlDocument
- 从XmlDocument到XDocument的转换
- XmlDocument和XDocument搜索xml比较
- XML(2)通过XmlDocument与XDocument方式写入XML
- XML(3)XDocument与XmlDocument递归读取xml文件
- XML(4)XDocument和XmlDocument搜索指定的节点
- C# XML技术总结之XDocument 和XmlDocument
- byte[] to file or file to byte[]
- Failed to allocate a 76 byte allocation with 0 free bytes and 0B until OOM
- java.lang.OutOfMemoryError: Failed to allocate a 3110419 byte allocation with 741152 free bytes and
- Failed to allocate a 38189038 byte allocation with 16777216 free bytes and 20MB until OOM
- LINQ to SQL语句(1)之Where
- android in practice_create and start a service(portfolio project)
- 八大經方治感冒
- LINQ to SQL语句(2)之Select/Distinct
- Iterator模式
- XmlDocument to Byte[] and bytes[] to xmldocument or xdocument.
- add-apt-repository用法
- 进程同步互斥——读者写者问题
- vim - cannot save backup file
- LINQ to SQL语句(3)之Count/Sum/Min/Max/Avg
- 一套完整自定义工作流的实现
- hdu 2035
- js动态合并表格单元格
- 明年货币政策或宽松