0

I want to get the href value of the link that has rel='edit', i am wondering how i can do it.

<link rel='self' type='application/atom+xml' href='https://spreadsheets.google.com/feeds/****'/>
<link rel='edit' type='application/atom+xml' href='https://spreadsheets.google.com/feeds/****'/>

I am trying

this.url = entry.getElementsByTagName('link')[1].getAttribute('href');

but i get href of the first link.

thanks.

EDIT :

now what i don't understand is thateven when i am sure i get the right link, the href value is not what i expect

<link rel='self' type='application/atom+xml' href='https://spreadsheets.google.com/feeds/list/**********/full/ba0fz'/>
<link rel='edit' type='application/atom+xml' href='https://spreadsheets.google.com/feeds/list/**********/full/ba0fz/27mpei328jki4e'/>

what i want is to do a regex on the href i want to get the "27mpei328jki4e" but instead of getting the full url, i get the short one, do you have any idea of why i get this result? no matter what method i use, neither the queryselector nor getElementsByTagName.

my document is an xml

<?xml version='1.0' encoding='UTF-8'?>
 <entry xmlns='http://www.w3.org/2005/Atom'    xmlns:gsx='http://schemas.google.com/spreadsheets/2006/extended'>
 <id>************</id>
 <updated>2013-06-06T17:38:25.749Z</updated>
 <category scheme='http://schemas.google.com/spreadsheets/2006' term='http://schemas.google.com/spreadsheets/2006#list'/>
 <title type='text'>30/05/2013 17:12:42</title><content type='text'>
 timeprocess: 01/01/1900, useroid: ICCOM-00000327, 
 </content>
 <link rel='self' type='application/atom+xml' href='https://spreadsheets.google.com/**********/full/ba0fz'/>
 <link rel='edit' type='application/atom+xml' href='https://spreadsheets.google.com/**********/full/ba0fz/27mpei328jki4e'/>
 <gsx:time>30/05/2013 17:12:42</gsx:time>
 <gsx:timeprocess>01/01/1900</gsx:timeprocess>
 <gsx:useroid>ICCOM-00000327</gsx:useroid>
 </entry>
MNS
  • 395
  • 1
  • 4
  • 16
  • 1
    have a look here http://stackoverflow.com/questions/9496427/how-to-get-elements-by-attribute-selector-w-native-javascript-w-o-queryselector – BeNdErR Jun 07 '13 at 14:47
  • 1
    When you call `getElementsByTagName`, take a look at all of the elements in it - compare that to what's in your HTML - there's a difference somewhere, so it will help once you know what that difference is. – Joe Enos Jun 07 '13 at 14:49
  • 2
    That code above works you need to verify that those are the only 2 link's on the page before assuming that index 1 is the one you want. You might give them another arbitrary attribute then loop through the node list that `getElementsByTagName` returns until you find the one that has the href you want. – scrappedcola Jun 07 '13 at 14:50

1 Answers1

3

Try using query selectors:

document.querySelector('link[rel="edit"]');
Julian H. Lam
  • 25,501
  • 13
  • 46
  • 73