System.IO.FileStream xmlFileStream = new System.IO.FileStream(mXmlFileName, System.IO.FileMode.Create);
////创建Writer文本流
System.Xml.XmlTextWriter xmlWriter = new System.Xml.XmlTextWriter(xmlFileStream, System.Text.Encoding.Default);
//////写出xml标题头 xmlWriter.WriteStartDocument(true);
xmlWriter.WriteStartAttribute("xmlns", null, "http://www.w3.org/2000/10/XMLSchema");
xmlWriter.WriteEndAttribute();
xmlWriter.WriteAttributeString("xmlns", "po", null, "http://contoso.com/po");
xmlWriter.WriteEndAttribute();
xmlWriter.WriteStartElement("DataSetProjects", "11", "http://passport.kubao.com");
MessageBox.Show("ok");
string fileName=mXmlFileName;
看看是哪错了?老出错报错为:处于状态 Prolog 的标记 StartAttribute 将导致无效的 XML 文档。
解决方案 »
- PrintPreviewDialog 打印预览后能不能加个按钮保存为图像
- mschart画图
- 悬赏100分 Tab符转换成空格符问题,求解决。
- 怎么在datagridview 中实现,点击一个checkbox所在的单元格时,使checkbox处于选中状态
- c#连接数据库问题
- ★★★★★datagrid中放置的textbox读取数据有误
- struct中成员是struct对象的问题
- 正则表达式问题,不包含指定的串
- 为什么在for循环里重复定义变量不会报错?
- 菜单的起始位置
- ImageList空间如何动态设置其大小
- 在datagridView中加入一个combox列,怎么能允许用户输入?(winform)
System.Xml.XmlDocument xmldoc;
System.Xml.XmlNode nRoot, nNode;
xmldoc = new XmlDocument();
//xml头
xmldoc.AppendChild(xmldoc.CreateXmlDeclaration("1.0", "utf-8", ""));
//Root根节点
nRoot = xmldoc.CreateNode(XmlNodeType.Element, "Records", "");
// .........往nRoot中加入其它子节点
xmldoc.AppendChild(nRoot);
XmlDocument doc = new XmlDocument();
............
doc.Save("data.xml");2、XmlWriter:
XmlWriter writer = XmlWriter.Create("output.xml");
writer.WriteStartElement("book");
writer.WriteElementString("price", "19.95");
writer.WriteEndElement();
writer.Flush();
xmlWriter.WriteStartAttribute("xmlns", null, "http://www.w3.org/2000/10/XMLSchema");
xmlWriter.WriteEndAttribute();
xmlWriter.WriteAttributeString("xmlns", "po", null, "http://contoso.com/po");
xmlWriter.WriteEndAttribute();
xmlWriter.WriteStartElement("DataSetProjects", "11", "http://passport.kubao.com");
开始不能是属性