Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP (Non-Forum Related)
 Reading XML Nodes with multiple attributes
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

dayve
Forum Moderator

USA
5820 Posts

Posted - 15 May 2007 :  16:27:05  Show Profile  Visit dayve's Homepage
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  Show Profile  Visit dayve's Homepage
I hate bumping topics but I would really appreciate if someone could shed some light on this.

Go to Top of Page

HuwR
Forum Admin

United Kingdom
20595 Posts

Posted - 18 May 2007 :  04:58:46  Show Profile  Visit HuwR's Homepage
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
Go to Top of Page

dayve
Forum Moderator

USA
5820 Posts

Posted - 21 May 2007 :  15:31:24  Show Profile  Visit dayve's Homepage
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.

Go to Top of Page

HuwR
Forum Admin

United Kingdom
20595 Posts

Posted - 21 May 2007 :  15:38:03  Show Profile  Visit HuwR's Homepage
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
Go to Top of Page

dayve
Forum Moderator

USA
5820 Posts

Posted - 26 May 2007 :  22:07:23  Show Profile  Visit dayve's Homepage
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.

Go to Top of Page

HuwR
Forum Admin

United Kingdom
20595 Posts

Posted - 27 May 2007 :  04:24:26  Show Profile  Visit HuwR's Homepage
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 

Go to Top of Page

dayve
Forum Moderator

USA
5820 Posts

Posted - 27 May 2007 :  11:42:06  Show Profile  Visit dayve's Homepage
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.

Go to Top of Page

HuwR
Forum Admin

United Kingdom
20595 Posts

Posted - 27 May 2007 :  13:02:09  Show Profile  Visit HuwR's Homepage
that's ok, it is often the obvious thinks that we miss even when they are staring us in the face
Go to Top of Page

dayve
Forum Moderator

USA
5820 Posts

Posted - 27 May 2007 :  18:28:56  Show Profile  Visit dayve's Homepage
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

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.3 seconds. Powered By: Snitz Forums 2000 Version 3.4.07