views:

228

answers:

2

Here is an extract from the XML:

<?xml version="1.0" encoding="utf-8"?>
<usa_map_locator>
    <map_data>
     <state>
      <id>2</id>
      <link/>
     </state>
     <state>
      <id>3</id>
      <link/>
     </state>
    </map_data>
</usa_map_locator>

I need to assign a value to the link node for state 2 (or 3 or 4 or 5 and so on). I am using MICROSOFT.XMLDOM object to read the source XML and need the right method(s) to accomplish this.

+1  A: 

doc.selectSingleNode("/usa_map_locator/map_data/state/id[.='2']::parent()/link").innerText = "link value";

Raj
Doh! I need to learn XPath!
Salman A
`doc.selectSingleNode("/usa_map_locator/map_data/state/id[.='2']/../link").innerText = ""` worked
Salman A
+1  A: 

The accepted answer doesn't work for a number of reasons try this:-

 doc.selectSingleNode("/usa_map_locator/map_data/state[id='2']/link").text = "value"
AnthonyWJones
I managed to get the first answer to work for my needs. Your's is correct too.
Salman A