473,609 Members | 2,241 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What is the best way to remove XML namespace

Hi,

I am trying to remove the namespace in the root node in the following XML,

<ordersHistor y xmlns="http://tempuri.org/Orders.xsd">
<order number="PO-1" added="12/12/2002">
<client name="Microsoft ">
<address country="USA" city="Washingto n" />
<notes>
Produces a great framework for developing applications.
</notes>
</client>
<items>
<item id="1" name="Windows XP Professional" qty="2" />
<item id="2" name="BizTalk 2002" qty="1" />
</items>
<total>12,2</total>
</order>
<order number="PO-2" added="10/11/2002">
<client name="Dobkin &amp; Mappets gmbh">
<address country="German y" city="Berlin" />
<notes>
Shipped...
</notes>
</client>
<items>
<item id="3" name="Red pencils" qty="1" />
<item id="4" name="Color pens" qty="20" />
<item id="5" name="Plastic pocket" qty="2" />
</items>
<total>10000</total>
</order>
</ordersHistory>

so that I do not have to take namespaces into consideration in my XPath.
What is the best way to remove the xmlns attribute "safely"?

Thanks in advanced
Jan 23 '06 #1
2 11825


Joe Bloggs wrote:

I am trying to remove the namespace in the root node in the following XML,

<ordersHistor y xmlns="http://tempuri.org/Orders.xsd">
<order number="PO-1" added="12/12/2002">
All elements are in that namespace with namespace URI
http://tempuri.org/Orders.xsd as the declaration on the root elements is
also valid for child and descendant elements. If you wanted to change
the namespace of all those elements you would have to change each element.
so that I do not have to take namespaces into consideration in my XPath.
What is the best way to remove the xmlns attribute "safely"?


Then don't try to "fix" or rather damage the original XML but rather
learn how to use XPath with namespaces
<http://www.faqts.com/knowledge_base/view.phtml/aid/34022/fid/616>

If you really wanted to transform that document into one without using
namespaces then an XSLT stylesheet could do that e.g.
<xsl:template
xmlns:pf1="http ://tempuri.org/Orders.xsd"
match="pf1:*>
<xsl:element name="{local-name()}" namespace="">
<xsl:apply-templates select="@* | node()" />
</xsl:element>
</xsl:template>

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Jan 23 '06 #2
Thanks,

this did the trick, however, I have also tried using RegEx with some
success, however, this calls for getting the XML string, run through RegEx
then read it back into the DOM.

In any case, I am too "lazy" to deal with the xml namespaces when it comes
to doing XPath. Therefore, removing the Xml Namespace does the trick!

Anyway, thanks again.

Regards

"Martin Honnen" <ma*******@yaho o.de> wrote in message
news:eI******** ******@TK2MSFTN GP09.phx.gbl...


Joe Bloggs wrote:

I am trying to remove the namespace in the root node in the following
XML,

<ordersHistor y xmlns="http://tempuri.org/Orders.xsd">
<order number="PO-1" added="12/12/2002">


All elements are in that namespace with namespace URI
http://tempuri.org/Orders.xsd as the declaration on the root elements is
also valid for child and descendant elements. If you wanted to change the
namespace of all those elements you would have to change each element.
so that I do not have to take namespaces into consideration in my XPath.
What is the best way to remove the xmlns attribute "safely"?


Then don't try to "fix" or rather damage the original XML but rather learn
how to use XPath with namespaces
<http://www.faqts.com/knowledge_base/view.phtml/aid/34022/fid/616>

If you really wanted to transform that document into one without using
namespaces then an XSLT stylesheet could do that e.g.
<xsl:template
xmlns:pf1="http ://tempuri.org/Orders.xsd"
match="pf1:*>
<xsl:element name="{local-name()}" namespace="">
<xsl:apply-templates select="@* | node()" />
</xsl:element>
</xsl:template>

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/

Jan 23 '06 #3

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

Similar topics

1
2719
by: John L. Clark | last post by:
I am curious as to the rationale, and effect, of having default namespaces not applying (directly) to attributes (see http://www.w3.org/TR/REC-xml-names/#defaulting). Given an attribute without a namespace prefix, what is its namespace, if default namespaces do not apply? Are (either of) prefixed or non-prefixed attributes correct? For example, are the following equivalent: <html:br class="foo"...
25
3070
by: kj | last post by:
Consider the following XML document: <?xml version='1.0' encoding='UTF-8'?> <bar:foo xmlns:bar='someuri'> <baz/> </bar:foo> What namespace does baz belong to? What is this namespace bound to/associated with? My understanding was that baz above belongs to some "default default namespace", but I have not been able to
3
10035
by: Mike Dickens | last post by:
hi, i'm sure this has come up before but havn't managed to find an answer. if i have the following xslt <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet method="xml" version="1.0" xmlns:ns1="abc" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output indent="yes" media-type="text/xml" standalone="yes" version="1.0"/> <xsl:template match="/">
2
15761
by: Gabe Moothart | last post by:
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.
2
11401
by: Manoj G | last post by:
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?
2
1269
by: dioscuroi | last post by:
Is there any difference between declaring in unnamed namespace and i global namespace? I can't recognize this p.s: Have a nice day ^_________ -
2
1252
by: Showjumper | last post by:
I get this error after i changed the root namespace in the properties window for my vbnet server control since i didnt like the fact that vbnet uses the project name as the root namespace. Or do i need to changeit prior to compiling it, when i first make the project? Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details...
0
969
by: SA | last post by:
Hi all, VS 2005 beta 1, with .NET 2.0 beta 1. I am trying to see if I can get WSE 2.0 SP 1 to work with it. I need to find out what the name of the autogenerated assembly is, in order to add the HttpHandler for my WSE 2.0 SoapService. Also, I need to find out what the namespace is of the classes in my Web project.
6
7172
by: tshad | last post by:
Is there a reason to use session.remove over session.contents.remove? Don't they both remove the key and data from the contents collection? I assume that session(x) = nothing does essentially the same thing but is actually deleted later by the GC. Thanks, Tom
2
8190
by: SR | last post by:
How can I remove an empty namespace with XElement ? Using the below code I wish to apply the namespace only to the root node <urlsetbut I obtain also an empty xmlns="" on the child nodes. Thanks Sandro XNamespace ns = "http://www.sitemaps.org/schemas/sitemap/0.9"; XElement elRoot = new XElement(ns + "urlset", new XElement ("url",
0
8113
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
8051
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
8557
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...
0
8512
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...
0
8378
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...
1
6047
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
4066
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2517
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
0
1373
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.