Author |
Topic  |
|
dayve
Forum Moderator
    
USA
5820 Posts |
Posted - 15 May 2007 : 16:27:05
|
I have an XML file which contains these 2 nodes:
<link rel="alternate" type="text/html" href="http://picasaweb.google.com/oatha.org/2006NAHROConferenceAtlantaGeorgia/photo#4989498871769137170" />
<link rel="self" type="application/atom+xml" href="http://picasaweb.google.com/data/entry/api/user/oatha.org/albumid/4989497778618826769/photoid/4989498871769137170" />
Up until recently I was using this to get the value:
strImage = Node.selectSingleNode("link").Attributes.GetNamedItem("href").Text Now my code is picking up the second line instead of the first. How can I make a request for the value of an item with similar and multiple attributes?
|
|
|
dayve
Forum Moderator
    
USA
5820 Posts |
Posted - 17 May 2007 : 22:05:58
|
I hate bumping topics but I would really appreciate if someone could shed some light on this. |
|
 |
|
HuwR
Forum Admin
    
United Kingdom
20595 Posts |
Posted - 18 May 2007 : 04:58:46
|
you would do something like this
'Create the XmlDocument.
Dim doc as XmlDocument = new XmlDocument()
doc.Load("yourfile.xml")
Dim link as XmlNode
Dim nodeList as XmlNodeList
Dim root as XmlNode = doc.DocumentElement
nodeList=root.SelectNodes("link")
'Change the price on the books.
for each link in nodeList
strImage = link.Attributes.GetNamedItem("href").Text
next
or something similar anyway |
 |
|
dayve
Forum Moderator
    
USA
5820 Posts |
Posted - 21 May 2007 : 15:31:24
|
Thanks Huw, but I am pretty much doing exactly what you've pointed out. Unfortunately since both items have attributes named "href" the second sets the value and I need the first one. If there was a way I could identify the attribute "href" and another one, rel="alternate", then I could quickly and easily identify the one I want to use. |
|
 |
|
HuwR
Forum Admin
    
United Kingdom
20595 Posts |
Posted - 21 May 2007 : 15:38:03
|
that is because the loop is simply setting strImage to the href value, but it will get updated on every trip through the loop, so will allways have the value of the last href, to set it at any other value you need to add an escape condition to the for each loop |
 |
|
dayve
Forum Moderator
    
USA
5820 Posts |
Posted - 26 May 2007 : 22:07:23
|
quote: Originally posted by HuwR
that is because the loop is simply setting strImage to the href value, but it will get updated on every trip through the loop, so will allways have the value of the last href, to set it at any other value you need to add an escape condition to the for each loop
That's what I am trying to do. I was hoping to catch the rel or type value to get the correct value I needed from the href. |
|
 |
|
HuwR
Forum Admin
    
United Kingdom
20595 Posts |
Posted - 27 May 2007 : 04:24:26
|
well you should be able to do that fairly easily in the for each loop
'Change the price on the books.
for each link in nodeList
strType = link.Attributes.GetNamedItem("type").Text
if strType = whatyouwant
strImage = link.Attributes.GetNamedItem("href").Text
end if
next
|
 |
|
dayve
Forum Moderator
    
USA
5820 Posts |
Posted - 27 May 2007 : 11:42:06
|
quote: Originally posted by HuwR
well you should be able to do that fairly easily in the for each loop
'Change the price on the books.
for each link in nodeList
strType = link.Attributes.GetNamedItem("type").Text
if strType = whatyouwant
strImage = link.Attributes.GetNamedItem("href").Text
end if
next
I consider myself somewhat of a smart guy, not brilliant, but smart and it amazes me that I continue to overlook some obvious things like this. Thanks. |
|
 |
|
HuwR
Forum Admin
    
United Kingdom
20595 Posts |
Posted - 27 May 2007 : 13:02:09
|
that's ok, it is often the obvious thinks that we miss even when they are staring us in the face  |
 |
|
dayve
Forum Moderator
    
USA
5820 Posts |
Posted - 27 May 2007 : 18:28:56
|
I should have thought of this earlier as well... just used the node index for the item I wanted and it worked as well:
strImage = Node.childNodes(8).Attributes.GetNamedItem("href").text |
|
 |
|
|
Topic  |
|