473,789 Members | 2,694 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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("n ame(parent::*)" ); and get "month". But if I do
nav.Evaluate("n ame(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.SelectSingl eNode(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_windwa rd_dot_net
http://www.windwardreports.com

Jul 9 '06 #1
3 1290
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("<M onth><jan>231</jan></Month>");
XPathNavigator nav = doc.CreateNavig ator();
XPathNavigator n = nav.SelectSingl eNode("//Month/jan");
object o = n.Evaluate("nam e(self::*)");

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

2. The SelectSingleNod e method does different things from Evaluate method.
SelectSingleNod e 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_windwa rd_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("<M onth><jan>231</jan></Month>");
XPathNavigator nav = doc.CreateNavig ator();
XPathNavigator n = nav.SelectSingl eNode("//Month/jan");
object o = n.Evaluate("nam e(self::*)");

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

2. The SelectSingleNod e method does different things from Evaluate method.
SelectSingleNod e 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
3222
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. Xml Doc: Dropdown.xml XML Schema: Dropdown.xsd Here is my XML Document...
3
4288
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" encoding="UTF-8" ?> <ms:Locales xmlns:ms="urn:myspace" xmlns="http://www.w3.org/1999/xhtml"> <ms:Locale id="EN" locale="en-US" xml:lang="EN"> <ms:Text name="LegalInformation">Legal Information</ms:Text>
7
4088
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 other words, I initially create an XPathNavigator for my entire xml document. To get an XPathNavigator object who's root is a given node in the original xml document, there is a unique xpath that will return that node. The unique xpath could have,...
1
1838
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. A closer look has shown that there seems to be a none optimal evaluation of attribute predicates such as . It works as expected if there is a match of the attribute value, i.e. the XPathNavigator calls MoveToNextAttribute until it gets the ID...
11
6467
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); XPathNavigator nav = docNav.CreateNavigator(); XmlDocument doc = new XmlDocument(); doc.LoadXml("<DocumentData></DocumentData>"); XmlElement elem = doc.CreateElement(currentNodeName);
2
4543
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. I can iterate the document and get my XmlType and XmlBaseType values just fine. However, as soon as I call SetValue to write to an attribute, the
4
8779
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 the node does not exist but that is also the result for an empty node. -- thanks - dave david_at_windward_dot_net
1
2823
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 Excel). Using XPathNavigator I managed to read some of the data, but in order to do this I had to manually remove the attributes from the Parent Nodes. Going forward this isnt an option as we may be reading and running hundreds of files a day and so I...
5
7164
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
9663
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
9511
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10195
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10136
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,...
1
7525
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
5415
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
5548
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3695
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2906
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.