你的语句是正确的,encoding是指你的UNCODE编码这是正常的啊

解决方案 »

  1.   

    xml文檔沒有<?xml version="1.0" encoding="utf-16"?>也可以用呀,我一般用XMl文檔來保存一些配置信息和GUI控件的Text,例如:菜單
      

  2.   

    XmlTextWriter xwriter = new XmlTextWriter(m_filename,System.Text.Encoding.UTF8);
    xwriter.WriteStartDocument(true);
    xwriter.WriteEndDocument();
    xwriter.Close();
      

  3.   

    StringBuilder sb = new StringBuilder("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
    System.Xml.XmlTextWriter tw = new System.Xml.XmlTextWriter(new System.IO.StringWriter(sb));// tw.WriteStartDocument();
      

  4.   

    XmlTextWriter xwriter = new XmlTextWriter(m_filename,System.Text.Encoding.UTF8);
    xwriter.WriteStartDocument(true);
    xwriter.WriteEndDocument();
    xwriter.Close();
      

  5.   


    System.IO.FileStream myFileStream = new System.IO.FileStream(file, System.IO.FileMode.Create);
    // Create an XmlTextWriter with the fileStream.
    System.Xml.XmlTextWriter myXmlWriter =new System.Xml.XmlTextWriter(myFileStream, System.Text.Encoding.UTF8);
    ds.WriteXml(myXmlWriter);   // Write to the file with the WriteXml method.
    myXmlWriter.Close();
      

  6.   

    public static void test()
    {
    XmlTextWriter xmlWriter = new XmlTextWriter(("C:\\1.xml"), null);// Format automatically
    xmlWriter.Formatting = Formatting.None;xmlWriter.WriteStartDocument();// Write root element
    xmlWriter.WriteStartElement("FriendsList");
    // Write first sub element of root element
    xmlWriter.WriteStartElement("Friend");
    // now start adding names 1.name
    xmlWriter.WriteElementString("Name","Michael");
    // 2.name
    xmlWriter.WriteElementString("Age","39");// write end elements
    xmlWriter.WriteEndElement();xmlWriter.WriteEndDocument();
    // close writer
    xmlWriter.Close();
    }这样生成的XML文档只有<?xml version="1.0" ?> ,没有encoding!