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>
3
  • 1
    have a look here stackoverflow.com/questions/9496427/… Commented Jun 7, 2013 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. Commented Jun 7, 2013 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. Commented Jun 7, 2013 at 14:50

1 Answer 1

3

Try using query selectors:

document.querySelector('link[rel="edit"]');
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot; but the weird thing is the href i am getting

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.