C# 中xmlreader类的实用源码演示

下面内容段是关于C# 中xmlreader类的实用演示的内容。

protected void Page_Load(object sender, EventArgs e)
        {
            int i = 0;
            XmlReaderSettings set=new XmlReaderSettings();
            set.IgnoreComments=true;
            set.IgnoreWhitespace=true;
            using (XmlReader reader = XmlReader.Create(Server.MapPath("books.xml"), set)) {
                while (reader.Read()) {
                    if (reader.NodeType == XmlNodeType.Element) {
                        if (reader.LocalName == "book") {
                            i++;
                        }
                    }
                }
                Response.Write("<script>alert('共有" + i.ToString() + "本书')</script>");
            }
           
        }
 

                                
                        
                                
xml文档内容
                                
                        
                                

<?xml version="1.0" encoding="utf-8"?>
<books>
  <book>
    <author>张三</author>
    <publisher>清华大学出版社</publisher>
    <date>2009-1-1</date>
    <name>ASP.NET实训教程</name>
    <isbn>978-7-333-20981-4</isbn>
    <price>50.00</price>
  </book>
  <book>
    <author>李四</author>
    <publisher>机械工业出版社</publisher>
    <date>2009-6-8</date>
    <name>ASP.NET详解</name>
    <isbn>978-7-333-20332-1</isbn>
    <price>45.00</price>
  </book>
  <book>
    <author>王五</author>
    <publisher>电子工业出版社</publisher>
    <date>2010-10-9</date>
    <name>C#程序设计</name>
    <isbn>978-7-311-21231-2</isbn>
    <price>50.00</price>
  </book>
  <book>
    <author>张飞</author>
    <publisher>机械工业出版社</publisher>
    <date>2008-4-12</date>
    <name>.NET设计模式</name>
    <isbn>978-7-310-12341-9</isbn>
    <price>30.00</price>
  </book>
</books>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
C# XML文件读写操作源码,以及如何调用,注释详解,有任何问题请留言, 以下截取xml文件和部分调用代码段: * ++++++++++++++++++++++++++++++++++++++ <?xml version="1.0" encoding="utf-8" standalone="no"?> <!--TestPlugins的信息--> <!--DataPlugins的信息--> * ++++++++++++++++++++++++++++ xml xl = new xml(); xl.XMLWriteRootNode("info"); //XmlElement Eml1 = xl.XMLReadNode("",0); //XmlElement Eml2 = xl.XMLReadNode("DataPlugins", 1); //XmlElement Eml4 = xl.XMLReadNode("DeviceInfo", 2); // TestPlugins XmlElement testPlugins = xl.XMLCreateNode("TestPlugins", null, null); xl.XMLInsertNode("info", 0, "TestPlugins的信息", testPlugins); // FixturePlugin XmlElement fixturePlugin = xl.XMLCreateNode("TestPlugin", null, new Dictionary() { { "Type", "FixturePlugin" } }); xl.XMLInsertNode(testPlugins.LocalName, 1, null, fixturePlugin); // DUTPlugin XmlElement DUTPlugin = (XmlElement)fixturePlugin.CloneNode(true);// xl.XMLCreateNode("TestPlugin", null, new Dictionary() { { "Type", "DUTPlugin" } }); DUTPlugin.SetAttribute("Type", "DUTPlugin"); xl.XMLInsertNode(testPlugins.LocalName, 1, null, DUTPlugin); // Agilent34461APlugin XmlElement Agilent34461APlugin = xl.XMLCreateNode("TestPlugin", null, new Dictionary() { { "Type", "Agilent34461APlugin" } }); xl.XMLInsertNode(testPlugins.LocalName, 1, null, Agilent34461APlugin); // ================================== // DataPlugins XmlElement dataPlugins = xl.XMLCreateNode("DataPlugins", null, null); xl.XMLInsertNode("info", 0, "DataPlugins的信息", dataPlugins); // CSVLogPlugin XmlElement csvlogPlugin = xl.XMLCreateNode("DataPlugin", null, new Dictionary() { { "Type", "CSVLogPlugin" } }); xl.XMLInsertNode(dataPlugins.LocalName, 1, null, csvlogPlugin); XmlElement uartlogPlugin = (XmlElement)csvlogPlugin.CloneNode(true); uartlogPlugin.SetAttribute("Type", "UartLogPlugin"); xl.XMLInsertNode(dataPlugins.LocalName, 1, null, uartlogPlugin); XmlElement testlogPlugin = (XmlElement)csvlogPlugin.CloneNode(true); testlogPlugin.SetAttribute("Type", "TestLogPlugin"); xl.XMLInsertNode(dataPlugins.LocalName, 1, null, testlogPlugin); }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值