Wednesday, March 28, 2012

Why isn't my xpathNavigator selecting what I want?

I think I am in syntax hell. ;o)
Here's some XML that I'm trying to grab some text from:
<?xml version="1.0"?>
<!--Created on 10/16/2004 8:05:57 PM-->
<menuItems>
<menuItem>
<pageID>2</pageID>
<pageName>Tax and Accounting</pageName>
<menuCategory>tax</menuCategory>
<menuItem>
<pageID>3</pageID>
<pageName>Services and Rates</pageName>
<menuCategory />
</menuItem>
What I want to do is select the menuCategory text of any parent of the
menuItem who's pageID is set to specific variable.
So, if I pass a pageID of '3' to the above, I want to look up all of it's
parents until I find one with a menuCategory set to a value other than
empty.
I thought I could just use an expression, but now realize that I probably
need to use an iterator to grab and entire node, check the first
menuCategory for a value, if empty, navigate up, check again, and repeat
until I get a value.
Does that sound like the right direction?> <?xml version="1.0"?>
> <!--Created on 10/16/2004 8:05:57 PM-->
> <menuItems>
> <menuItem>
> <pageID>2</pageID>
> <pageName>Tax and Accounting</pageName>
> <menuCategory>tax</menuCategory>
> <menuItem>
> <pageID>3</pageID>
> <pageName>Services and Rates</pageName>
> <menuCategory />
> </menuItem>
Further clarification. I think I figured out how to grab the value without
the need of the iterator. This:
//menuCategory[../descendant-or-self::pageID = '3']
works just fine in an XSL file...it returns exactly what I need.
However, I'm not sure how to turn that select into a STRING in my asp.net
code:
dim strtest as string
strtest = xpn.Select("//menuCategory[../descendant-or-self::pageID = '3']")
I can't do the above, because I can't convert the apathnavigator select into
a string. What's the path I need to take to turn that into a text string?
-Darrel
Actually, let me simplify my entire question:
How do I go from an axpathnavigator selected item to a string?
I'd like to do this:
xpathnavigator.select(my statement).tostring
However, I can't convert a xpathnavigator.select to a string. I'm guessing
I'm missing some in-between logic here?

0 comments:

Post a Comment