1

I want to parse an atom feed using javascript xpath API:

<feed xmlns="http://www.w3.org/2005/Atom">
   <category scheme="http://app.link.com/schemes" type="types"/>
   <link rel="app" href="http://app.link.com"/>
  <entry>
   <link rel="appnn" href="http://app.link.internal"/>
  </entry>  
</feed>

I tried to get the link(s) attributes using the javascript xPath API. This is what I have tried:

 var urlvar = '/feed/link/@href';
 var feed = xDoc.evaluate(urlvar, xDoc, null,XPathResult.STRING_TYPE, null);

But the result is null for

feed.stringValue What I am doing wrong?

Update:

I tried

function feedNSResolver(prefix) {
  return "http://www.w3.org/2005/Atom";
 }

without any luck.

3
  • possible duplicate of Parsing XML with default namespace using xPath in javascript Commented Mar 26, 2013 at 21:57
  • updated about namespace resolver. Commented Mar 26, 2013 at 22:04
  • 1
    You might need to use a prefix in your XPath query. Any prefix should do, since your function will resolve all prefixes to the same namespace. Also: don't forget to pass your resolver function to the evaluate call! Commented Mar 26, 2013 at 22:08

0

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.