Attribute().Remove failure

6 views
Skip to first unread message

Vic

unread,
Nov 21, 2009, 5:00:16 PM11/21/09
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
I think anyone could run this code and see the problem. On the last
line, if you look at the content of the xB object in your debugger,
you'll see the "xmlns" attribute, even though it's removed in the
previous command. I've tried variations on this idea, like a while
(xB.Attribute("xmlns") != null). Can anyone tell me why the "xmlns"
attribute is not removed from this object?

xBlog is an <asp:Xml> object on the page. This code is in the
Page_Load event in a ASP.Net app using the 3.5 framework.

HttpWebRequest req = (HttpWebRequest)WebRequest.Create(@"http://
charliescowboyblog.blogspot.com/feeds/posts/default");
HttpWebResponse response = (HttpWebResponse)req.GetResponse();
Stream stream = response.GetResponseStream();
StreamReader reader = new StreamReader(stream, Encoding.UTF8);
XElement xB = XElement.Parse(reader.ReadToEnd());
response.Close();
reader.Close();
xB.Attribute("xmlns").Remove();
xBlog.DocumentContent = xB.ToString();

Cerebrus

unread,
Nov 23, 2009, 12:59:28 PM11/23/09
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
An "xmlns" attribute is not a normal attribute. It is parsed as an
XNamespace, so cannot be removed so simply.

You could use something like the code in the following article to
remove the Namespace, however:
http://tinyurl.com/yc52d9z
Reply all
Reply to author
Forward
0 new messages