473,700 Members | 2,601 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Traverse XML Document

I need a routine to search an entire XML document (all nodes) for a specified string & return the count (or return an arraylist of references to the nodes. I've tried various combinations of the code below, but somehow not all children or siblings are checked. I'm lost.

--Billg S

Public Function CountNodeValue( ByRef pNode As Xml.XmlNode, ByVal sValue As String) As Intege
Dim iCount As Intege

'Check siblings & childre
While Not pNode.FirstChil d Is Nothing AndAlso Microsoft.Visua lBasic.Left(pNo de.FirstChild.N ame, 1) <> "#
iCount = iCount + CountNodeValue( pNode.FirstChil d, sValue
End Whil

While Not pNode.NextSibli ng Is Nothing AndAlso Microsoft.Visua lBasic.Left(pNo de.NextSibling. Name, 1) <> "#
iCount = iCount + CountNodeValue( pNode.NextSibli ng, sValue
End Whil

If UCase(Trim(pNod e.Name)) = UCase(Trim(sVal ue)) The
iCount = iCount +
Els
' retrieve node.attributes for compariso
If Not pNode.Attribute s Is Nothing The
For Each oItem In pNode.Attribute
If UCase(Trim(oIte m.Name)) = UCase(Trim(sVal ue)) The
Debug.WriteLine ("Match Found: " & sValue & "' = " & oItem.Name
iCount = iCount +
End I
Nex
End I
End I

Return iCoun
End Functio

Nov 22 '05 #1
1 1568
I would recommend using XPath for something like this - with the SelectNodes() method on System.Xml.XmlN ode
You will have MUCH less code to write (and maintain)

If XPath is new to you just search MSDN or Google for info

There are some good examples of xpath expressions here
http://msdn.microsoft.com/library/de...athexamples.as

Nov 22 '05 #2

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

Similar topics

1
3772
by: Murtaza Tinwala | last post by:
Hello friends, I have a XML document and I want to modify some of its nodes. What I need to do is traverse through all the nodes and test the name of each. If the node is to be modified, I would output the modified code or I would output the same code. Is there any way I can get all nodes from the root node? Or, let me put this question in another way. Is there an easy way to modify XML document. Say, I want to make minor changes...
1
414
by: Billg_sd | last post by:
I need a routine to search an entire XML document (all nodes) for a specified string & return the count (or return an arraylist of references to the nodes. I've tried various combinations of the code below, but somehow not all children or siblings are checked. I'm lost. --Billg S Public Function CountNodeValue(ByRef pNode As Xml.XmlNode, ByVal sValue As String) As Intege Dim iCount As Intege 'Check siblings & childre While Not...
1
5689
by: Raed Sawalha | last post by:
I have a TreeView with 4 levels I need to implement Next and Back capability , my problem in how to traverse the tree to achieve this task.
2
3190
by: john | last post by:
I posted this question to comp.lang.javascript but didn't get a response, so I'll try here. I am using ASP.NET and I have a datagrid. One of the columns in my grid is all checkboxes. When the user clicks on a certain button on the page, which is not in the grid, I want to be able to traverse through all the checkboxes in that column and see how many are checked. This is so that I can give them a confirmation dialog before I do an action...
0
1827
by: Subba Rao via DotNetMonster.com | last post by:
---------------------------HTML---------------------------------------- <html> <head> <title>:: DHTML Table Demo ::</title> <script langauge="javascript" src="InterchangeRows.js"></script> <style> .mainTable { background-color: black; color: white; font-face: tahoma;
4
5541
by: shinya | last post by:
Hi there! I'm trying to figure out how to traverse an xml hierarchy from within javascript. Here's my text.xml file: <?xml version="1.0" encoding="ISO-8859-1"?> <main> <text1>this is a text</text1> <text2>this is another one</text2> <text3>and this is the last</text3>
3
7204
by: visor7 | last post by:
Hi, i've been trying to investigate how to traverse through an object instance properties or fields with no success. I have read about IEnumerable interface but that seems to apply only to collection of objects. What i want to do actually is to traverse through each property of an instance and if possible, assign a null value... something like this: MyClass instance = new MyClass(); instance.property1 = "A string";
1
1595
by: Rotsey | last post by:
Hi, As the subject says I have an application that uses xml at the client to render custom tables to get a drill down effect. So I query my database and create a xml document of it. I then want to pass the xml to the client and have javascript manipulate it. So far I have it working by calling a XMLHttp request by passing the URL
1
2057
by: SonOfGrey | last post by:
Hi! I'm looking for a way to traverse all the controls on a dialog in the order of the tabstop index. Note that I use unmanaged C++, so no GetTabIndex function afaik. The ALMOST perfect function for this looks like: CWnd::GetNextDlgTabItem. BUT...this function skips controls that are disabled (WS_DISABLED),
2
3800
by: rvimalram | last post by:
Hi all, I have a created a multidimesional array,what i need is to traverse that array and return the value of the array in the particular page the array is $one=array("one" =>"Text1"); $two=array( "two" =>array( "a" =>array( "b" =>"Text2"
0
8712
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
9058
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...
0
8911
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
7794
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
6555
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
5895
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4395
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
4649
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3082
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.