473,373 Members | 1,085 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,373 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 11380
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.