一个比较有用的XML文件操作类 C#代码 可以继续扩展


     CXml
</span>
{
</span>
strXmlFile;
</span>
XmlDocument();
</span>
xmlFile)
</span>
{
</span>

</span></span>
try
</span></span>
{
</span>
objXmlDoc.Load(xmlFile);
</span>
}
</span>
catch
</span></span>
{
</span>
}
</span>
strXmlFile = xmlFile;
</span>
}
</span>
xmlPathNode)
</span>
{
</span>
DataView
</span></span>
DataSet();
</span>
StringReader(objXmlDoc.SelectSingleNode(xmlPathNode).OuterXml);
</span>
ds.ReadXml(read);
</span>
ds.Tables[0].DefaultView;
</span>
}
</span>
content)
</span>
{
</span>

</span></span>
objXmlDoc.SelectSingleNode(xmlPathNode).InnerText = content;
</span>
}
</span>
node)
</span>
{
</span>

</span></span>
mainNode = node.Substring(0,node.LastIndexOf("/"));
</span>
objXmlDoc.SelectSingleNode(mainNode).RemoveChild(objXmlDoc.SelectSingleNode(node));
</span>
}
</span>
content)
</span>
{
</span>

</span></span>
XmlNode objRootNode = objXmlDoc.SelectSingleNode(mainNode);
</span>
XmlElement objChildNode = objXmlDoc.CreateElement(childNode);
</span>
objRootNode.AppendChild(objChildNode);
</span>
XmlElement objElement = objXmlDoc.CreateElement(element);
</span>
objElement.InnerText = content;
</span>
objChildNode.AppendChild(objElement);
</span>
}
</span>
content)
</span>
{
</span>

</span></span>
XmlNode objNode = objXmlDoc.SelectSingleNode(mainNode);
</span>
XmlElement objElement = objXmlDoc.CreateElement(element);
</span>
objElement.SetAttribute(attrib,attribContent);
</span>
objElement.InnerText = content;
</span>
objNode.AppendChild(objElement);
</span>
}
</span>
content)
</span>
{
</span>

</span></span>
XmlNode objNode = objXmlDoc.SelectSingleNode(mainNode);
</span>
XmlElement objElement = objXmlDoc.CreateElement(element);
</span>
objElement.InnerText = content;
</span>
objNode.AppendChild(objElement);
</span>
}
</span>
Save()
</span>
{
</span>

</span></span>
try
</span></span>
{
</span>
objXmlDoc.Save(strXmlFile);
</span>
}
</span>
catch
</span></span>
{
</span>
}
</span>
;
</span>
}
</span>
}
</span>
 

你可能感兴趣的:(java,工作)