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

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,

<ordersHistory xmlns="http://tempuri.org/Orders.xsd">
<order number="PO-1" added="12/12/2002">
<client name="Microsoft">
<address country="USA" city="Washington" />
<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="Germany" 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 11813


Joe Bloggs wrote:

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

<ordersHistory 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*******@yahoo.de> wrote in message
news:eI**************@TK2MSFTNGP09.phx.gbl...


Joe Bloggs wrote:

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

<ordersHistory 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
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...
25
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...
3
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"...
2
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. ...
2
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...
2
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
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...
0
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...
6
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...
2
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...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...

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.