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

C#显示XML元素内容的简单例子

接上一篇
显示所有结点的内容
1 原xml文件 bookstore.xml
<?xml version="1.0" encoding="gb2312"?>
<bookstore>
  <book ISBN="1234123">
    <title>who am i </title>
    <author>who</author>
    <price>999</price>
  </book>
  <book>
  </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");
            XmlNode xn = xmlDoc.SelectSingleNode("bookstore");
            XmlNodeList xnl = xn.ChildNodes;
            foreach (XmlNode xnf in xnl)
            {
                XmlElement xe = (XmlElement)xnf;
                //该属性没有,不显示,但不会报错
                Console.WriteLine(xe.GetAttribute("genre"));
                //显示属性值
           &nb


相关文档:

XML 增删改查

using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Xml;
using System.Data;
public class Cls_XML
{
    #region 创建xml文件
    /// <summary>
    /// 创建xml文件
    /// ......

FOR XML PATH举例

大家都知道在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, ......

xml中特殊符号的转换

调试时发现日志报如下错误 org.xml.sax.SAXParseException
发现是xml对特殊符号要做处理,几个特殊符号如下:
&lt; < 小于号
&gt; > 大于号
&amp; & 和
&apos; ' 单引号
&quot; " 双引号
在xml中把特殊符号用上述转下即好了 ......

C#修改XML的简单例子

接上一篇《C#写XML的简单例子》
这个例子要修改XML文件中结点的属性和和元素的文本
1 原xml文件 bookstore.xml
<?xml version="1.0" encoding="gb2312"?>
<bookstore>
  <book genre="love" ISBN="1234123">
    <title>who am i </title>
    &l ......

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</aut ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号