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
相关文档:
Spring是一个强有力的java程序框架,其被广泛应用于java的程序中。它用POJO提供了企业级服务。Spring利用依赖注入可以获得简单而有效的测试能力。Spring beans,依赖关系,以及服务所需要的bean都将在配置文件中予以描述,配置文件一般采用XML格式。然而XML配置文件冗长而不易使用,在你进行一个使用了大量bean的大项目中它 ......
xml文件:
<?xml version="1.0" encoding="iso-8859-1"?>
<Products>
<product>
<name>lovechoosesun</name>
<buyNowURL>http://merch.danecook ......
最近在工作中,经常设计报表(ireport+jasperReport)反复和设计模板xml打交道,于是就有了写这篇文章的想法了。java操作xml主要是有四种方式:dom,sax,jdom,dom4j。这四种方式各有优缺点:(以下比较是来自网络)
1:DOM4J性能最好,连Sun的JAXM也在用DOM4J.目前许多开源项目中大量采用DOM4J,例如大名鼎鼎的Hibernate ......
■ 开发前要求配置
■ Select XML格式数据
■ Insert XML格式数据
■ Updata XML格式数据
■ Delete XML格式数据
开发前要求配置
必须安装Oracle客户端
把Classpath指向
classes111.zip ......
源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 ......