all groups > dotnet xml > january 2006 >
You're in the

dotnet xml

group:

Using XPath to build a Breadcrumb menu.


Using XPath to build a Breadcrumb menu. Mike
1/19/2006 3:32:02 AM
dotnet xml:
Hi,

I'm a complete newbie to XML and am needing to rush through a job requiring
far more knowledge than I have the time to gather.

Basically... I need to build a breadcrumb menu for our website, using a
passed URL and an XML menu string, what has been retrieved from an SQL server
(we need to support no-script clients, hence the use of the request URL).

Essentially I need to do the following::

- Search the XML string to find nodes where an attribute contains the
absolutepath of the passed URL.
eg PassedURL = "http://www.mysite.com/Default.aspx?dept=main&info=new"
AbsolutePath="/Default.aspx"
Find nodes like <item href="/Default.aspx?dept=main&content=old" />

- Do a test on the full attribute value to see if it's the one I'm really
looking for.
eg Compare the passed querystring args to the attribute's args (they
might not be in the same order, so I need to test the args individually).

- If it is the one I'm looking for, then gather up it and all it's
ancestors, to build a breadcrumb menu

- If it's not... search for the next node.

Being a menu, the structure is multi-level, and <item href="value" /> nodes
can appear at all levels... and I have no way of knowing how they got
there... I need to search the menu, find the entry for the node they chose,
and then back-track to build up the href items of all the ancestor nodes.

So far, I've worked out that I need to be using XPath, and have worked out
how to get the XML string into an XPathDocument

XPathDocument xml_PathDoc = new XPathDocument(new StringReader((string)
xml_String));

and then I THINK that I need to use an Navigator like this...

XPathNavigator xmlPathNav = xml_PathDoc.CreateNavigator();

The test part I'm obvioulsy OK with... that's just simple string work... but
the search, find and then gather ancestors... I'm totally lost.

It's taken me a day to get this far... and I have people screaming at me to
get the thing working.

Much appreciate any assistance, hints or links thrown my way.

Cheers,

RE: Using XPath to build a Breadcrumb menu. Mike
1/19/2006 9:28:02 PM
Never Mind... I've worked it all out and having it running now.

Cheers.

[quoted text, click to view]
AddThis Social Bookmark Button