Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

attributes by name instead of index

Status
Not open for further replies.

skiflyer

Programmer
Sep 24, 2002
2,213
US
I'm using MSXML3.0 for VB...

I have an XML of this sort...

<root>
<product>
<name>blah</name>
<instance id=&quot;1&quot; active=&quot;true&quot;>
...
...
</instance>
<instance id=&quot;2&quot; active=&quot;false&quot;>
...
</instance>
</product>
<product>
...
...
</product>
</root>

And I'm fine getting into the right product, but once there I'd like to find the instance with the highest id where the active=&quot;true&quot;...

As it stands, I'm looping through the attributes and if their NodeName = &quot;id&quot; then I read it, and such.

My problem is that to do this I make a call to

node.Item(x).Attributes(0).nodeName
and then
node.Item(x).Attributes(0).text

and so on.... what worries me is the 0... I don't like having to worry about the order of my attributes and the fact that stuff is 0 indexed etc... I know I could loop through the whole list of attributes first (which is where I'm headed)... but this seems silly innacurate... what I'm hoping for is something like...

id = node.Item(x).Attributes(&quot;id&quot;).text

Is there anyway to do this?

Thanks,
Rob
 
um why don't you get a node list using an xpath query (//product/instance[@active='true']) and then just iterate the list and keep the largest id?

-pete
 
cause I don't know how!

Going to look into this now, but if you have some information for me that'd be great.

-Rob
 
um you mean you don't know XPath?

If so u need to, that's what u use to do programatic DOM development. It's SQL to databases... try doing DB development without SQL.

Anyway ur using MSXML right? once u look at XPath statments then u use Node.selectNodes() and Node.selectSingleNode() to run an XPath query.

u should find XML developement much simpler in the future.

-pete

 
LOL

What've I'm been doing yesterday afternoon... this xpath stuff is so much easier.... thanks for the prod in the right direction, figuring things out nicely now. (scary I had it working before, just seemed to fragile for my liking... now that's no longer a worry)

-Rob

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top