tm (version 0.5-10)

XMLSource: XML Source

Description

Constructs a source for an XML file.

Usage

XMLSource(x, parser, reader, encoding = "unknown")

Arguments

x
a file name or a connection.
parser
a function accepting an XML tree (as delivered by xmlTreeParse in package XML) as input and returning a list of XML elements.
reader
a function capable of turning XML elements as returned by parser into a subclass of TextDocument.
encoding
encoding to be assumed for input strings. It is used to mark character strings as known to be in Latin-1 or UTF-8: it is not used to re-encode the input.

Value

  • An object of class XMLSource which extends the class Source representing an XML file.

See Also

Vignette 'Extensions: How to Handle Custom File Formats', readXML; Encoding

Examples

Run this code
## An implementation for readGmane is provided as an example in ?readXML
example(readXML)

## Construct a source for a Gmane mailing list RSS feed.
GmaneSource <-
function(x, encoding = "unknown")
  XMLSource(x, function(tree)
               XML::xmlChildren(XML::xmlRoot(tree))
                 [names(XML::xmlChildren(XML::xmlRoot(tree))) == "item"],
            readGmane, encoding)

gs <- GmaneSource("http://rss.gmane.org/gmane.comp.lang.r.general")
elem <- getElem(stepNext(gs))
(gmane <- readGmane(elem, language = "en", id = "id1"))
meta(gmane)

Run the code above in your browser using DataLab