Get XML configuration Data

Source: Internet
Author: User

XML Structure:

<Setting>
<BIG>
<tdHead>
&LT;TD tdname= "serial number" tdwidth= "50px" tdheight= "" tdtitle= "" tdrowspan= "" tdcolspan= "" ></td>
&LT;TD tdname= "Company" tdwidth= "60px" tdheight= "tdtitle=" "tdrowspan=" "tdcolspan=" "></td>
&LT;TD tdname= "line" tdwidth= "90px" tdheight= "tdtitle=" "tdrowspan=" "tdcolspan=" "></td>
&LT;TD tdname= "license Number" tdwidth= "tdheight=" "tdtitle=" "tdrowspan=" "tdcolspan=" "></td>
&LT;TD tdname= "self-numbering" tdwidth= "tdheight=" "tdtitle=" "tdrowspan=" "tdcolspan=" "></td>
&LT;TD tdname= "Start Time" tdwidth= "120px" tdheight= "" tdtitle= "" tdrowspan= "" tdcolspan= "" ></td>
&LT;TD tdname= "End Time" tdwidth= "120px" tdheight= "" tdtitle= "" tdrowspan= "" tdcolspan= "" ></td>
&LT;TD tdname= "overspeed duration (seconds)" tdwidth= "80px" tdheight= "tdtitle=" "tdrowspan=" "tdcolspan=" "></td>
&LT;TD tdname= "overspeed mileage (km)" tdwidth= "80px" tdheight= "tdtitle=" "tdrowspan=" "tdcolspan=" "></td>
&LT;TD tdname= "Maximum speed (km/h)" tdwidth= "90px" tdheight= "tdtitle=" "tdrowspan=" "tdcolspan=" "></td>
&LT;TD tdname= "Average speed (km/h)" tdwidth= "90px" tdheight= "tdtitle=" "tdrowspan=" "tdcolspan=" "></td>
&LT;TD tdname= "Overspeed standard (km/h)" tdwidth= "70px" tdheight= "" tdtitle= "" tdrowspan= "" tdcolspan= "" ></td>
&LT;TD tdname= "overspeed position" tdwidth= "tdheight=" "tdtitle=" "tdrowspan=" "tdcolspan=" "></td>
</tdHead>
</BIG>

</Setting>

<summary>
Get the required node data into the XML dataset
</summary>
<param name= "Path" ></param>
<param name= "NodeName" ></param>
<returns></returns>
Public list<list<monitortablehead>> getxmldata (string path,string NodeName)
{
list<list<monitortablehead>> Listlmont = new list<list<monitortablehead>> ();
Try
{
String str1 =process.getcurrentprocess (). mainmodule.filename;//gets the file name of the EXE that is currently executing.
String str2=environment.currentdirectory;//gets and sets the current directory (that is, the project from which the process starts
The fully qualified path of the record).
Note by definition, if the process is started in the root directory of a local or network drive, the value of this property is drive
A trailing backslash (such as "C: \") followed by the actuator name. If the process is started in a subdirectory, the value of this property is not
Drive and subdirectory paths with trailing backslashes (such as "C:\mySubDirectory").
String Str3=directory.getcurrentdirectory ();//Gets the current working directory of the application.
String str4=appdomain.currentdomain.basedirectory;//gets the base directory, which is resolved by Assembly conflict
The program is used to probe the assembly.
String str5=system.net.mime.mediatypenames.application.startuppath;//gets the path to the executable file that launched the application, not including the
The name of the execution file.
String str6=system.net.mime.mediatypenames.application.executablepath;//gets the path to the executable file that launched the application, including the
The name of the execution file.
String str7=appdomain.currentdomain.setupinformation.applicationbase;//Gets or sets the containing
The name of the directory for the application.
XmlDocument doc = new XmlDocument ();
Doc. Load (AppDomain.CurrentDomain.BaseDirectory + Path);
XmlNodeList NodeList = ((XmlElement) doc. selectSingleNode ("Setting")). selectSingleNode (NodeName). ChildNodes;
Traverse all child nodes
foreach (XmlNode xn in nodeList)
{
list<monitortablehead> Listmon = new list<monitortablehead> ();
XmlElement XE = (XmlElement) xn; To convert a child node type to a XmlElement type
if (XE. Name = = "Tdhead")
{

Xe. attributes["id"]. Value = "SSSS";//Modify the values of the node properties.
Xe. SetAttribute ("Genre", "Update Sky_kwolf"); Then modify the property to "Update Sky_kwolf"
XmlNodeList NLS = Xe. childnodes;//continue to acquire all child nodes of the XE child node
foreach (XmlNode xn1 in NLS)//traversal
{
Monitortablehead mont = new Monitortablehead ();
XmlElement Xe2 = (XmlElement) xn1; Conversion type
Mont. Tdname = Xe2. attributes["Tdname"]. Value;
Mont. Tdwidth = Xe2. attributes["Tdwidth"]. Value;
Mont. Tdheight = Xe2. attributes["Tdheight"]. Value;
Mont. Tdtitle = Xe2. attributes["Tdtitle"]. Value;
Mont. Tdrowspan = Xe2. attributes["Tdrowspan"]. Value;
Mont. Tdcolspan = Xe2. attributes["Tdcolspan"]. Value;
Listmon.add (Mont);
}
}
Listlmont.add (Listmon);
}
}
catch (Exception)
{
return null;
Throw
}
return listlmont;
}

Get XML configuration Data

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.