473,396 Members | 1,933 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 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 11385
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: niko | last post by:
Hi there I use SUN's reference implementation of JAXB to generate xml bining. I use two different namespaces ("blah:first" and "blah:second"). some tags of "blah:first" may include tags of...
6
by: Tjerk Wolterink | last post by:
When i open the following xml file in internetexplorer: <?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE xc:content > <xc:xcontent...
3
by: echoharger | last post by:
Hello, I have two XML files. File#1 has a namespace. File#2 does not. I am storing some XML from File#1 in File#2, therefore, the node has a namespace attribute. Later, I remove the node...
0
by: dp | last post by:
Hi, I hava strong typed classes generated from a xsd-file with the root object: /// <remarks/> public class IPDRDoc { ... }
8
by: Gustaf Liljegren | last post by:
I'm using XmlTextWriter to generate an XML document. I can't figure out how to get more than one namespace declaration in an element, when there is no WriteNamespaceDeclaration() method. Thanks,...
6
by: David B. Bitton | last post by:
I am having a problem deserializing XML when the root node is missing a namespace declaration. My Type has an XmlTypeAttribute with a namespace defined. If I attempt to deserialize the XML, I get...
1
by: Dorte | last post by:
Hi, From an ASP.NET application I am loading an xml-file in order to modify it. This is part of the code I have produced so far: XmlDocument XMLDoc = new XmlDocument(); XmlNamespaceManager...
1
by: Leonel Galan | last post by:
Hi all, I'm having trouble with VC++. I have a namespace, named Compiler (I'm building one at university). Some classes appear to be defined in Compiler::Compiler::Compiler or just...
0
by: Jordi Puigmique | last post by:
Hello, I'm using this script to change the IP settings for a server application that won't run if the xml has the version declaration tag: <?php $ip = getenv("REMOTE_ADDR") ; $dom = new...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.