[R] using XML package to read RSS

J Toll jctoll at gmail.com
Thu May 17 04:26:40 CEST 2012


On Wed, May 16, 2012 at 9:02 PM, Duncan Temple Lang
<duncan at wald.ucdavis.edu> wrote:
> Hi James.
>
>  Yes, you need to identify the namespace in the query, e.g.
>
>  getNodeSet(doc, "//x:entry", c(x = "http://www.w3.org/2005/Atom"))
>
> This yeilds 40 matching nodes.
>
> (getNodeSet() is more convenient to use when you don't specify a function
> to apply to the nodes. Also, you don't need xmlRoot(doc), as it works on the
> entire document with the query "//...".)
>
>  BTW, you want to use xmlParse() and not xmlTreeParse().
>
>   D.


Brilliant!  Thank you so much.  I never would have figure out
specifying the namespace like that.  I had tried:

src <- xpathApply(xmlRoot(doc), "//entry", namespaces =
"http://www.w3.org/2005/Atom")

but that wasn't working.

Thanks again,


James



More information about the R-help mailing list