易截截图软件、单文件、免安装、纯绿色、仅160KB

把XMLDocument转换成xml字符串

XMLDocument类提供了丰富的属性和方法,可以帮助我们轻松完成xml的编辑。但是,完成后的xml很多情况下可能还是需要以字符串形式传递。XMLDocument有个Save方法,不仅可以保存XML文件至磁盘,还能将其保存至指定的流,然后,就能从这个流(stream)读取所需要的字符串了。
XmlDocument doc = new XmlDocument();
...
...//生成xml的代码
实例化一个流,并将生成的XMLDocument保存在其中:
MemoryStream stream = new MemoryStream();
XmlTextWriter writer = new XmlTextWriter(stream, null);
writer.Formatting = Formatting.Indented;
doc.Save(writer);
声明一个StreamReader,用于读取刚才那个Stream中的数据到一个字符串变量
StreamReader sr = new StreamReader(stream, Encoding.UTF8);
stream.Position = 0;
string XMLString = sr.ReadToEnd();
sr.Close();
stream.Close();
********


相关文档:

ASP.NET/XML深入编程技术

这是关于Asp.Net/XML深入编程的技术书,作者精心设计了66个实例详细介绍了.Net   Framework以及XML技术在.Net   Framework的编程方法和技巧。全书由12章构成,内容包括.Net平台的建立、Asp.Net的Web   Forms、控件、数据访问、Web   Service、Asp.Net的设置和跟踪、Asp.Net的安全 ......

XML 语法规则


转自:http://www.w3school.com.cn/xml/xml_syntax.asp
XML 的语法规则很简单,且很有逻辑。这些规则很容易学习,也很容易使用。
所有 XML 元素都须有关闭标签
在 HTML,经常会看到没有关闭标签的元素:
<p>This is a paragraph
<p>This is another paragraph
在 XML 中,省略关闭标签是非法的。所有元 ......

GridView 操作XML文件

<?xml version="1.0" standalone="yes"?>
<imgs>
<pic name="/adv_pic/1.jpg" url="http://www.baidu.com/" title="test" />
<pic name="/adv_pic/2.jpg" url="http://www.baidu.com/" title="test" />
......

Parsing XML from the Net Using the SAXParser


Parsing XML from the Net - Using the SAXParser
http://www.anddev.org/parsing_xml_from_the_net_-_using_the_saxparser-t353.html
What you learn:
You will learn how to properly parse XML
(here: from the net
) using a SAXParser
.
What it will look like:
Description:
0.)
In this tutorial we ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号