473,698 Members | 2,467 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 15766
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
5973
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
24498
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
8678
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
8609
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
8871
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
7737
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...
0
5861
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
4371
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4621
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3052
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
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.