473,787 Members | 2,798 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Removing namespace declaration on a node

Hello,

I believe there is no way to remove the default namespace declaration (For
eg <DataSet xmlns="somethin g">.... ) 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 11408
Manoj G wrote:
I believe there is no way to remove the default namespace declaration (For
eg <DataSet xmlns="somethin g">.... ) 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.Doc umentElement to modify/remove namespace
declaration, for example:

doc.documentEle ment.RemoveAttr ibute("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.DocumentEle ment;
e.Prefix = "b";
Console.WriteLi ne(doc.InnerXml );

#Changing Namespace Declarations in an XML Document
http://msdn.microsoft.com/library/en...gingnamespacex
mlnsdeclaration sinxmldocument. 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
1879
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 "blah:second". The xsd shows that and it compiles fine. When I make use of a Tag from "blah:second" in "blah:first" the marshaller produces the following xml: <Tag1 xmlns="blah:first">
6
8242
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 xmlns:xc="http://www.wolterinkwebdesign.com/xml/xcontent" xmlns="http://www.w3.org/1999/xhtml" module="gastenboek"> <xc:bericht> <xc:id>1</xc:id> <xc:naam type="string"><!]></xc:naam>
3
2112
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 from File#2 and append it back to File#1. The node keeps it's namespace attribute even though File#1 has a default namespace of equal value.
0
1098
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
3463
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, Gustaf
6
8348
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 the dreaded <elementname xmlns=''> was not expected exception. If I comment out the XmlTypeAttribute, it works just fine. Just so you know, when I instantiate an instance of an XmlSerializer, I pass a default namespace to the ctor. ...
1
3903
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 nsmanager = new XmlNamespaceManager(XMLDoc.NameTable); nsmanager.AddNamespace("rd",
1
1145
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 Compiler::Compiler. It seems I'm having trouble with "#include ..." and "using namespace Compiler;" declarations; When removing all "using namespace Compiler;" since I'm inside the namespace Compiler I have some error as unrecognized classes objects and...
0
1023
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 DOMDocument(); $dom->formatOutput = true;
0
9497
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10363
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10110
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9964
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8993
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7517
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6749
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5534
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.