Methods for displaying XML objects
print.RdThese different methods attempt to provide a convenient
way to display R objects representing XML elements
when they are printed in the usual manner on
the console, files, etc. via the print
function.
Each typically outputs its contents in the way
that they would appear in an XML document.
Usage
# S3 method for class 'XMLNode'
print(x, ..., indent= "", tagSeparator = "\n")
# S3 method for class 'XMLComment'
print(x, ..., indent = "", tagSeparator = "\n")
# S3 method for class 'XMLTextNode'
print(x, ..., indent = "", tagSeparator = "\n")
# S3 method for class 'XMLCDataNode'
print(x, ..., indent="", tagSeparator = "\n")
# S3 method for class 'XMLProcessingInstruction'
print(x, ..., indent="", tagSeparator = "\n")
# S3 method for class 'XMLAttributeDef'
print(x, ...)
# S3 method for class 'XMLElementContent'
print(x, ...)
# S3 method for class 'XMLElementDef'
print(x, ...)
# S3 method for class 'XMLEntity'
print(x, ...)
# S3 method for class 'XMLEntityRef'
print(x, ..., indent= "", tagSeparator = "\n")
# S3 method for class 'XMLOrContent'
print(x, ...)
# S3 method for class 'XMLSequenceContent'
print(x, ...)Arguments
- x
the XML object to be displayed
- ...
additional arguments for controlling the output from print. Currently unused.
- indent
a prefix that is emitted before the node to indent it relative to its parent and child nodes. This is appended with a space at each succesive level of the tree. If no indentation is desired (e.g. when
xmlTreeParseis called withtrimandignoreBlanksbeingFALSE) andTRUErespectively, one can pass the valueFALSEfor thisindentargument.when printing nodes, successive nodes and children are by default displayed on new lines for easier reading. One can specify a string for this argument to control how the elements are separated in the output. The primary purpose of this argument is to allow no space between the elements, i.e. a value of
"".
Note
We could make the node classes self describing with information
about whether ignoreBlanks was TRUE or FALSE and
if trim was TRUE or FALSE.
This could then be used to determine the appropriate values for
indent and tagSeparator. Adding an S3 class element
would allow this to be done without the addition of an excessive
number of classes.
Examples
fileName <- system.file("exampleData", "event.xml", package ="XML")
# Example of how to get faithful copy of the XML.
doc = xmlRoot(xmlTreeParse(fileName, trim = FALSE, ignoreBlanks = FALSE))
print(doc, indent = FALSE, tagSeparator = "")
#> <event date="2003-05-23" id="esc018">
#> <dialog>
#> <feature name="Date">2003-05-23</feature>
#> <feature name="f2">1</feature>
#> <feature name="f3">3</feature>
#> </dialog>
#> <dialog>
#> <feature name="Date">2003-05-24</feature>
#> <feature name="f2">17</feature>
#> <feature name="f3">24</feature>
#> </dialog>
#> <dialog>
#> <feature name="Date">http://mtadss01.mt.att.com/nlslogapp/displaysession.jsp?serviceid=esc018&sessionid=2OLhD6ZX&dat+e=2003_05_23</feature>
#> <feature name="f2">17</feature>
#> <feature name="f3">24</feature>
#> </dialog>
#> </event>
# And now the default mechanism
doc = xmlRoot(xmlTreeParse(fileName))
print(doc)
#> <event date="2003-05-23" id="esc018">
#> <dialog>
#> <feature name="Date">2003-05-23</feature>
#> <feature name="f2">1</feature>
#> <feature name="f3">3</feature>
#> </dialog>
#> <dialog>
#> <feature name="Date">2003-05-24</feature>
#> <feature name="f2">17</feature>
#> <feature name="f3">24</feature>
#> </dialog>
#> <dialog>
#> <feature name="Date">http://mtadss01.mt.att.com/nlslogapp/displaysession.jsp?serviceid=esc018&sessionid=2OLhD6ZX&dat+e=2003_05_23</feature>
#> <feature name="f2">17</feature>
#> <feature name="f3">24</feature>
#> </dialog>
#> </event>