472,988 Members | 2,411 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,988 software developers and data experts.

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
3 5420
* 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Mark Bordner | last post by:
Hi All, Given the following XML, I've been trying to figure out what XPATH expression will give me the "position" of a <lineitem> within the <shipto> that is its grandparent. To give you an...
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"...
0
by: maxim mat | last post by:
Hi I need to build client for web service. But when I'm using Visual Studio .NET to add Web Reference, I get error: "Custom tool error: Unable to import WebService/Schema. Unable to import...
2
by: Kathy Burke | last post by:
Hi, I'm using Dim xDoc as XmlDocument Dim xElem As xmlElement = xDoc("xpath") I then assign a variable to a value from the result node: Dim r As String =...
3
by: ano | last post by:
Hi, Anyone knows how to get "xmlns" value from XML file? For example, how to check that this xml file has a xmlns or not? Or how to read the xmlns value? <bookstore...
6
by: Thea | last post by:
Hi I am trying to use datatypes defined in xml file to check correctness of input parameter values To define needed datatypes following schema.xml file was created: <?xml version="1.0"?>...
0
by: SolaFide | last post by:
I have an XML doc that looks something like this: <?xml version="1.0" encoding="utf-8"?> <elem1> <elem2 xmlns="http://someurl.com"> <elem3> <item>some stuff here</item> ...
3
by: Lee | last post by:
Hello guys, I am new to XML and working on a XSLT to transforn yahoo shopping search result to html. my problem is the return XML contain xmlns in root element, here is the sample xml: <?xml...
1
by: yawnmoth | last post by:
<?php $content = ' <a> <d> <b> <c/><c/> </b> </d> <b> <c/><c/><c/>
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: 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...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
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...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
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
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
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.