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.

Time Travel
  • 1,404
  • 2
  • 10
  • 11
  • possible duplicate of [Parsing XML with default namespace using xPath in javascript](http://stackoverflow.com/questions/6761517/parsing-xml-with-default-namespace-using-xpath-in-javascript) – Martijn Mar 26 '13 at 21:57
  • updated about namespace resolver. – Time Travel Mar 26 '13 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! – Martijn Mar 26 '13 at 22:08

0 Answers0