R Language
Approach is based on a XML Schema.
R XMLSchema from Duncan Temple Lang.
A package that reads XML schema into an R representation and can perform some operations on the resulting information to generate class definitions and code to read documents using this schema.
The R representation uses S4 classes.
Usage of readSchema
Installation of XMLSchema in R
1install.packages("remotes")
2remotes::install_github("omegahat/XMLSchema")
3install.packages("sloop")
Test Run
An internal representation of the XML schema is created as S4 classes.
1options(echo=TRUE)
2
3library(sloop)
4library(XML)
5library(XMLSchema)
6
7args <- commandArgs(TRUE)
8print(args[1])
9
10print('--------------------------------------------------')
11cdi = readSchema(args[1], createConverters = TRUE, verbose = TRUE)
12# cdi = readSchema("E:/Git/ddi-cdi/build/encoding/xml-schema/ddi-cdi.xsd", createConverters = TRUE)
13
14print('--------------------------------------------------')
15is(cdi)
16
17print('--------------------------------------------------')
18otype(cdi)
19
20print('--------------------------------------------------')
21class(cdi)
22
23print('--------------------------------------------------')
24names(cdi)
25
26print('--------------------------------------------------')
27sapply(cdi, length)
28
29print('--------------------------------------------------')
30sapply(cdi, class)
31
32print('--------------------------------------------------')
33sapply(cdi, names)
34
35print('--------------------------------------------------')
36showMethods( classes=class(cdi) )
37
38print('--------------------------------------------------')
39print(cdi)
40
41print('--------------------------------------------------')
42saveRDS(cdi, 'cdi.rds')
43rm(cdi)
44exists("cdi")
45cdi <- readRDS('cdi.rds')
46otype(cdi)
47class(cdi)
48names(cdi)
49
50# serialize S4 classes, not sure if this is right
51sink("cdi.R")
52sapply(cdi, expandS4)
53sink()
Documentation of XMLSchema
In R:
help(package="XMLSchema")
Once a local web server has been started, the documentation is displayed in the web browser.