asp.net read edit modify XML information

Source: Internet
Author: User
Tags foreach

ASP tutorial. NET read edit modify XML information

Reading images

Public list<string> loadimg ()
{
list<string> list = new list<string> ();
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;
}


Login
public bool IsLogin (user model)
{
list<string> list = new list<string> ();
XmlDocument xmldoc = new XmlDocument ();
Xmldoc.load (Xmlpath);

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

Verify that you are logged in through
if (model.username.tolower () = = Node.childnodes[0].innertext.tolower () && model.pwd.tolower () = = Node.childnodes[1].innertext.tolower ())
{
FT = true;
Break
}
}

return ft;
}


Write XML
public void InsertXML (user model)
{
XmlDocument xmldoc = new XmlDocument ();
Xmldoc.load (Xmlpath);

Get root node
XmlNode root = Xmldoc.selectsinglenode ("userinfo");
XmlElement xment = xmldoc.createelement ("user");

Creating nodes
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 version= "1.0" encoding= "Utf-8"?>
The XML file stores user registration information temporarily instead of the user table
<userinfo>
<user>

<name>admin</name>
<pwd>888888</pwd>
<age>22</age>
<sex> male </sex>
</user>


</userinfo>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.