更改xmlnamespace的顺序

时间:2014-07-22 13:34:37

标签: c# xml-serialization linq-to-xml

我正在研究Xml序列化。我的班级是

[XmlRoot("urlset", Namespace = "http://www.sitemaps.org/schemas/sitemap/0.9")]
[XmlInclude(typeof(Url))] 
public class UrlSet
{


   [XmlAttribute("schemaLocation", Namespace = XmlSchema.InstanceNamespace)]
    public string xsiSchemaLocation = "http://www.sitemaps.org/schemas/sitemap/0.9" +
                                      "http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd";
}

尝试添加

XmlSerializerNamespaces xmlNameSpace = new XmlSerializerNamespaces();
            xmlNameSpace.Add("xsi", "http://www.w3.org/2001/XMLSchema-instance");

输出给我的是

<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">

我需要

<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">

我也尝试添加空命名空间,但是为xml中的每个元素添加了前缀q。我还想知道这个订单是否真的重要,因为我要将生成的站点地图提交给谷歌

任何解决方案?

0 个答案:

没有答案