hasXML <- require(XML)
hasxml2 <- require(xml2)
if (!hasXML && !hasxml2)
return() # can't demo without XML or xml2 packages present
parseFn <- if (hasXML) xmlParse else read_xml
# Demo for working with the XML package (if present, otherwise xml2)
exdoc <- parseFn('')
querySelector(exdoc, "#anid") # Returns the matching node
querySelector(exdoc, ".aclass") # Returns the matching node
querySelector(exdoc, "b, c") # First match from grouped selection
querySelectorAll(exdoc, "b, c") # Grouped selection
querySelectorAll(exdoc, "b") # A list of length one
querySelector(exdoc, "d") # No match
querySelectorAll(exdoc, "d") # No match
# Read in a document where two namespaces are being set:
# SVG and MathML
svgdoc <- parseFn(system.file("demos/svg-mathml.svg",
package = "selectr"))
# Search for Run the code above in your browser using DataLab