1 replies
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
#hhojavascript #javascript
  • Profile picture of the author kdavies
    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.
    {{ DiscussionBoard.errors[10170290].message }}

Trending Topics