Learn R Programming

XML (version 0.7-1)

xmlTree: An internal, updatable DOM object for building XML trees

Description

This is a mutable object (implemented via a closure) for representing an XML tree, in the same spirit as xmlOutputBuffer and xmlOutputDOM but that uses the internal structures of libxml. This can be used to create a DOM that can be constructed in R and exported to another system such as XSLT (http://www.omegahat.org/Sxslt)

Usage

xmlTree(tag, dtd=NULL, namespaces=list())

Arguments

tag
the tagname of the top-level element. This is basically ignored!
dtd
the name of the external DTD for this document. See newXMLDoc
namespaces
a named character vector with each element giving the name space identifier and the corresponding URI, e.g c(shelp="http://www.omegahat.org/XML/SHelp")

Value

  • An object of class XMLInternalDOM that extends XMLOutputStream and has the same interface (i.e. ``methods'') as xmlOutputBuffer and xmlOutputDOM. Each object has methods for adding a new XML tag, closing a tag, adding an XML comment, and retrieving the contents of the tree.
  • addTagcreate a new tag at the current position, optionally leaving it as the active open tag to which new nodes will be added as children
  • closeTagclose the currently active tag making its parent the active element into which new nodes will be added.
  • addCommentadd an XML comment node as a child of the active node in the document.
  • valueretrieve an object representing the XML tree. See saveXML to serialize the contents of the tree.
  • adddegenerate method in this context.

Details

This creates a collection of functions that manipulate a shared state to build and maintain an XML tree in C-level code.

References

http://www.w3.org/XML, http://www.xmlsoft.org, http://www.omegahat.org

See Also

saveXML newXMLDoc newXMLNode xmlOutputBuffer xmlOutputDOM

Examples

Run this code
tr <- xmlTree("Duncan")
  tr$addTag("name", attrs=c(a=1,b="xyz"), close=F)
    tr$addTag("first", "Larry")
    tr$addTag("last", "User")
  tr$closeTag()
  tr$value()
  cat(saveXML(tr$value()))

Run the code above in your browser using DataLab