By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,543 Members | 902 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,543 IT Pros & Developers. It's quick & easy.

What is the best way to remove XML namespace

P: n/a
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
Share this Question
Share on Google+
2 Replies

P: n/a


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

P: n/a
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.