xml| comparison
public class CXml
{
private string Strxmlfile;
Private XmlDocument objxmldoc = new XmlDocument ();
Public CXml (String xmlFile)
{
Constructors
Try
{
Objxmldoc.load (XmlFile);
}
Catch
{
}
Strxmlfile = XmlFile;
}
Public DataView GetData (string xmlpathnode)
{
Find Data returns a DataView
DataSet ds = new DataSet ();
StringReader read = new StringReader (Objxmldoc.selectsinglenode (Xmlpathnode). OuterXml);
Ds. READXML (read);
Return DS. Tables[0]. DefaultView;
}
public void Replace (string xmlpathnode,string content)
{
Update node content
Objxmldoc.selectsinglenode (Xmlpathnode). innertext = content;
}
public void Delete (String node)
{
Delete a node
String mainnode = node. Substring (0,node. LastIndexOf ("/"));
Objxmldoc.selectsinglenode (Mainnode). RemoveChild (Objxmldoc.selectsinglenode (node));
}
public void Insertnode (string mainnode,string childnode,string element,string content)
{
Inserts a node and a child node of this node
XmlNode Objrootnode = Objxmldoc.selectsinglenode (Mainnode);
XmlElement objchildnode = objxmldoc.createelement (Childnode);
Objrootnode.appendchild (Objchildnode);
XmlElement objelement = objxmldoc.createelement (Element);
Objelement.innertext = content;
Objchildnode.appendchild (objelement);
}
public void Insertelement (string mainnode,string element,string attrib,string attribcontent,string content)
{
Insert a node with one attribute
XmlNode objnode = Objxmldoc.selectsinglenode (Mainnode);
XmlElement objelement = objxmldoc.createelement (Element);
Objelement.setattribute (attrib,attribcontent);
Objelement.innertext = content;
Objnode.appendchild (objelement);
}
public void Insertelement (string mainnode,string element,string content)
{
Insert a node with no attributes
XmlNode objnode = Objxmldoc.selectsinglenode (Mainnode);
XmlElement objelement = objxmldoc.createelement (Element);
Objelement.innertext = content;
Objnode.appendchild (objelement);
}
public void Save ()
{
Save XML file
Try
{
Objxmldoc.save (Strxmlfile);
}
Catch
{
}
objXMLDoc = null;
}
}