XML this time to write the project every time to use XML to save some configuration, and each operation of XML is very cumbersome, no database so smooth. It was later discovered that using a dataset to manipulate XML was convenient and flexible, so it wrote a class that manipulated XML to deal with general XML operations (source download attachments).
1 Basic Ideas
In fact, using dataset to manipulate XML, in the final analysis, is to manipulate the tables, rows, columns, and so on in the dataset, and then write the contents of the dataset back into XML to achieve the purpose of editing XML. It works better if you cooperate with the. xsd file.
2 Detailed procedures
(1) XML file content
The XML of this class operation is the same as the generated XML format, as follows (click to view Code 1 attachment): (if there is garbled in Chinese, please choose "Simplified Chinese" in the code of the browser view option)
Then click "Data" in the lower-right corner of the XML file to see the familiar table Form, right-click anywhere in the table and select "Create Schema", and an. xsd file is generated that defines the types of XML columns. Its contents are as follows (click to view Code 2 attachment):
Note: If you imagine a database with an automatically growing ID field, you can do this:
First you add an element to the XML so that when you generate. xsd, there will be an ID segment, in the. xsd, select the column of ID, and in the right property, set "AutoIncrementSeed" and "AutoIncrementStep" to 1, respectively. This will automatically increase the ID starting at 1 with a step size of 1.
The above code does not matter if it is not understood, because we can generate the contents of this format through a dataset. The next step is to begin manipulating the XML.
(2) Processing XML file paths
This mainly deals with the incoming XML path and, if the relative path is passed in, returns the full path and returns without processing if the full path is passed in. The method is as follows:
#region Getxmlfullpath
<summary>
Return full path
</summary>
<param name= "strpath" >xml path </param>
<returns></returns>
public static string Getxmlfullpath (String strpath)
{
If the path contains: symbol, then the full path is assumed to be passed in
if (Strpath.indexof (":") > 0)
{
return strpath;
}
Else
{
Return full path
Return System.Web.HttpContext.Current.Server.MapPath (strpath);
}
}
#endregion