472,952 Members | 2,266 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,952 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 11794


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: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

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.