Register Advertise with usHelp Desk Today's Posts Search

Closed Thread
Thread Tools Search this Thread
Unread 15th Jul 2015, 08:47 AM   #1
Senior Warrior Member
War Room Member
 
Join Date: 2006
Location: Mars
Posts: 1,133
Thanks: 152
Thanked 310 Times in 223 Posts
Blog Entries: 2
Default
Javascript Help
Share on: 
fb share twitter share gplus share more share

I get tryng to work this code. First I would like to add all items within "Feature" tags. Each time I run it , I only get the last item "TriZone". How can get all items and add a line break ?

Top Part shows the output I am getting from Amazon and second part shows the function I am using to get the information.

Code:
<Feature>Rechargeable </Feature>
<Feature>Dynamic </Feature>
<Feature>manual</Feature>
<Feature>TriZone</Feature>


*****************
function getinfo(){
 
  var o = {};
  var a = response.getDescendants();
  
  for(var i=0;i<a.length;i++) {
 
    if(a[i].getType() == XmlService.ContentTypes.ELEMENT){
      switch(a[i].asElement().getName()){
        case "Feature" :
          o.feature = a[i].asElement().getText();
}
}
}

I am also trying to get "URL" value from this but no luck. How can I get URL element?

Code:
<SmallImage>
<URL>http://ecx.images-amazon.com/images/I/313lIweldTL._SL75_.jpg</URL>
<Height Units="pixels">75</Height>
<Width Units="pixels">41</Width>
</SmallImage>

<MediumImage>
<URL>http://ecx.images-amazon.com/images/I/313lIweldTL._SL160_.jpg</URL>
<Height Units="pixels">160</Height>
<Width Units="pixels">87</Width>
</MediumImage>

***********************

function getinfo(){
 
  var o = {};
  var a = response.getDescendants();
  
  for(var i=0;i<a.length;i++) {
 
    if(a[i].getType() == XmlService.ContentTypes.ELEMENT){
      switch(a[i].asElement().getName()){

case "SmallImage" :
          o.smallimage = a[i].asElement().getText();
}
}
}
I am hoping that someone can easily find the solution to this.

Thanks
blackjack is offline  
Unread 15th Jul 2015, 02:58 PM   #2
HyperActive Warrior
War Room Member
 
Join Date: 2009
Posts: 156
Thanks: 1
Thanked 11 Times in 10 Posts
Default
Re: Javascript Help
Share on: 
fb share twitter share gplus share more share

Just a quick guess try changing "for(var i=0;i<a.length;i++) {" to " for(i in a) {". No guarantee it will work. You need to find out exactly what "response.getDescendants(); " is returning.

kdavies is offline  
Closed Thread


Bookmarks

Tags
hhojavascript, javascript


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -6. The time now is 02:40 PM.