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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to set attributes / add children with duplicate node names

Status
Not open for further replies.

mnolting

Programmer
Oct 6, 2008
26
US
I need to add children and set the attribute for a node where it is the second instance in a family of nodes.
But I cant seem to find a way to "SelectSingleNode" so that I can add children and set attributes.
This is what I have created so far:

<Markers ObjectID="22" ClassID="bee50706-b524-416c-9f03-b596ce5f6866" Version="2">
<Markers Version="1" ObjectRef="24">
<Marker Version="1" Index="0">
<Second ObjectRef="23"/>
<First>5009872344</First>
</Marker>
<Marker/>
</Markers>
<Node Version="1"/>
</Markers>

=========================================================
I cant get any further because I cant set the attribute of the second instance of the node "Marker". Everything I try sets the first instance of "Marker" and replaces what it already has.

This is what I need to end up with:

<Markers ObjectID="22" ClassID="bee50706-b524-416c-9f03-b596ce5f6866" Version="2">
<Markers Version="1">
<Marker Version="1" Index="0">
<Second ObjectRef="23"/>
<First>5009119315200</First>
</Marker>
<Marker Version="1" Index="1">
<Second ObjectRef="24"/>
<First>419274305049600</First>
</Marker>
</Markers>
<Node Version="1"/>
</Markers>

A nodelist of "//Markers[@ObjectID='22'/Markers/Marker) produces 2 items in the list.
I am trying to figure out how to reference a single node from this list but I just cant figure out how.

Is there a way to identify a node that has no attributes???
Thanks for your help
 
It looks like an MSXML DOM question and not a VB6 question.

An MSXML NodeList is pretty well documented, see IXMLDOMNodeList Members. There are few VB6 examples but the VBScript examples (while shabby) should be correct even if not always of high quality.

If this is indeed VB6 then I'd have thought the IDE's Object Browser would have provided 98% of what you need to understand to use one anyway. Possibly leaving you to guess or experiment whether you have 0-based or 1-based item indexes in MSXML if you didn't know from prior experience.


Short answer: Use the .item() method and pass it a 0-based index, or iterate from 0 to .length - 1 if you want to visit each Node in the NodeList.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top