C#中XML的初步使用

#c:\\xml\\a.xml

<?xml version="1.0" encoding="GB2312"?>
<Config>
    <user value="1.0">用户一</user>     1
    <user value="1.1">用户二</user>     2
    <user value="1.2">                             3
        <name>刀疤</name>
        <old>20</old>
        <tel>02880773281</tel>
    </user>
</Config>

加入命名空间:using System.Xml;

XmlDocument doc = new XmlDocument();
doc.Load("c:\\xml\\a.xml");
XmlElement root = doc.DocumentElement;
// 获得1的值与属性
root.SelectNodes("user")[0].InnerText;  // 值
root.SelectNodes("user")[0].Attributes[0].InnerText;  // 属性

// 获得2的值与属性
root.SelectNodes("user")[1].InnerText;
root.SelectNodes("user")[1].Attributes[0].InnerText;

// 获得3的属性与old节
root.SelectNodes("user")[2].Attributes[0].InnerText; // 属性
root.SelectNodes("user")[2]["old"].InnerText; // OLD节

posted on 2006-01-25 12:38 samuel's blog 阅读(670) 评论(0)  编辑 收藏 网摘 所属分类: C#




发表评论

昵称: [登录] [注册]

主页:

邮箱:(仅博主可见)

评论内容:

  登录  注册

[使用Ctrl+Enter键快速提交评论]

0 323105




相关文章:

相关链接:

导航

统计

与我联系

搜索

 

常用链接

留言簿

随笔分类

随笔档案

文章分类

相册

连接

最新随笔

最新评论

阅读排行榜