using System.Xml;
private void GetMsrStep()
{
if (File.Exists(strStepPath))
{
//读取
lstcStrStep.Clear();
XmlReader cXmlReader = XmlReader.Create(strStepPath);
cXmlReader.ReadStartElement("Operation-Steps");
while (XmlNodeType.EndElement != cXmlReader.MoveToContent())
{
XmlNodeType cXNT = cXmlReader.MoveToContent();
List<string> lstTemp = new List<string>(2);
lstTemp.Add(cXmlReader.LocalName);
lstTemp.Add(cXmlReader.ReadElementString());
lstcStrStep.Add(lstTemp);
}
cXmlReader.ReadEndElement();
cXmlReader.Close();
}
else
{
//保存
XmlWriterSettings cXmlWriterSetting = new XmlWriterSettings();
cXmlWriterSetting.ConformanceLevel = ConformanceLevel.Auto;
XmlWriter cXmlWriter = XmlWriter.Create(strStepPath,cXmlWriterSetting);
cXmlWriter.WriteStartDocument();
cXmlWriter.WriteWhitespace("\n");
cXmlWriter.WriteStartElement("Operation-Steps");
cXmlWriter.WriteWhitespace("\n");
foreach (List<string> lstData in lstcStrStep)
{
cXmlWriter.WriteWhitespace(" ");
cXmlWriter.WriteElementString(lstData[0],lstData[1]);
cXmlWriter.WriteWhitespace("\n");
}
cXmlWriter.WriteEndElement();
cXmlWriter.WriteEndDocument();
cXmlWriter.Close();
}
catch
{
}
}
原文链接:https://www.f2er.com/xml/298814.html