467,911 Members | 1,293 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

XPath query with node in empty namespace xmlns=""

Hi all,

my XML looks like:

<root xmlns="tempuri.org">
<result xmlns="">
<date>2006-09-14</date>
<status>ok</status>
</result>
</root>

How do I query the status node using .NET 2.0 and XPath?

The only way I found is using local-name():

strState =
xmlDoc.SelectSingleNode("//*[local-name()='status']").InnerText;

Is there another way?

Thanks for your attention and time,
Stefan

Jan 16 '07 #1
  • viewed: 5197
Share:
3 Replies
* ol**********@gmx.de wrote in microsoft.public.dotnet.xml:
>my XML looks like:

<root xmlns="tempuri.org">
<result xmlns="">
<date>2006-09-14</date>
<status>ok</status>
</result>
</root>

How do I query the status node using .NET 2.0 and XPath?

The only way I found is using local-name():

strState =
xmlDoc.SelectSingleNode("//*[local-name()='status']").InnerText;

Is there another way?
You can setup an XmlNamespaceManager as explained in the MSDN docs, and
generally it would be better to use "/root/result/status" instead of the
more complex expression you are using.
--
Björn Höhrmann · mailto:bj****@hoehrmann.de · http://bjoern.hoehrmann.de
Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/
Jan 16 '07 #2
Bjoern,

thanks for your feedback. I got it. It's quite easy with .NET. I first
tested my XPath in XMLSpy and its XPath evaluator seems to have
problems with default and empty NSs. But now I just tried with .NET,
defined a NS "ns" for "tempuri.org" using the NS manager and then the
XPath just is:

/ns:root/result/status

Stefan
Bjoern Hoehrmann schrieb:
* ol**********@gmx.de wrote in microsoft.public.dotnet.xml:
my XML looks like:

<root xmlns="tempuri.org">
<result xmlns="">
<date>2006-09-14</date>
<status>ok</status>
</result>
</root>

How do I query the status node using .NET 2.0 and XPath?

The only way I found is using local-name():

strState =
xmlDoc.SelectSingleNode("//*[local-name()='status']").InnerText;

Is there another way?

You can setup an XmlNamespaceManager as explained in the MSDN docs, and
generally it would be better to use "/root/result/status" instead of the
more complex expression you are using.
--
Björn Höhrmann · mailto:bj****@hoehrmann.de · http://bjoern.hoehrmann.de
Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld..de
68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/
Jan 16 '07 #3
ol**********@gmx.de wrote:
<root xmlns="tempuri.org">
<result xmlns="">
<date>2006-09-14</date>
<status>ok</status>
</result>
</root>

How do I query the status node using .NET 2.0 and XPath?

The only way I found is using local-name():

strState =
xmlDoc.SelectSingleNode("//*[local-name()='status']").InnerText;
One way would be the XPath expression /*/result/status e.g.
xmlDoc.SelectSingleNode("/*/result/status")
or
xmlDoc.DocumentElement.SelectSingleNode("result/status)

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Jan 16 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Mark Bordner | last post: by
3 posts views Thread by Mike Dickens | last post: by
2 posts views Thread by Kathy Burke | last post: by
3 posts views Thread by ano | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.