#region Public Property
<summary>
Content in XML format
</summary>
public string Filecontent
{
get {return _filecontent;}
set {_filecontent = value;}
}
<summary>
Absolute path to XML file
</summary>
public string FilePath
{
get {return _filepath;}
set {_filepath = value;}
}
<summary>
An XPath expression
</summary>
public string XPath
{
get {return _xpath;}
set {_xpath = value;}
}
<summary>
Mode of operation
</summary>
Public Operatexmlmethod method
{
get {return _method;}
set {_method = value;}
}
#endregion
# region "XML file Operations"
#region "New"
<summary>
Creates a new, blank, XML-formatted file (no root node)
</summary>
public void Createxml ()
{
Create a temporary file with the same name to ensure that the folder exists
Fobject.create (this. FilePath, fsomethod.file);
Releasing resources
Writer. Flush ();
Writer. Close ();
}
<summary>
Creates a new XML-formatted file (with the root node)
</summary>
<param name= "Rootnodename" > Root node name </param>
public void Createxml (string rootnodename)
{
Create a temporary file with the same name to ensure that the folder exists
Fobject.create (this. FilePath, fsomethod.file);
<summary>
Creates a child node under the specified node and assigns a property or child node to the child node
</summary>
<param name= "NodeName" > Name of the child node to be created </param>
<param name= "DT" >
Storing assignment information for child nodes (a DataTable)
Row 1 (name, before the name contains the @ character, then the property)
Line 2 (value) </param>
public void CreateNode (string nodename, DataTable DT)
{
XmlDocument doc = new XmlDocument ();
Doc. Load (this. filePath);
XmlNode root = Doc. selectSingleNode (this. xPath);
Creating child nodes
XmlElement XE = Doc. CreateElement (nodename);
XmlElement xechild = null;
if (! Object.Equals (DT, NULL))
{
for (int i = 0; i < dt. Columns.count; i + +)
{
if (dt. Columns[i]. Columnname.startswith ("@"))
{
String attributename = dt. Columns[i]. Columnname.replace ("@", "");
Set properties for this child node
Xe. SetAttribute (attributename, dt. rows[0][i]. ToString ());
}
Else
{
Xechild = doc. createelement (dt. Columns[i]. ColumnName);
Try
{
Xechild.innerxml = dt. rows[0</
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.