当父节点有xmlns属性时,动态创建子节点,会默认增加一个 xmlns=“” 的节点属性值。

原有

doc.CreateElement("son-node");

改为

doc.CreateElement("son-node", doc.DocumentElement.NamespaceURI);

 

C# 添加xml节点多了xmlns属性问题

 

参考百度站点地图文件sitemap.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:mobile="http://www.baidu.com/schemas/sitemap-mobile/1/">
    <url>
    <loc>http://m.example.com/index.html</loc>
    <mobile:mobile type="mobile" />
    <lastmod>2009-12-14</lastmod>
    <changefreq>daily</changefreq>
    <priority>0.8</priority>
    </url>
    </urlset>

 

相关文章:

  • 2022-01-03
  • 2021-10-27
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-09-10
  • 2021-07-13
  • 2022-12-23
  • 2021-07-20
  • 2021-09-13
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案