472,133 Members | 1,302 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,133 software developers and data experts.

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 11259
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 leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.