Once I saw a gay website back-end, and the method for operating XML files was stiff, I wrote a simple XML class.
If you are interested, you can download it and check it out. It would be a great honor for me to help you.
Http://files.cnblogs.com/zhhh/zhh.Xml.rar
This is the source code. The class library generated in the bin directory is A. net2.0 project.
If you are interested, give me some advice. Thank you.
-----------------------
The following is a description of this class, which is very simple in general:
========================================================== ====================
The main function of the xmlreader class is to read or set an attribute or text of a subnode from a node of an XML file, or an object (the object property corresponds to a subnode of the same name as the node)
The xmlreader class contains the following functions (methods ):
1. Get the value of an attribute based on a property name
2. Obtain the text of a node based on the node name.
3. Get an object of the specified type
4. Set an attribute value based on the attribute name and attribute value.
5. Set the text of a node based on the node name and node value.
6. Set an object
For example, if an XML file is stored in D: \ JJ. XML, the file content is as follows:
<? XML version = "1.0" ?>
< Root >
< Man >
< Name > XiaoBei </ Name >
< Age > 25 </ Age >
< Ismale > False </ Ismale >
</ Man >
</ Root >
You can first introduce the namespaceZhh. xml
Then createXmlreaderObject
Xmlreader XR = New Xmlreader ( " D: \ JJ. xml " , " Root/man " );
This statement is used to locate the xmlreader object to the man node under the root node under the D: \ JJ. xml file. All subsequent operations will be performed on this node.
After the preceding object declaration statement is executed, you can use it directly.
For example, this statement can add an XML node attribute named name for the current node with the value "OK.
XR. setattribute ( " Name " , " OK " );
After the execution, the XML file will look like this:
<? XML version = "1.0" ?>
< Root >
< Man Name = "OK" >
< Name > XiaoBei </ Name >
< Age > 25 </ Age >
< Ismale > False </ Ismale >
</ Man >
</ Root >
Of course, you can use the following statement to writeXMLFileOKRead
String V = XR. getattribute ( " Name " );
To change the value of the name subnode under the current node, you can use the following statement:
XR. setchildnodetext ( " Name " , " XiaoBei " );
Similarly, you can use this statement to obtain the saved value.
String V = XR. getchildnodetext ( " Name " );
The two basic functions are complete. The following describes a slightly more complex function:
For example, the following entity classes are available:
Public Class Man
{
Public String Name { Get ; Set ;}
Public Int Age { Get ; Set ;}
Public Bool Ismale { Get ; Set ;}
}
Using this statement, we can directly read the content in the XML file (encapsulate the content in the subnode directly into the corresponding attributes of the object ):
Man m = XR. getobjectbyclasspath ( New MAN (). GetType (). tostring ()) As Man;
Similarly, you can directly Save the following object to the current node:
Man m = New MAN () {age = 25 , Ismale = False , Name = " XiaoBei " };
XR. setobject (m );
However, only basic data operations are supported during object reflection.