469,353 Members | 2,066 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,353 developers. It's quick & easy.

Removing namespace declaration on a node

Hello,

I believe there is no way to remove the default namespace declaration (For
eg <DataSet xmlns="something">.... ) on an XmlNode object directly through
DOM.

So, what is the best way to remove it
1) XSLT templates?
2) Copy all the contents into a new node and leave out the namespace? Use
this node node in lieu of the old one?
3) Some other way?

Thanks,
Manoj G
Nov 12 '05 #1
2 11059
Manoj G wrote:
I believe there is no way to remove the default namespace declaration (For
eg <DataSet xmlns="something">.... ) on an XmlNode object directly through
DOM.

So, what is the best way to remove it
1) XSLT templates?
2) Copy all the contents into a new node and leave out the namespace? Use
this node node in lieu of the old one?
3) Some other way?


More efficient would be to filter namespace out when loading XML into
XmlDocument or when writing it out.

--
Oleg Tkachenko [XML MVP, MCP]
http://blog.tkachenko.com
Nov 12 '05 #2
Thanks for Oleg's suggestion.

Hi Manoj G,

As for the Manipulation XmlNamespace in .net's System.Xml apis, I haven't
found any direct means for modifying the xml namespaceURI or prefix in
XmlDocument (they're readonly). However, if you just want to modify
(remove) the default namespace declaration, we can use the Attributes
collection of XmlDocument.DocumentElement to modify/remove namespace
declaration, for example:

doc.documentElement.RemoveAttribute("xmlns")

Or if you want to mofiying namespace Prefix for elements, we can use the
following means:

XmlDocument doc = new XmlDocument();
doc.LoadXml("<a:test xmlns:a='123' xmlns:b='456'/>");
XmlElement e = doc.DocumentElement;
e.Prefix = "b";
Console.WriteLine(doc.InnerXml);

#Changing Namespace Declarations in an XML Document
http://msdn.microsoft.com/library/en...gingnamespacex
mlnsdeclarationsinxmldocument.asp?frame=true

#Changing Namespace Prefix Properties
http://msdn.microsoft.com/library/en...gingnamespacep
refixproperties.asp?frame=true
In addition, I think Oleg's suggestion on using XmlWriter to filtering
prefix (or using xslt transformation) is a efficient means for document
based replacing. Here is a certain article mentioned remove namespace
prefix through a customized Writer:

#How Do I Remove Namespaces Using XSLT?
http://blogs.msdn.com/kaevans/archiv...16/132959.aspx

Hope also helps. Thanks,
Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


Nov 12 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by niko | last post: by
3 posts views Thread by echoharger | last post: by
8 posts views Thread by Gustaf Liljegren | last post: by
1 post views Thread by Leonel Galan | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.