问题如下:
【1】我用以下代码
XmlDoc = new XmlDocument();
XmlNode = XmlDoc.CreateNode(XmlNodeType.XmlDeclaration, "", "");
XmlDoc.AppendChild(XmlNode);只能在xml中增加<?xml version="1.0"?> ,那么“encoding="UTF-8"”为何没有?【2】在xml格式中可否有如下格式的xml<?xml version="1.0" encoding="UTF-8"?>
<a>
<b>xxx</b>
<c>xxx</c>
</a>
<d>
<e Key=”信息编号”>
<f>xxx</f>
</e>
</d>a节点我已经写好,但是如何写d节点。而且在d节点中的e节点以及其中信息都是需要循环写入的,不知可否实现?谢谢,盼复
【1】我用以下代码
XmlDoc = new XmlDocument();
XmlNode = XmlDoc.CreateNode(XmlNodeType.XmlDeclaration, "", "");
XmlDoc.AppendChild(XmlNode);只能在xml中增加<?xml version="1.0"?> ,那么“encoding="UTF-8"”为何没有?【2】在xml格式中可否有如下格式的xml<?xml version="1.0" encoding="UTF-8"?>
<a>
<b>xxx</b>
<c>xxx</c>
</a>
<d>
<e Key=”信息编号”>
<f>xxx</f>
</e>
</d>a节点我已经写好,但是如何写d节点。而且在d节点中的e节点以及其中信息都是需要循环写入的,不知可否实现?谢谢,盼复
{
public static void Main()
{
XmlDocument doc = new XmlDocument();
doc.LoadXml("<book genre='novel' ISBN='1-861001-57-5'>" +
"<title>Pride And Prejudice</title>" +
"</book>"); //Create an XML declaration.
XmlDeclaration xmldecl;
xmldecl = doc.CreateXmlDeclaration("1.0",null,null); //Add the new node to the document.
XmlElement root = doc.DocumentElement;
doc.InsertBefore(xmldecl, root);
Console.WriteLine("Display the modified XML...");
doc.Save(Console.Out);
}
}
http://blog.csdn.net/yumanqing/archive/2007/03/20/1534744.aspx
<a>
<d>
<b>xxx</b>
<c>xxx</c>
</d>
<e>
<f Key=”信息编号”>
<g>xxx</g>
</f>
</e>
</a>f节点和节点中的内容用循环实现
XmlDoc = new XmlDocument();
XmlNode = XmlDoc.CreateNode(XmlNodeType.XmlDeclaration, "", "");
XmlNode.InnerText += " encoding=\"UTF-8\"";
XmlDoc.AppendChild(XmlNode);
{
try{
XmlDoc = new XmlDocument();
XmlDoc.Create(name,Encoding.UTF-8);
XmlDoc.close();
return true;
}
catch(Exception ex)
{MessageBox.Show(ex.toString());return false;}
}