Re: [R] Treatment of xml-stylesheet processing instructions in XML module

From: Duncan Temple Lang <duncan_at_wald.ucdavis.edu>
Date: Wed, 06 Apr 2011 16:06:19 -0700

Hi Adam

To use XPath and getNodeSet on an XML document, you will want to use xmlParse() and not xmlTreeParse() to parse the XML content. So

t = xmlParse(I(a)) # or asText = TRUE
elem = getNodeSet(t, "/rss/channel/item")[[1]]

works fine.

You don't need to specify the root node, but rather the document in getNodeSet.

Also, if you have the package loaded, you don't need the XML:: prefix before the function names.

  HTH
    D.

On 4/6/11 11:32 AM, Adam Cooper wrote:
> Hello again,
> Another stumble here that is defeating me.
>
> I try:
> a<-readLines(url("http://feeds.feedburner.com/grokin"))
> t<-XML::xmlTreeParse(a, ignoreBlanks=TRUE, replaceEntities=FALSE,
> asText=TRUE)
> elem<- XML::getNodeSet(XML::xmlRoot(t),"/rss/channel/item")[[1]]
>
> And I get:
> Start tag expected, '<' not found
> Error: 1: Start tag expected, '<' not found
>
> When I modify the second line in "a" to remove the following (just
> leaving the <rss> tag with its attributes), I do not get the error.
> I removed:
> <?xml-stylesheet type=\"text/xsl\" media=\"screen\" href=
> \"/~d/styles/rss2full.xsl\"?><?xml-stylesheet type=\"text/css\" media=
> \"screen\" href=\"http://feeds.feedburner.com/~d/styles/itemcontent.css
> \"?>
>
> I would have expected the PI to be totally ignored by default.
> Have I missed something??
>
> Thanks in advance...
>
> Cheers, Adam
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Wed 06 Apr 2011 - 23:08:39 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 07 Apr 2011 - 00:10:27 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive