On XML usage in C #

Source: Internet
Author: User
Tags cdata
XML I am also just getting started XML, but I also want to learn what I have to share one of the university, please support a lot of it
This is a 001.xml file.
<?xml version= "1.0" encoding= "Utf-8"?>
<! DOCTYPE contents SYSTEM "001.dtd" >
<contents>
<person name= "Guo Yonghao" num= "61102332" email= "gyh2008320@163.com" >i Love you</person>
<person name= "Han" num= "61102333" email= "han@163.com" > You love me</person> </contents>
Here are the contents of the 001.dtd file
<! ELEMENT contents (person) >
<! ELEMENT person (#PCDATA) >
<! ATTLIST person name CDATA #REQUIRED Num CDATA #REQUIRED email CDATA #REQUIRED >
Add a text box to the item, add a button, and then add the following code to the button's Click event to find out if there is one.
But before you do, you have to refer to a using System.Xml and then add the code.
String strfilpath= "D:\001.xml";
int flag=0;
XmlTextReader objtxtrd=new XmlTextReader (strFilePath);
while (Objtxtrd.read ())
{
if (objtxtrd.nodetype=xmlnodetype.element)
{
if (objtxtrd.hasattributes)
{
Objtxtrd.movetoattribute ("num");
if (Objtxtrd.value==textbox1.text)
{flag=1; MessageBox.Show ("Find success");
}
}
}
if (flag==0) {MessageBox.Show ("No this person, please make sure the input.");}
If there is a Chinese character in your document, please remember to keep it in the form of UTF-8, otherwise the wrong words can not wish me ah



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.