Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 关于在.Net中编写XML文件的问题?_C#_Xml_.net 3.5 - Fatal编程技术网

C# 关于在.Net中编写XML文件的问题?

C# 关于在.Net中编写XML文件的问题?,c#,xml,.net-3.5,C#,Xml,.net 3.5,下面是我尝试遵循的XML模式: <?xml version="1.0" encoding="UTF-8"?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> <url> <loc>http://www.example.com/</loc> <lastmod>2005-01-01</lastmod>

下面是我尝试遵循的XML模式:

<?xml version="1.0" encoding="UTF-8"?>

<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">

   <url>

      <loc>http://www.example.com/</loc>

      <lastmod>2005-01-01</lastmod>

      <changefreq>monthly</changefreq>

      <priority>0.8</priority>

   </url>

</urlset>
我的代码非常简单,但它仍然与我要遵循的示例xml不匹配。你们能帮助确保两组xml相互匹配吗?

你们非常接近:


但是,您可能会发现使用序列化或LINQ to XML要容易得多。

该死。。。。这就是我离得有多近。谢谢你,伙计。谢谢你,伙计,但是我被这一次的主要项目拖走了,所以我不想太过分。谢谢你。
<?xml version="1.0" encoding="utf-8"?>
<urlset>
  <url>
    <loc>http://www.ign.com</loc>
    <lastmod>2005-01-01</lastmod>
    <changefreq>monthly</changefreq>
    <priority>0.8</priority>
  </url>
</urlset>
            // Create the settings object that will define the settings that our writer will use.
        XmlWriterSettings settings = new XmlWriterSettings();
        settings.Encoding = Encoding.UTF8;
        settings.Indent = true;
        settings.OmitXmlDeclaration = false;

        // create the XML writer object.
        XmlWriter xmlW = XmlWriter.Create("SiteMap.xml", settings);

        // write the start header for the XML document.
        xmlW.WriteStartDocument();

        xmlW.WriteStartElement("urlset");

        xmlW.WriteStartElement("url");

        xmlW.WriteElementString("loc", "http://www.ign.com");
        xmlW.WriteElementString("lastmod", "2005-01-01");
        xmlW.WriteElementString("changefreq", "monthly");
        xmlW.WriteElementString("priority", "0.8");

        xmlW.WriteEndElement();

        xmlW.WriteFullEndElement();

        // close the writer.
        xmlW.Close();

        Console.ReadKey();
xmlW.WriteStartElement("urlset", "http://www.sitemaps.org/schemas/sitemap/0.9");