473,387 Members | 1,569 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,387 software developers and data experts.

selecting the VALUE of an XML element with XPathNavigation...

I've done a bit of transoforming XML in ASP.net by passing it to an XSL file
and returning the results.

I'm not trying to navigate an XML file and just return one value. I could
use XSL for this, but seems to be overkill to just return one value.

This is what I have thus far:

dim filename As String =
(MapPath("/usercontrols/navigation/siteStructure.xml"))
Dim xDoc As XPathDocument = New XPathDocument(filename)
Dim xNav1 as XPathNavigator = xDoc.CreateNavigator()
xNav1.Select("linkTitle")
dim strLinkTitle as String = xNav1.value

The problem is that xNav1.value returns the entire Node. I just want the
value of the element 'lnkTitle' as a string. I'm completely stumped as to
how to get that via asp.net.

-Darrel
Nov 18 '05 #1
4 1592
I think I *can't* do this with xpathnavigator. Is that correct? Do I need to
use an XMLReader instead? If so, can I navigate with the navigator then
select the element with the reader?

-Darrel
Nov 18 '05 #2
an XPath returns a node or collection of nodes:

the following xml frag:

<a id="a1" b="d">hello</a>

if an XPath query returns the node "a", it will have two attribute children
nodes ("id" and "b")and a child text node ("hello"). you are probably
interested in the childs value not the parents.

-- bruce (sqlwork.com)

"darrel" <no*****@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
I've done a bit of transoforming XML in ASP.net by passing it to an XSL file and returning the results.

I'm not trying to navigate an XML file and just return one value. I could
use XSL for this, but seems to be overkill to just return one value.

This is what I have thus far:

dim filename As String =
(MapPath("/usercontrols/navigation/siteStructure.xml"))
Dim xDoc As XPathDocument = New XPathDocument(filename)
Dim xNav1 as XPathNavigator = xDoc.CreateNavigator()
xNav1.Select("linkTitle")
dim strLinkTitle as String = xNav1.value

The problem is that xNav1.value returns the entire Node. I just want the
value of the element 'lnkTitle' as a string. I'm completely stumped as to
how to get that via asp.net.

-Darrel

Nov 18 '05 #3
> if an XPath query returns the node "a", it will have two attribute
children
nodes ("id" and "b")and a child text node ("hello"). you are probably
interested in the childs value not the parents.


ARRRRRRRRRGGGGGGGGGGHHHHHHHHHHH!!!!

Yes, you are absolutely right. Duh. I always forget that the value-of *is* a
child of the element.

Dang XML terminology!

OK, can I ask for a bit of help with the syntax?

I have this:

xNav1.Select("//linkTitle[parent::linkID = '" & intPageID & "']")

Which should find the linkTitle that has a parent that has a child of linkID
with the value of intPageID

Once I navigate to that, I want to grab the child text element of linkTitle.
So, I have this:

dim strLinkTitle as String = xNav1.MoveToFirstChild.ToString

But that returns a boolean true/false as opposed to the value.

I also tried changing the xpath query:

xNav1.Select("//linkTitle[parent::linkID = '" & intPageID &
"']/linkTitle")

but that, again, returns the entire node it seems.

my brain hurts.
Nov 18 '05 #4
MoveToFirstChild returns a boolean. you will need to find node, movetochild,
then get value from the navigator.

"darrel" <no*****@hotmail.com> wrote in message
news:OJ**************@TK2MSFTNGP09.phx.gbl...
if an XPath query returns the node "a", it will have two attribute children
nodes ("id" and "b")and a child text node ("hello"). you are probably
interested in the childs value not the parents.


ARRRRRRRRRGGGGGGGGGGHHHHHHHHHHH!!!!

Yes, you are absolutely right. Duh. I always forget that the value-of *is*

a child of the element.

Dang XML terminology!

OK, can I ask for a bit of help with the syntax?

I have this:

xNav1.Select("//linkTitle[parent::linkID = '" & intPageID & "']")

Which should find the linkTitle that has a parent that has a child of linkID with the value of intPageID

Once I navigate to that, I want to grab the child text element of linkTitle. So, I have this:

dim strLinkTitle as String = xNav1.MoveToFirstChild.ToString

But that returns a boolean true/false as opposed to the value.

I also tried changing the xpath query:

xNav1.Select("//linkTitle[parent::linkID = '" & intPageID &
"']/linkTitle")

but that, again, returns the entire node it seems.

my brain hurts.

Nov 18 '05 #5

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

Similar topics

2
by: Mike Kamermans | last post by:
I'm having some trouble using text() in an xsl:value-of xpath. I have the following xml: .... <graphemes> <grapheme>1</grapheme> <grapheme>2</grapheme> <grapheme>3</grapheme> </graphemes>...
2
by: areef.islam | last post by:
Hi, I am kinda new to javascript and I am having this problem with selecting multiple options from a select tag. Hope someone can help me out here. here is my code...
1
by: jdhcards | last post by:
Hello, I've been banging my head against a problem all day without a solution, and I'm hoping you all can help. I've got a piece of XML that defines a set of elements in a flat list. Each of...
4
by: Paul J. Lucas | last post by:
I have a simple form that contains an INPUT element that has an initial value. <form name="Form"> <input name="Number" type="text" value="Hello"> </form> When the form loads, I want all of...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
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,...

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.