XmlWriter The ':' character, hexadecimal value 0x3A, cannot be included in a name

微笑、不失礼 提交于 2019-12-12 02:07:13

问题


I am using an XmlWriter and getting the following error:

Invalid name character in 'news:news'. The ':' character, hexadecimal value 0x3A, cannot be included in a name.

does anyone have any idea what is causing this? here is my code:

using (XmlWriter writer = XmlWriter.Create("moo.xml"))
            {               

                writer.WriteStartDocument();
                writer.WriteStartElement("urlset", "http://www.sitemaps.org/schemas/sitemap/0.9");
                writer.WriteAttributeString("xmlns", "news", null, "http://www.google.com/schemas/sitemap-news/0.9");


                writer.WriteStartElement("url");
                writer.WriteElementString("loc", "http://www.monkeys.co.uk");

                writer.WriteStartElement("news:news");
                writer.WriteEndElement();

                writer.WriteEndElement();



                writer.WriteEndElement();
                writer.WriteEndDocument();

            }

回答1:


You need to use the overload of WriteStartElement that takes two parameters:

writer.WriteStartElement("news", "http://www.google.com/schemas/sitemap-news/0.9");
//               Tag   ----^       ^--- Namespace


来源:https://stackoverflow.com/questions/13680615/xmlwriter-the-character-hexadecimal-value-0x3a-cannot-be-included-in-a-nam

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!