Look up an element via the XML catalog mechanism
catalogResolve.RdXML parsers use a catalog to map generic system and public addresses
to actual local files or potentially different remote files.
We can use a catalog to map a reference such as
https://www.omegahat.net/XSL/ to a particular
directory on our local machine and then not have to
modify any of the documents if we move the local files to another
directory, e.g. install a new version in an alternate directory.
This function provides a mechanism to query the catalog to resolve a URI, PUBLIC or SYSTEM identifier.
This is now vectorized, so accepts a character vector of
URIs and recycles type to have the same length.
If an entry is not resolved via the catalog system,
a NA is returned for that element.
To leave the value unaltered in this case, use asIs = TRUE .
Arguments
- id
the name of the (generic) element to be resolved
- type
a string, specifying whether the lookup is for a uri, system or public element
- asIs
a logical. If
TRUEany element ofidwhich is not resolved by the catalog system will be left as given in the call. IfFALSE, such unresolved elements are identified byNA.- debug
logical value indicating whether to turn on debugging output written to the console (
TRUE) or not (FALSE).
Value
A character vector. If the element was resolved, the single element is the resolved value. Otherwise, the character vector will contain no elements.
Examples
if(!exists("Sys.setenv")) Sys.setenv = Sys.putenv
Sys.setenv("XML_CATALOG_FILES" = system.file("exampleData", "catalog.xml", package = "XML"))
catalogResolve("-//OASIS//DTD DocBook XML V4.4//EN", "public")
#> [1] "file:///usr/share/xml/docbook44/docbookx.dtd"
catalogResolve("https://www.omegahat.net/XSL/foo.xsl")
#> [1] NA
catalogResolve("https://www.omegahat.net/XSL/article.xsl", "uri")
#> [1] NA
catalogResolve("https://www.omegahat.net/XSL/math.xsl", "uri")
#> [1] NA
# This one does not resolve anything, returning an empty value.
catalogResolve("http://www.oasis-open.org/docbook/xml/4.1.2/foo.xsl", "uri")
#> [1] NA
# Vectorized and returns NA for the first and /tmp/html.xsl
# for the second.
catalogAdd("http://made.up.domain", "/tmp")
#> [1] TRUE
catalogResolve(c("ddas", "http://made.up.domain/html.xsl"), asIs = TRUE)
#> [1] "ddas" "/tmp/html.xsl"