XML format
<? XML version = "1.0" encoding = "UTF-8"?>
<Projects id = "">
<Projectgroup>
<Projectitem id = "">
<Infolist>
<Infoitem code = "gcxx" name = "project information" remark = "" value = "">
<Infoitem code = "ysbh" name = "Project No. (required)" remark = "" value = "20120330001"/>
<Infoitem code = "ysmc" name = "project name (required)" remark = "" value = "project 0059"/>
<Infoitem code = "buildunit" name = "(owner) (required)" remark = "" value = ""/>
<Infoitem code = "jsdwfdr" name = "" remark = "" value = ""/>
<Infoitem code = "gclx" name = "project type (required)" remark = "" value = ""/>
<Infoitem code = "bagcdq" name = "project region" remark = "" value = ""/>
<Infoitem code = "gcdd" name = "Project location" remark = "" value = ""/>
<Infoitem code = "zjly" name = "funding source" remark = "" value = ""/>
<Infoitem code = "constructversion" name = "version (required)" remark = "" value = "Guangdong Construction Project Cost document data exchange standardization provision 2.0"/>
<Infoitem code = "wjcjsj" name = "File Creation Time" remark = "" value = ""/>
<Infoitem code = "wjxgsj" name = "file modification time" remark = "" value = ""/>
<Infoitem code = "yslb" name = "file type" remark = "" value = "Settlement"/>
</Infoitem> </infolist>
</Projectitem>
</Projectgroup>
</Projects>
Add reference
Using system. xml. LINQ;
Using system. xml. XPath;
JoinCode:
String xml_path = server. mappath ("~ /XML/baseinfo. xml "); xdocument loaded = xdocument. Load (xml_path); // LINQ
Ienumerable <xelement> list_gcxx = loaded. xpathselectelements ("// projectgroup/projectitem/infolist/infoitem [@ code = 'gcxx']"); // project information
Foreach (xelement item in list_gcxx.elements ())
{
Label1.text + = "code =" + item. Attribute ("Code"). value. tostring () + "";
Label1.text + = "name =" + item. Attribute ("name"). value. tostring () + "";
Label1.text + = "value =" + item. Attribute ("value"). value. tostring () + "<br> ";
// Response. Write (item. Value + "<br> ");
}
Ienumerable <xelement> list_cgwjpz = loaded. xpathselectelements ("// projectgroup/projectitem/infolist/infoitem [@ code = 'cgwjpz']"); // result file configuration
Foreach (xelement item in list_cgwjpz.elements ())
{
Label1.text + = "code =" + item. Attribute ("Code"). value. tostring () + "";
Label1.text + = "name =" + item. Attribute ("name"). value. tostring () + "";
Label1.text + = "value =" + item. Attribute ("value"). value. tostring () + "<br> ";
// Response. Write (item. Value + "<br> ");
}