473,386 Members | 1,827 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,386 software developers and data experts.

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.MyNamespace.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.DocumentElement.Attributes.RemoveAll();

and even

MyXml.LoadXml("<RootNode>" + OrderXml.DocumentElement.InnerXml +
"</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 15731
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.com").*?>

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

"Gabe Moothart" <ga**@imaginesystems.net> wrote in message
news:Os**************@tk2msftngp13.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.MyNamespace.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.DocumentElement.Attributes.RemoveAll();

and even

MyXml.LoadXml("<RootNode>" + OrderXml.DocumentElement.InnerXml +
"</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.MyNamespace.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
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...
5
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...
3
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...
4
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...
0
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...
4
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...
6
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...
2
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. ...
5
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...
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: 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: 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...
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
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...

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.