C#删除XML结点的简单例子
接上一篇
删除原genre属性,删除leixing=love的所有结点。
1 原xml文件 bookstore.xml
<?xml version="1.0" encoding="gb2312"?>
<bookstore>
<book genre="love" ISBN="1234123">
<title>who am i </title>
<author>who</author>
<price>999</price>
</book>
<book leixing="love" ISBN="56756">
<title>CS从入门到精通</title>
<author>黎明</author>
<price>222</price>
</book>
</bookstore>
2 program.cs
using System;
using System.Xml;
namespace ReadXml
{
class Class1
{
static void Main(string[] args)
{
//实例化一个XmlDocument对象
XmlDocument xmlDoc = new XmlDocument();
//实例对象读取要写入的XML文件
xmlDoc.Load("bookstore.xml");
XmlNodeList xnl = xmlDoc.SelectSingleNode("bookstore").ChildNodes;
foreach (XmlNode xn in xnl)
{
XmlElement xe = (XmlElement)xn;
if (xe.GetAttribute("genre") == "love")
{
&n
相关文档:
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Syste ......
Ajax和jsp的怪现象
如果用Ajax去请求一个jsp页面,该jsp页面返回的是xml(response.setContentType("text/xml; charset=GB2312");),并且该jsp包含下面这些头@page指令的话,则在客户端xml=XMLHttpRequest.responseXML得到的是一个不包含任务东西的xml对象,即xml.childNodes.length将会是0.
......
大家都知道在SQL Server中利用 FOR XML PATH 语句能够把查询的数据生成XML数据,下面是它的一些应用示例。
DECLARE @TempTable table(UserID int , UserName nvarchar(50));
insert into @TempTable (UserID,UserName) values (1,'a')
insert into @TempTable (UserID,UserName) values (2,'b')
select UserID, ......
这个例子要把bookstore.xml文件增加一条book记录
1 bookstore.xml
<?xml version="1.0" encoding="gb2312"?>
<bookstore>
<book genre="love" ISBN="1234123">
<title>who am i </title>
<author>who</author>
  ......
序列化是将对象转换成易于传输的形式的过程。例如,可以序列化对象,并使用 HTTP 通过 Internet 在客户端和服务器之间进行传输。另一方面,反序列化在流中重新构建对象。
XML 序列化只将对象的公共字段和属性值序列化为 XML 流。XML 序列化不包括类型信息。例如,如果 Library 命名空间中存在 Book 对象,则不能保证将它反 ......