How to Search by name in xml file

hwatemy

New member
Joined
Jun 4, 2007
Messages
1
Programming Experience
Beginner
I have and xml file related to a weatherpoints program which it saves the wetherpoints cities details in this file and any other information, i just want to make search for specific entries in this file which it's starting from specific word

the problem is the file always starts with <entry name="whatever">somedata</entry>

or it could be <entry name="whatever" \>

and so

any way there is top node of which i am looking for which i want to find it first and count the line number and then start search for the subnodes from the line number i reached coz this line number differ from file to another but the name is constant

the node i search for :

<entry name="weatherPoints_dpStyle">

...subnodes

<\entry>

and this is snap shot for the file coz it's size is too big about 8 mb

any way i want him specifically find the word weatherPoints_dpStyle and then start search as i said



XML Sample



the file starts with the top node <entry> the contents <\entry>

inside the top nodes some nodes unneeded till i reach the desired node which i don't know which line it stills

any way that an example for the xml node from the begining of the node i want to search for

<entry name="weatherPoints_dpStyle">

<entry name="pointsData_newyork">

<entry name="pointsData_newyork_0">

<viz>

<dataobject>

<entry name="WeatherPoints:pointsData_newyork_0">

<entry name="temp">18</entry>

<entry name="wind_dir">180</entry>

<entry name="wind_speed">5</entry>

<entry name="viz_id">NewYork</entry>

<entry name="min">14</entry>

<entry name="max">22</entry>

<entry name="pressure">8</entry>

<\entry>

<\dataobject>

<\viz>

<\entry>

<entry name="pointsData_newyork_1">

<viz>

<dataobject>

<entry name="WeatherPoints:pointsData_newyork_1">

<entry name="temp">17</entry>

<entry name="wind_dir">155</entry>

<entry name="wind_speed">4</entry>

<entry name="viz_id">NewYork</entry>

<entry name="min">16</entry>

<entry name="max">24</entry>

<entry name="pressure">7</entry>

<\entry>

<\dataobject>

<\viz>

<\entry>

<\entry>

<entry name="pointsData_la">

<entry name="pointsData_la_0">

<viz>

<dataobject>

<entry name="WeatherPoints:pointsData_la_0">

<entry name="temp">18</entry>

<entry name="wind_dir">200</entry>

<entry name="wind_speed">5</entry>

<entry name="viz_id">LosAngeles</entry>

<entry name="min">14</entry>

<entry name="max">22</entry>

<entry name="pressure">8</entry>

<\entry>

<\dataobject>

<\viz>

<\entry>

<entry name="pointsData_la_1">

<viz>

<dataobject>

<entry name="WeatherPoints:pointsData_la_1">

<entry name="temp">17</entry>

<entry name="wind_dir">210</entry>

<entry name="wind_speed">5</entry>

<entry name="viz_id">LosAngeles</entry>

<entry name="min">15</entry>

<entry name="max">21</entry>

<entry name="pressure">9</entry>

<\entry>

<\dataobject>

<\viz>

<\entry>

<\entry>

.

.

.

to the end of points

<\entry> -----> closes the node <entry name="weatherPoints_dpStyle">
then some unwanted tags till the file ends

so the data i want to get is <entry name="wind_speed">5</entry>

<entry name="viz_id">LosAngeles</entry>

5 and LosAngeles and so

and i care about the line number coz there is another <entry name="whatever_else">

ok

that's the sample for the file

thanks for advance
 
You question is rather long and I just skimmed through it. If you want to read the Attributes of an element then this is how you do it:

Dim myDoc as New XMLDocument
myDoc.Load("file.xml")
Dim myNode as XMLNode
myNode = myDoc.SelectSingleNode("entry")
if myNode.Attributes("value") = "something" then
'do something
end if

I hope that answers your question.
 
XPath expressions is commonly used to get one or more nodes at a specific level in the node hierarchy, these can be specified with SelectSingleNode and SelectNodes methods, for example mydoc.SelectSingleNode("/entry/entry/entry[@name='wind_speed']")
 

Latest posts

Back
Top