Learn R Programming

RTest (version 1.2.6)

xmlRead.default: General import function to reads XML data of different types

Description

This function controls the import of input data set.

Usage

xmlRead.default(xmlItem)

Arguments

xmlItem

(XMLNode) Object of class XMLNode that defines the a list object and fullfills XSD definition 'xmlReadData_list'.

Value

(data.frame) or (variable) or (vector) or a named list of all imported input datasets.

Details

Based on the tag name of the input data definition in the XML file, the corresponding readXMLData_* function is called, whereby * is a placeholder for the data type definition in the XML scheme. For example, for XML definitions following the data.frame specification, a function readXMLData_data.frame <- function(xmlDataItem) is expected, which implements the XML parser for data.frames and returns the data as R object.

See Also

XMLNode-class

Examples

Run this code
# NOT RUN {
data <- '<text type="character">My text is awesome</text>'
item <- XML::xmlRoot(XML::xmlParse(data,asText=TRUE))
value <- RTest::xmlRead.default(item)
stopifnot(value=="My text is awesome")

data <- '<list><data.frame><col-defs>
<coldef name="Column1" type="character"/>
<coldef name="Column2" type="numeric"/>
</col-defs>
<row name="1"><cell>ID1</cell><cell>1</cell></row>
<row name="2"><cell>ID2</cell><cell>2.1</cell></row>
<row name="3"><cell>ID3</cell><cell>3.1</cell></row>
</data.frame></list>'
item <- XML::xmlRoot(XML::xmlParse(data,asText=TRUE))
value <- RTest::xmlRead.default(item)
stopifnot(dim(value)[1]==3)
stopifnot(dim(value)[2]==2)

data <- '<variable type="character" value="My text is awesome"/>'
item <- XML::xmlRoot(XML::xmlParse(data,asText=TRUE))
value <- RTest::xmlRead.default(item)
stopifnot(value=="My text is awesome")
# }

Run the code above in your browser using DataLab