sax方式,(推)
读xml
XmlTextReader xmlReader = new XmlTextReader(Server.MapPath(strXmlFileName));
while (xmlReader.Read())
{
//找到指定的结点(元素,文本等),
if (xmlReader.NodeType == XmlNodeType.Element)
{
//读取;
xmlReader.ReadString();
}
xmlReader.Close();//关闭
}
写xml
//xml配置
XmlWriterSettings setting = new XmlWriterSettings();
setting.Indent = true;
setting.NewLineOnAttributes = true;
strXmlFileName = txtFileName.Text.ToString();
//开始生成xml
XmlWriter writer = XmlWriter.Create("", setting);
writer.WriteStartDocument();
//开始结点
writer.WriteStartElement("config");
//写属性
writer.WriteAttributeString("", "");
//写内容
writer.WriteElementString("ztregion", this.txtZtregion.Text);
//结束结点
writer.WriteEndElement();
writer.Flush();
writer.Close();