473,406 Members | 2,345 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

XPathNavigator and name()

Hi;

Two questions. I have an XPathNavigator object where it's OuterXml property
is "<jan>231</jan>" and I am trying to write an xpath statement that will
return the "jan".

XPathNavigator nav = ...;

1) I can do nav.Evaluate("name(parent::*)"); and get "month". But if I do
nav.Evaluate("name(self::*)"); I get "" returned. Shouldn't I get "jan"?

2) This is for code that can be passed random xpath statements. For some it
seems I need to call nav.SelectSingleNode(xpath) and for some (the name()
example) nav.Evaluate(). Is there any way to have a single call that handles
any xpath?

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Jul 9 '06 #1
3 1261
Hi Dave,

Thanks for posting!

1. I tried to reproduce it, but with my code below, it is working fine. The
object returns "jan".

XmlDocument doc = new XmlDocument();
doc.LoadXml("<Month><jan>231</jan></Month>");
XPathNavigator nav = doc.CreateNavigator();
XPathNavigator n = nav.SelectSingleNode("//Month/jan");
object o = n.Evaluate("name(self::*)");

Could you show me your code that can repro it? Thanks.

2. The SelectSingleNode method does different things from Evaluate method.
SelectSingleNode does an XPath query and returns another XPathNavigator, so
that you can move to another node with it.

However, Evaluate method evaluates an XPath expression and returns result.
It will be converted to an object.

Kevin Yu
Microsoft Online Community Support

================================================== ==========================
==========================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
================================================== ==========================
==========================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Jul 10 '06 #2
I swear this wasn't working yesterday - but it work now. I must have types
something wrong without realizing it.

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

"Kevin Yu [MSFT]" wrote:
Hi Dave,

Thanks for posting!

1. I tried to reproduce it, but with my code below, it is working fine. The
object returns "jan".

XmlDocument doc = new XmlDocument();
doc.LoadXml("<Month><jan>231</jan></Month>");
XPathNavigator nav = doc.CreateNavigator();
XPathNavigator n = nav.SelectSingleNode("//Month/jan");
object o = n.Evaluate("name(self::*)");

Could you show me your code that can repro it? Thanks.

2. The SelectSingleNode method does different things from Evaluate method.
SelectSingleNode does an XPath query and returns another XPathNavigator, so
that you can move to another node with it.

However, Evaluate method evaluates an XPath expression and returns result.
It will be converted to an object.

Kevin Yu
Microsoft Online Community Support

================================================== ==========================
==========================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
================================================== ==========================
==========================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Jul 11 '06 #3
No problem, Dave. Anyway, it was nice to know that it's working for you.

If you have any questions, please feel free to post them in the community.

Kevin Yu
Microsoft Online Community Support

================================================== ==========================
==========================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
================================================== ==========================
==========================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Jul 11 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Obe | last post by:
PLEASE HELP! I'm writing a function to populate DropDownLists from and xml file. I am having a problem getting my XPathNavigator to select any nodes when I attach a schema to my xml document. ...
3
by: Alexander Gräf | last post by:
Hello, I'm stuck with a simple problem, for which I don't have a solution. I basically have an XML file containing fragments of plain text and html, in several languages: <?xml version="1.0"...
7
by: David Thielen | last post by:
Hi; Is there a way from an XPathNavigator object to get an xpath string that will, when used in a Select(xpath) on the underlying base/root XPathNavigator return the same XPathNavigator? In...
1
by: SteZgr | last post by:
I have implemented in .NET 2.0 a custom XPathNavigator for Xpath filtering on an object tree. So far it works. While analyzing the performance, I have noticed a lot of MoveToNextAttribute calls. ...
11
by: ericms | last post by:
Can anybody show me how to insert a CDATA section using XPathNavigator ? I have tried the follwing with no luck: XmlDocument docNav = new XmlDocument(); docNav.LoadXml(xmlString);...
2
by: =?Utf-8?B?Tm9yZW1hYw==?= | last post by:
Hi. Using VS2005, .NET 2.0. I have an xml document that I want to go through and set the values on attributes of elements. The elements are complex types defined in my schema (xsd) files. ...
4
by: =?Utf-8?B?RGF2aWQgVGhpZWxlbg==?= | last post by:
Hi; If I have an XPathNavigator object and for a given xpath statement need to know if the node exists, how should I do this? I have found for some xpath functions it returns an empty string if...
1
by: WestyCHC | last post by:
Morning all from a newbie. I have recently written an automation program (my first ever program) for testing and now I am trying to read XML data and assign the values to variables (rather than...
5
by: Gigs_ | last post by:
hi i have xml in this structue <?xml version="1.0" encoding="utf-8" ?> <obrazac sifra="N-08-V"> <!-- Stanje: u obradi Primjedbe: nema -->
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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,...
0
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...

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.