Building a Google Product Feed in .Net (C#)?

限于喜欢 提交于 2019-12-05 12:56:39

What if, instead of doing this:

xw.WriteStartElement("rss version=\"2.0\"");
xw.WriteAttributeString("xmlns", "g", null, "http://base.google.com/ns/1.0");

You did something like this:

xw.WriteStartElement("rss");
xw.WriteAttributeString("version", "2.0");
xw.WriteAttributeString("xmlns", "g", null, "http://base.google.com/ns/1.0");

I've never used XmlTextWriter before, but I'd think you should be able to add the version attribute after creating the rss tag, based on your code example. (Might wanna double-check my syntax)

The problem is that you're trying to create an element with a name of rss version="2.0". Instead, you should be creating an element with a name of rss, and setting the version attribute to have a value of 2.0:

xw.WriteStartElement("rss");
xw.WriteAttributeString("version", "2.0");

Personally I'd use LINQ to XML instead of XmlWriter to start with, mind you - it's a much nicer API.

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