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

C#操作xml文件入门(后附示例源代码)

          ~/    在runat=server的控件中,自动的被解析为Request.ApplicationPath的值,是当前应用程序级程序的目录     在例子中是:/WebSite
          ./或者什么都不写:表示当前目录,./teacup.jpg和teacup.jpg都表示当前网页所在目录下的teacup.jpg文件
         ../表示上一层目录,比如http://www.cnblogs.com/../teacup.jpg就表示当前网页所在目录的上三层的目录下的一个teacup.jpg文件,
          /表示根目录,一般表示为:系统盘下的Inetpub\wwwroot
已知有一个XML文件(bookstore.xml)如下:
<?xml version="1.0" encoding="gb2312"?>
<bookstore>
<book genre="fantasy" ISBN="2-3631-4">
<title>Oberon's Legacy</title>
<author>Corets, Eva</author>
<price>5.95</price>
</book>
</bookstore>
1、往<bookstore>节点中插入一个<book>节点:
XmlDocument xmlDoc=new XmlDocument();
xmlDoc.Load("bookstore.xml");
XmlNode root=xmlDoc.SelectSingleNode("bookstore");//查找<bookstore>
XmlElement xe1=xmlDoc.CreateElement("book");//创建一个<book>节点
xe1.SetAttribute("genre","李赞红");//设置该节点genre属性
xe1.SetAttribute("ISBN","2-3631-4");//设置该节点ISBN属性
XmlElement xesub1=xmlDoc.CreateElement("title");
xesub1.InnerText="CS从入门到精通";//设置文本节点
xe1.AppendChild(xesub1);//添加到<book>节点中
XmlElement xesub2=xmlDoc.CreateElement("author");
xesub2.InnerText="候捷";
xe1.AppendChild(xesub2);
XmlElement xesub3=xmlDoc.CreateElement("price");
xesub3.InnerText="58.3";
xe1.AppendChild(xesub3);
root.AppendChild(xe1);//添加到<bookstore>节点中
xmlDoc.Save("bookstore.xml");
//================
结果为:
<?xml version="1.0" encoding="gb2312"?>
<bookstore>
<book genre="fantasy" ISBN="2-3631-4">
<title>Oberon's Legacy</title>
<author>Corets, E


相关文档:

超级简单:使用FOR XML AUTO控制XML输出(译转)

这篇文章描述如何通过使用FOR XML AUTO更好的控制XML输出格式。例如添加XML标记。用这个来替代难于理解的FOR XML EXPLICIT 语句。如果你在应用程序中即将反序列化输出的XML,你就会觉得这个信息对你有用。
    在For XML从句中,您通常使用下列方式之一:
    RAW
    AUT ......

grails解析xml文件

xml文件:
<?xml version="1.0" encoding="iso-8859-1"?>
<Products>
    <product>
        <name>lovechoosesun</name>
        <buyNowURL>http://merch.danecook ......

flex学习 flex读取xml文件

源xml文件
 <?xml version="1.0" encoding="iso-8859-1"?>
<books>
<stock>
<name>The Picasso Code</name>
<author>Dan Blue</author>
<category>Fiction</category>
<description>Cubist paintings reveal a secret society of people ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号