I have the following code that uses xquery to return search results
from an xml doc.
dim xmlString as string
xmlString =
"siteMapNode/siteMapNode/siteMapNode/siteMapNode[contains(translate(@title,'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ'),
'" + txtSearchCriteria.Text.ToUpper() + "')]"
nodeList=root.SelectNodes(xmlString,nsmgr)
It all works great as long as I specify the level in which to search:
siteMapNode/siteMapNode/siteMapNode/siteMapNode
but I want to search all levels of the doc.
siteMapNode
siteMapNode/siteMapNode
siteMapNode/siteMapNode/siteMapNode
etc..
will I have to loop for each level and append the nodes:
dim myNode as string
dim myNodeLevel as string
do while something
myNodeLevel = myNodeLevel & "/siteMapNode"
loop
xmlString =
myNodeLevel &
"[contains(translate(@title,'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ'),
'" + txtSearchCriteria.Text.ToUpper() + "')]"
nodeList=root.SelectNodes(xmlString,nsmgr)
anyway, that is air code but hopefully you'll get my point. Any help
is appreciated.
Stephen - 26 Aug 2005 20:04 GMT
I did figure something out. Here is what I did:
dim doc as XmlDocument = new XmlDocument()
doc.Load(Server.MapPath("web.sitemap"))
dim nodeList as XmlNodeList
dim root as XmlNode = doc.DocumentElement
dim nsmgr as XmlNamespaceManager = new
XmlNamespaceManager(doc.NameTable)
nsmgr.AddNamespace("ns0",
"xmlns:ns0='urn:schemas-microsoft-com:xslt")
dim nodeLevel as string = ""
dim i as integer
for i = 1 to 4
nodeLevel = nodeLevel & "siteMapNode/"
dim xmlString as string = nodeLevel &
"siteMapNode[contains(translate(@title,'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ'),
'" + txtSearchCriteria.Text.ToUpper() + "')]"
'dim xmlString as string =
"siteMapNode/siteMapNode/siteMapNode/siteMapNode[contains(translate(@title,'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ'),
'" + txtSearchCriteria.Text.ToUpper() + "')]"
nodeList=root.SelectNodes(xmlString,nsmgr)
'Change the price on the books.
dim book as XmlNode
for each book in nodeList
Dim tempRow As New TableRow()
Dim tempCell As New TableCell()
tempCell.Text = "<a class='HoverStyle' href=" &
book.Attributes("url").Value & " target='_blank' a>" &
book.Attributes("title").Value & "</a>"
tempRow.Cells.Add(tempCell)
tblSearchResults.Rows.Add(tempRow)
next
next i
It loops four levels of the xml doc. Although I would like to be able
to determone the number of levels without hard-coding. I will have to
research this.
Martin Honnen - 28 Aug 2005 12:34 GMT
> It all works great as long as I specify the level in which to search:
>
[quoted text clipped - 5 lines]
> siteMapNode/siteMapNode
> siteMapNode/siteMapNode/siteMapNode
Then you need the XPath expression
//siteMapNode
to search from the document root node or
.//siteMapNode
to search from the context node.

Signature
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Stephen - 30 Aug 2005 18:27 GMT
Very nice. Worked perfectly. I can get rid of the loop now. Thanks