Create Character Vectors from an XML File or String

DESCRIPTION:

This function parses an XML file or and S-PLUS string following the specified XML paths and creating appropriate character vectors.

USAGE:

parseXMLPath(parse, path, isFile, default=character(0), delimiters=character(0), 
        separateDelimiters=F)

REQUIRED ARGUMENTS:

parse
a character string containing the name of the XML file to parse or an XML encoded object.
path
a vector or list of character strings containing one or more XML paths.
isFile
a logical value. If TRUE, the argument parse is the name of a file containing the XML representation of an S-PLUS object. Otherwise, parse is the XML representation of an object.

OPTIONAL ARGUMENTS:

default
a character string providing a default return value for invalid paths.
delimiters
a character string specifying the delimiter to use when parsing.
separateDelimiters
a logical value. If T, successive delimiters will create an empty value.

VALUE:

a named list of character vectors with one list element for each string in the argument path, where the names of the list elements are the path strings. Each list element contain the parsed strings corresponding to a XML path string.

REFERENCES:

http://www.w3.org/XML

SEE ALSO:

, , , , , .

EXAMPLES:

# Create an XML file for an S-PLUS matrix and parse with an XML path
xmlfile <- file.path(path.expand("~"), "statex91.xml")
createXMLFile(state.x91, xmlfile)
parseXMLPath(xmlfile, isFile=T, "S-PLUS/Matrix/RowNames/Items/Item/text()")

# Create an XML string for an S-PLUS matrix and parse with an XML path
xmls <- createXMLString(state.x91)
parseXMLPath(xmls, isFile = F,
        "S-PLUS/Matrix/Columns/Column[@name = 'Population']/Items/Item/text()")