先说下 要达到的目的是 创建如下格式文档<?xml version="1.0" encoding="gb2312"?>
<AutoUpdater description="" Version="1,0,0,1">
  <VerifySuggestions>
  </VerifySuggestions>
</AutoUpdater>
我创建的代码为什么老是<?xml version="1.0"?>
<AutoUpdater>
  <VerifySuggestions>
    <VerifySuggestion />  </VerifySuggestions>
</AutoUpdater>为什么不是双开关。代码如下                XmlDocument   xmlDoc = new XmlDocument();
                XmlNode Head = xmlDoc.CreateNode(XmlNodeType.XmlDeclaration,"测试","");
              
                xmlDoc.AppendChild(Head);                XmlElement root = xmlDoc.CreateElement("AutoUpdater");                XmlElement Fathernode = xmlDoc.CreateElement("VerifySuggestions");
              
                root.AppendChild(Fathernode);                xmlDoc.AppendChild(root);                xmlDoc.Save(xmlpath );

解决方案 »

  1.   

    你的代码产生的文件应该是:
    <?xml version="1.0"?>
    <AutoUpdater>
      <VerifySuggestions />
    </AutoUpdater>
      

  2.   

    值给设置为 "" 就可以了。例如如下节点 ABCXElement element = new XElement("group",
                    new XElement("item",new XAttribute("name","kingdom_0"),new XAttribute("value","")),
                    new XElement("item",new XAttribute("name","faya"),new XAttribute("value","123")),
                    new XElement("ABC","")
                    );
                
                Console.WriteLine(element);
      

  3.   

    这个可以满足你的要求。            XmlDocument xmlDoc = new XmlDocument();
                XmlNode Head = xmlDoc.CreateXmlDeclaration("1.0", "gb2312", null);            xmlDoc.AppendChild(Head);            XmlElement root = xmlDoc.CreateElement("AutoUpdater");
                root.SetAttribute("description", "");
                root.SetAttribute("Version", "1,0,0,1");            XmlElement Fathernode = xmlDoc.CreateElement("VerifySuggestions");
                Fathernode.IsEmpty = false;
                root.AppendChild(Fathernode);            xmlDoc.AppendChild(root);            xmlDoc.Save(AppDomain.CurrentDomain.BaseDirectory + "1.xml");
    另外学习2楼。
      

  4.   

    唉  我发现简单的方法就是 加上   Fathernode.InnerText = "";
    和上面的那个查不多。