A class that operates XML through a dataset (original)

Source: Internet
Author: User
Tags format return string
xml| Original

This time the project writes each time to use the XML to save some configuration, but each operation XML is very troublesome, does not have the database so conveniently. 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

See details:
Http://www.pconline.com.cn/pcedu/empolder/wz/xml/0509/695205.html



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.