您的位置:程序门 -> .net技术 -> c#



如何实现对xml里面数据的查询,修改,删除操作


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


如何实现对xml里面数据的查询,修改,删除操作
发表于:2007-01-19 14:00:30 楼主
我想写一登录窗口,想把用户名,密码放在xml里面,请问如何实现对它里面的数据的操作
发表于:2007-01-19 14:05:351楼 得分:0
数据量不大的话可以使用dom
发表于:2007-01-19 14:16:582楼 得分:0
我是新手,帮你顶呀
发表于:2007-01-19 14:22:513楼 得分:0
能给点具体的代码吗?
在   应用程序下面的,先谢谢了
发表于:2007-01-19 14:49:234楼 得分:0
修改有很多办法的比如用createnavigator()建立一个system.xml.xpath.xpathnavigator   导航,楼主,或者直接修改节点的innerxml,
最好事先看看msdn里的xml知识背景
发表于:2007-01-19 16:06:315楼 得分:0
xml里面的数据能像   数据库那样可以有条件的查询,修改吗?
发表于:2007-01-19 16:31:466楼 得分:0
我记得可以,好像可以把它放入一个dataset对象中,就像对数据库进行操作一样
发表于:2007-01-19 16:40:177楼 得分:0
谢谢了,我再好好看一下msdn   吧
发表于:2007-01-19 17:01:338楼 得分:0
给你一个链接,c#操作xml...

http://www.blogcn.com/user63/rhfan2005/blog/25161802.html
发表于:2007-01-19 17:28:259楼 得分:0
用xpath吧,速度快,方便.
发表于:2007-01-19 19:46:5610楼 得分:0
dataset.readxml();
好象是这个东西!
发表于:2007-01-20 22:44:2811楼 得分:0
using   system;
using   system.io;
using   system.text;
using   system.diagnostics;
using   system.threading;
using   system.collections;
using   system.data;
using   system.xml;
using   system.management;
using   system.net;


namespace   zhzuo
{
class   zzconsole
{
[stathread]
static   void   main(string[]   args)
{
string   strxml= " <?xml   version=\ "1.0\ "?> "
+ " <data> "
+ " <head> "
+ " <nodeid> 1111 </nodeid> "
+ " <subid> 2222 </subid> "
+ " <version> 2004 </version> "
+ " <date> 20040302 </date> "
+ " <time> 101500 </time> "
+ " </head> "
+ " <body> "
+ " <code> 01 </code> "
+ " <name> 深圳 </name> "
+ " <idtype> 0 </idtype> "
+ " <idno> 110258740824082 </idno> "
+ " </body> "
+ " </data> ";
xmldocument   doc   =   new   xmldocument();
doc.loadxml(strxml);
string   vv;

xmlnodelist   mynodes   =   doc.getelementsbytagname( "version ");
vv   =   mynodes[0].innertext;
//修改
mynodes[0].innertext   =   "123455 ";
console.writeline(vv);
mynodes   =   doc.selectnodes( "//version ");
vv   =   mynodes[0].innertext;
console.writeline(vv);
//修改
mynodes[0].innertext   =   "67890 ";
doc.save( "d:\\text.xml ");
console.readline();
}

}

}
发表于:2007-01-22 12:23:5712楼 得分:0
請看這里:
http://www.cnblogs.com/jinliangliu/archive/2007/01/08/614813.html
发表于:2007-01-22 12:43:3013楼 得分:0
可用xpath进行快速的查询
如:xmldoc.documentelement.selectnodes( "/customerorders/customers[customerid= 'alfki '] ");
建议看一下xpath的语法
发表于:2007-01-22 12:54:1114楼 得分:0
刚好昨天写了一个
给你看看吧

config.xml内容如下:

<?xml   version= "1.0 "   encoding= "gb2312 "?>
<myconfig>
    <username> xingxing </username>
    <password> 123456 </password>
</myconfig>

=================================================================
//xmlpath()为xml文件路径   config.xml
using   system;
using   system.text;
using   system.io;
using   system.xml;

                public   void   readxml()
                {
                        if   (!file.exists(xmlpath()))
                        {
                                xmltextwriter   xmlwriter   =   new   xmltextwriter(xmlpath(),   encoding.default);//创建一个xml文档
                                xmlwriter.formatting   =   formatting.indented;
                                xmlwriter.writestartdocument();
                                xmlwriter.writestartelement( "myconfig ");

                                xmlwriter.writestartelement( "username ");
                                xmlwriter.writestring( " ");
                                xmlwriter.writeendelement();

                                xmlwriter.writestartelement( "password ");
                                xmlwriter.writestring( " ");
                                xmlwriter.writeendelement();
                               
                                xmlwriter.writeendelement();

                                xmlwriter.close();
                        }
                        //避免出错
                        username   =   " ";   password   =   " ";
                        if   (file.exists(xmlpath()))
                        {
                                xmldocument   xmldoc   =   new   xmldocument();
                                xmldoc.load(xmlpath());
                                xmlelement   root   =   xmldoc.documentelement;
                                username   =   root.selectsinglenode( "username ").innertext;
                                password   =   root.selectsinglenode( "password ").innertext;
                        }
                }


                public   void   writexml()
                {
                        if   (file.exists(xmlpath()))
                        {
                                xmldocument   xmldoc   =   new   xmldocument();
                                xmldoc.load(xmlpath());
                                xmlelement   root   =   xmldoc.documentelement;
                                root.selectsinglenode( "username ").innertext   =   "xingxing ";
                                root.selectsinglenode( "password ").innertext   =   "123456 ";
                                xmldoc.save(xmlpath());
                        }
                }

希望对你能有帮助。
发表于:2007-01-22 13:04:4815楼 得分:0
上面写的不错,初学者用数据集来实现xml   比较方便,实用


快速检索

最新资讯
热门点击