473,769 Members | 1,723 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.SelectSi ngleNode("//*[local-name()='status']").InnerTex t;

Is there another way?

Thanks for your attention and time,
Stefan

Jan 16 '07 #1
3 5465
* ol**********@gm x.de wrote in microsoft.publi c.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.SelectS ingleNode("//*[local-name()='status']").InnerTex t;

Is there another way?
You can setup an XmlNamespaceMan ager 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****@h oehrmann.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.or g" using the NS manager and then the
XPath just is:

/ns:root/result/status

Stefan
Bjoern Hoehrmann schrieb:
* ol**********@gm x.de wrote in microsoft.publi c.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.SelectSi ngleNode("//*[local-name()='status']").InnerTex t;

Is there another way?

You can setup an XmlNamespaceMan ager 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****@h oehrmann.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**********@gm x.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.SelectSi ngleNode("//*[local-name()='status']").InnerTex t;
One way would be the XPath expression /*/result/status e.g.
xmlDoc.SelectSi ngleNode("/*/result/status")
or
xmlDoc.Document Element.SelectS ingleNode("resu lt/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
5169
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 idea of what I'm trying to do...I'm transforming this XML into XSL-FO; which I will process with FOP to produce a PDF file. Each <shipto> element with the XML correlates to a new "section"
3
10043
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" xmlns:ns1="abc" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output indent="yes" media-type="text/xml" standalone="yes" version="1.0"/> <xsl:template match="/">
0
2988
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 binding 'controllerSoapBinding' from namespace 'http://Bla-Bla-Bla'. Unable to import operation 'getClient'. The datatype 'Array' is missing. " Some problem when I try to use wsdl.exe tool in .NET. I get: Schema validation warning: Type 'cww:Class' is...
2
5213
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 = xElem.Attributes.GetNamedItem("name").Value This works fine unless there is no node returned, then I get an "object reference not set" error.
3
9910
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 xmlns:bk="http://www.lucernepublishing.com"> <book> <title>Pride And Prejudice</title> </book>
6
20823
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"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:pd="uri:myUri.com"> <xsd:simpleType name="pd:width">
0
1438
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> <item>some more stuff here</item> <item>even more stuff here</item> </elem3>
3
2880
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 version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl" href="aproductsearch.xslt"?> <ProductSearch xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:yahoo:aprods" xsi:schemaLocation="urn:yahoo:aprods...
1
2130
by: yawnmoth | last post by:
<?php $content = ' <a> <d> <b> <c/><c/> </b> </d> <b> <c/><c/><c/>
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10211
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9994
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8870
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7408
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6673
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5298
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3561
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.