469,639 Members | 1,579 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,639 developers. It's quick & easy.

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 11628


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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by John L. Clark | last post: by
25 posts views Thread by kj | last post: by
3 posts views Thread by Mike Dickens | last post: by
2 posts views Thread by Gabe Moothart | last post: by
2 posts views Thread by Manoj G | last post: by
2 posts views Thread by dioscuroi | last post: by
2 posts views Thread by Showjumper | last post: by
6 posts views Thread by tshad | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.