473,659 Members | 3,553 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

traverse xml document nodes - SelectNodes()

I have the following code that uses xquery to return search results
from an xml doc.

dim xmlString as string

xmlString =
"siteMapNod e/siteMapNode/siteMapNode/siteMapNode[contains(transl ate(@title,'abc defghijklmnopqr stuvwxyz','ABCD EFGHIJKLMNOPQRS TUVWXYZ'),
'" + txtSearchCriter ia.Text.ToUpper () + "')]"
nodeList=root.S electNodes(xmlS tring,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(transl ate(@title,'abc defghijklmnopqr stuvwxyz','ABCD EFGHIJKLMNOPQRS TUVWXYZ'),
'" + txtSearchCriter ia.Text.ToUpper () + "')]"
nodeList=root.S electNodes(xmlS tring,nsmgr)

anyway, that is air code but hopefully you'll get my point. Any help
is appreciated.

Nov 12 '05 #1
3 6509
I did figure something out. Here is what I did:

dim doc as XmlDocument = new XmlDocument()
doc.Load(Server .MapPath("web.s itemap"))

dim nodeList as XmlNodeList
dim root as XmlNode = doc.DocumentEle ment

dim nsmgr as XmlNamespaceMan ager = new
XmlNamespaceMan ager(doc.NameTa ble)
nsmgr.AddNamesp ace("ns0",
"xmlns:ns0='urn :schemas-microsoft-com:xslt")

dim nodeLevel as string = ""
dim i as integer
for i = 1 to 4
nodeLevel = nodeLevel & "siteMapNod e/"
dim xmlString as string = nodeLevel &
"siteMapNod e[contains(transl ate(@title,'abc defghijklmnopqr stuvwxyz','ABCD EFGHIJKLMNOPQRS TUVWXYZ'),
'" + txtSearchCriter ia.Text.ToUpper () + "')]"
'dim xmlString as string =
"siteMapNod e/siteMapNode/siteMapNode/siteMapNode[contains(transl ate(@title,'abc defghijklmnopqr stuvwxyz','ABCD EFGHIJKLMNOPQRS TUVWXYZ'),
'" + txtSearchCriter ia.Text.ToUpper () + "')]"
nodeList=root.S electNodes(xmlS tring,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='HoverSty le' href=" &
book.Attributes ("url").Valu e & " target='_blank' a>" &
book.Attributes ("title").Va lue & "</a>"
tempRow.Cells.A dd(tempCell)
tblSearchResult s.Rows.Add(temp Row)
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.

Nov 12 '05 #2


Stephen wrote:

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


Then you need the XPath expression
//siteMapNode
to search from the document root node or
.//siteMapNode
to search from the context node.
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Nov 12 '05 #3
Very nice. Worked perfectly. I can get rid of the loop now. Thanks

Nov 12 '05 #4

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

Similar topics

1
2612
by: Andy Fish | last post by:
Hi, I'm using XML DOM in Java and I have a function like this Element makeSomeXml(Document doc) {..} This returns an Element owned by (but not appended to) the specified document. Now, when I call this function, sometimes I want to append the result
1
1618
by: james.kingston | last post by:
In my first experimentation with js, I'm writing a greasemonkey script which adds links to a page which, when clicked, will replace their parent element with the contents of an element from another URL. in the following function, pageHTML contains the entire text of an HTML page, pulled in via GM_xmlhttprequest. The page contains a ul with id="commentlisting". What I want to do, but can't seem to do, is turn that lump of html in the...
1
46126
by: Praveen Naregal | last post by:
hello all, I have a problem. I have an XML file like below one.I want to loop through node by node and store or display the data . Can anybody give me a sample piece of c# code? Thanks & Regards, Praveen
8
6438
by: e-mid | last post by:
i want to get childs of specific xml node. normally i use xmlNodeList fooList = myNode.SelectNodes("foo"); but in compactframework , there is no selectNodes() method or selectSingleNode() method. what else can i use instead?
6
8388
by: J Williams | last post by:
I'm using axWebBrowser control and HTML DOM in a VB .NET Windows application to create a new HTML document by cloning nodes. The function below is called from the axWebBrowser1_DocumentComplete event using: Dim mNewDoc As mshtml.IHTMLDocument3 mNewDoc = NewDoc(axWebBrowser1.Document) Private Function NewDoc(ByVal mInputDoc As mshtml.IHTMLDocument3) As mshtml.IHTMLDocument3
3
9945
by: sfeher | last post by:
Hi All, The following code returns a valid xmlDoc (since I can evaluate and selectNodes) but its value is "xmlDoc= null" ?! Or at least this is what the FireBug shows and (xmlDoc===null) is true. var parser = new DOMParser(); var xmlDoc = parser.parseFromString( responseText, "text/xml"); // at this point: xmlDoc= null
1
2323
by: Daniel Rucareanu | last post by:
Hello, Does anybody knows how can you delete, in just one step, not using a loop, a subset of the child nodes of a given DOM parent node? The subset will be continous, so for example, if the parent node has 100 nodes, I want to delete nodes 10 through 75, and not nodes 5, 10, 25 etc. I have a reference to the first and the last node in the list that has to be removed. Also it's position in the list, if that helps.
14
2011
by: drdeath89 | last post by:
Im writing some Javascript code that requires me to loop all child nodes and sub child nodes of a certain parent node and execute a function with the child node in question. I decided to write a recursive function with said functionality, with a node and a function as parameters, but it simply wont work. My problem is that whenever i pass a node to this function parameter it is always, regardless of what i change, equal to null. I even...
6
4076
by: Premal Mishra | last post by:
How to traverse a binary tree whose nodes only contain a father field. e.g. struct NodeType { int data; int father; }; A left son's father field has a negative value and right son's father field has +ve value. Absolute value of the father field points to the father of the node. Such tree can be traversed only in an upward direction but i cannot reach all nodes starting at a leaf. Once all nodes reachable from a leaf are traversed, i...
0
8428
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
8748
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
8531
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,...
0
8628
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7359
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6181
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
4175
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
4335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1739
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.