473,699 Members | 2,202 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

programatically remove namespace from XmlDocument

Hi,
I'm writing a program that loads an xml document, modifies it, validates
it with an xsd schema, then send it on to another application for
processing. I have no control over this aplication.

The problem is this: for some reason, this application rejects any xml
documents with a namespace (as crazy as that sounds). So I need to strip
the xmlns="www.MyNa mespace.com" attribute from the document before
passing it on.

This seems like it should be an easy thing to do... but I can't figure
out how to do it. I've tried

MyXml.DocumentE lement.Attribut es.RemoveAll();

and even

MyXml.LoadXml(" <RootNode>" + OrderXml.Docume ntElement.Inner Xml +
"</RootNode>");

but neither of those work. RemoveAll() has no effect on the xmlns
attribute, and re-loading the xml with a new root node only moves the
xmlns attribute down to the next child of RootNode.

Any ideas?

thanks,
Gabe
Nov 12 '05 #1
2 15767
If only the attribute that you want to get rid off, maybe using regular
expression is quick and dirty way to do it. Even if you need to remove the
prefix you still can use Regex. This regex should help you match the
attributes:

<.*?(xmlns="www .MyNamespace.co m").*?>

--
Victor Hadianto
http://synop.com/Products/SauceReader/

"Gabe Moothart" <ga**@imaginesy stems.net> wrote in message
news:Os******** ******@tk2msftn gp13.phx.gbl...
Hi,
I'm writing a program that loads an xml document, modifies it, validates
it with an xsd schema, then send it on to another application for
processing. I have no control over this aplication.

The problem is this: for some reason, this application rejects any xml
documents with a namespace (as crazy as that sounds). So I need to strip
the xmlns="www.MyNa mespace.com" attribute from the document before passing
it on.

This seems like it should be an easy thing to do... but I can't figure out
how to do it. I've tried

MyXml.DocumentE lement.Attribut es.RemoveAll();

and even

MyXml.LoadXml(" <RootNode>" + OrderXml.Docume ntElement.Inner Xml +
"</RootNode>");

but neither of those work. RemoveAll() has no effect on the xmlns
attribute, and re-loading the xml with a new root node only moves the
xmlns attribute down to the next child of RootNode.

Any ideas?

thanks,
Gabe

Nov 12 '05 #2
Gabe Moothart wrote:
The problem is this: for some reason, this application rejects any xml
documents with a namespace (as crazy as that sounds). So I need to strip
the xmlns="www.MyNa mespace.com" attribute from the document before
passing it on.


You can't remove namespace for XmlDocument in-memory. Namespace is
integral part of name, so you have to recreate any element, which is in
the namespace.
Alternatively strip namespaces while writing XmlDocument out using some
custom XmlWriter, e.g. take a look at
http://blogs.msdn.com/kaevans/archiv...02/206432.aspx

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com
Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2966
by: Izvra | last post by:
How can i specify default XML namespace when it does not declared in the xml document I need it for validation against xml schema @@@I have a procedure Sub ValidateXMLDocument(ByRef XMLDocument As Xml.XmlDocument, ByVal SchemaPath as string) If XMLDocument.DocumentElement.NamespaceURI = String.Empty Then '@@@ calculating target namspace of the schema
5
13578
by: jrmsmo | last post by:
Hi I have a document as follows: <?xml version="1.0"?> <metadata xml:lang="en"> </metadata> I want to change the document so it looks as follows: <?xml version="1.0"?> <metadata xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://localhost/XMLDemo/MyXMLschema.xsd">
3
3479
by: JT | last post by:
Hi all, I have a pretty basic question... I have a method (below) which uses ExecuteXMLReader to load the output from a FOR XML Explicit stored procedure into an XML document, and then save the document to a file. It works well. Now, I am trying to add namespace support, and want my namespace to be something like "http://MapTo837P". How do I get this incorporated into the XML document? Thanks.
4
4177
by: David Grogan | last post by:
Hi, 2 questions.... 1. I'm parsing an XHTML document that contains both the default namespace (xmlns="http://www.w3.org/1999/xhtml") and a custom one (xmlns:r="...") - both of these being attributes of <html>. When I then insert new XmlNodes into the DOM the HTML tags all end up getting an unnecesarry 'xmlns' attribute added, elements with the 'r' prefix don't, which is correct. Is there any way to stop the XmlNode/XmlWriter from...
0
5974
by: XML newbie: Urgent pls help! | last post by:
I am using VB.Net. My program is to connect to a remote IPAddress. Once, it verifies the login information it should display the SessionID and enable some button . I appreciate your help and thanku in advance When I run the pgm , I get the error: Can't parse login information. Namespace Manager or XsltContext needed. This query has a prefix, variable or userdefined function. I have added the Try-catch in all my functions. In...
4
4147
by: XML newbie: Urgent pls help! | last post by:
I am using VB.Net. My program is to connect to a remote IPAddress. Once, it verifies the login information it should display the SessionID and enable some button . I appreciate your help and thanku in advance When I run the pgm , I get the error: Can't parse login information. Namespace Manager or XsltContext needed. This query has a prefix, variable or userdefined function. I have added the Try-catch in all my functions. In...
6
24502
by: fzhang | last post by:
I am relatively new to XML and C#. So, forgive me if this question is too newbie. :-) While assuming this is an easy programming task, I couldn't find a single reference anywhere for how to do it. Here is the situation: I am given an XML file like the one below from other group in my company to load the data into our database. <root xmlns="the-namespace">
2
4106
by: daz_oldham | last post by:
Hi Everyone I have an xml document, and for the purposes of my application, I am going to take a node of the xml (child), add a child to it and then store it into the database for later use. So I start with: <doc xmlns:"http://www.xml.com"> <stuff>
5
15067
by: Tim Mackey | last post by:
hi, i have put my web.sitemap in /App_Data so i can edit it programatically via a web admin page, inheriting the modify permissions from the App_Data folder etc. i was hoping the provider would simply persist any changes i made, but it doesn't happen. e.g. selected.ParentNode.ChildNodes.Remove(selected); throws a NotSupportedException "Collection is read-only"
0
8705
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8628
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
9054
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8943
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
7785
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
6550
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
5884
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
4637
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3075
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.