XmlDocument doc = new XmlDocument();
 XmlElement root = doc.CreateElement("offers");
 doc.AppendChild(root);
 XmlAttribute xsi = doc.CreateAttribute("xmlns:xsi");
 xsi.Value = "http://www.w3.org/2001/XMLSchema-instance";
 XmlAttribute xsispace = doc.CreateAttribute("xsi:noNamespaceSchemaLocation");
 xsispace.Value = "feed.xsd";
 root.Attributes.Append(xsi);
 root.Attributes.Append(xsispace);
我这样写,生成出来的是这样的
<offers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" noNamespaceSchemaLocation="feed.xsd">但要求是这样的
<offers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="feed.xsd">
后面的那个xsi:不知道咋弄不出来

解决方案 »

  1.   

    XmlAttribute xsispace = doc.CreateAttribute("xsi:noNamespaceSchemaLocation");
    把这句话改成这个
    XmlAttribute xsispace = doc.CreateAttribute("noNamespaceSchemaLocation");
    不行吗。
      

  2.   

    XML头信息加上看看
    不行用记事本的形式,用StreamWriter往XML文件里写吧
      

  3.   

    http://www.cnblogs.com/kaifei/archive/2011/06/22/2087433.html
    看下这个里面的方法
      

  4.   

    XNamespace xsi = "http://www.w3.org/2001/XMLSchema-instance";
    XDocument Orders = new XDocument(new XDeclaration("1.0", "utf-8", "yes"), new XElement("Orders", new XAttribute(XNamespace.Xmlns + "xsi", xsi), new XAttribute(xsi + "noNamespaceSchemaLocation", "feed.xsd")));
    Orders.Save("E:\\1.xml"); 
      

  5.   

    改改就行了:                XmlDocument doc = new XmlDocument();
                    XmlElement root = doc.CreateElement("offers");
                    doc.AppendChild(root);
                    XmlAttribute xsi = doc.CreateAttribute("xmlns:xsi");
                    xsi.Value = "http://www.w3.org/2001/XMLSchema-instance";
                    XmlAttribute xsispace = doc.CreateAttribute("xsi", "noNamespaceSchemaLocation", "http://www.w3.org/2001/XMLSchema-instance");
                    xsispace.Value = "feed.xsd";
                    root.Attributes.Append(xsi);
                    root.Attributes.Append(xsispace);
      

  6.   

    http://download.csdn.net/detail/pirates_fish/3531583
      

  7.   

     xmlElement.SetAttribute("noNamespaceSchemaLocation","http://www.w3.org/2001/XMLSchema-instance","feed.xsd");