一聚教程网:一个值得你收藏的教程网站

热门教程

asp.net 读取编辑修改 xml 信息

时间:2022-06-25 06:36:14 编辑:袖梨 来源:一聚教程网

asp教程.net 读取编辑修改 xml 信息

       //读取图像

     

  public list loadimg()
       {
           list list = new list();
           xmldocument xmldoc = new xmldocument();
           xmldoc.load(xmlimgpath);
           xmlelement xmlele = xmldoc.documentelement;
         

           xmlnodelist xmllist = xmlele.selectnodes("image/items/item");
           foreach (xmlnode node in xmllist)
           {
               list.add(node.attributes["src"].innerxml.tostring());
           }
           return list;
       }

 

 

 
       //登录
       public bool islogin(user model)
       {
           list list  = new list();
           xmldocument xmldoc = new xmldocument();
           xmldoc.load(xmlpath);

           xmlnode xmlnode = xmldoc.selectsinglenode("userinfo");
           bool ft = false;
           foreach (xmlnode node in xmlnode)
           {

      //验证是否登录通过
               if (model.username.tolower() == node.childnodes[0].innertext.tolower() && model.pwd.tolower()==node.childnodes[1].innertext.tolower())
               {
                   ft = true;
                   break;
               }
           }

           return ft;
       }


  //写入xml
       public void insertxml(user model)
       {
           xmldocument xmldoc = new xmldocument();
           xmldoc.load(xmlpath);

       //获取根节点
           xmlnode root = xmldoc.selectsinglenode("userinfo");
           xmlelement xment = xmldoc.createelement("user");

    //创建节点
           xmlelement xmlname = xmldoc.createelement("name");
           xmlname.innertext = model.username;
           xment.appendchild(xmlname);


           xmlelement xmlpwd = xmldoc.createelement("pwd");
           xmlpwd.innertext = model.pwd;
           xment.appendchild(xmlpwd);

           xmlelement xmlage = xmldoc.createelement("age");
           xmlage.innertext = model.age;
           xment.appendchild(xmlage);

           xmlelement xmlsex = xmldoc.createelement("sex");
           xmlsex.innertext = model.sex;
           xment.appendchild(xmlsex);

           root.appendchild(xment);
           string strex = xmlpath.substring(6,xmlpath.length-6);
           xmldoc.save(strex);
          
       }


// xml 文件  存储用户注册信息  暂时代替用户表

   

        admin
        888888
        22
       
   


热门栏目