This creates a string from a hierarchical XML node and its children just as it prints on the console or one might see it in a document.

# S3 method for class 'XMLNode'
toString(x, ...)

Arguments

x

an object of class XMLNode.

...

currently ignored

Details

This uses a textConnection object using the name .tempXMLOutput. Since this is global, it will overwrite any existing object of that name! As a result, this function cannot be used recursively in its present form.

Value

A character vector with one element, that being the string corresponding to the XML node's contents.

Author

Duncan Temple Lang

Note

This requires the Expat XML parser to be installed.

Examples

 x <- xmlRoot(xmlTreeParse(system.file("exampleData", "gnumeric.xml", package = "XML")))

 toString(x)
#> [1] "<gmr:Workbook xmlns:gmr=\"http://www.gnome.org/gnumeric/v2\">\n <gmr:Summary>\n  <gmr:Item>\n   <gmr:name>Application</gmr:name>\n   <gmr:val-string>gnumeric</gmr:val-string>\n  </gmr:Item>\n  <gmr:Item>\n   <gmr:name>Author</gmr:name>\n   <gmr:val-string>Duncan Temple Lang</gmr:val-string>\n  </gmr:Item>\n </gmr:Summary>\n <gmr:Geometry Width=\"600\" Height=\"400\"/>\n <gmr:Sheets>\n  <gmr:Sheet>\n   <gmr:Name>Sheet1</gmr:Name>\n   <gmr:MaxCol>1</gmr:MaxCol>\n   <gmr:MaxRow>7</gmr:MaxRow>\n   <gmr:Zoom>1.000000</gmr:Zoom>\n   <gmr:CellStyles>\n    <gmr:Style No=\"1\" HAlign=\"1\" VAlign=\"4\" Fit=\"0\" Orient=\"1\" Shade=\"0\" Format=\"mm/dd/yyyy\">\n     <gmr:Font Unit=\"12.000000\" Bold=\"0\" Italic=\"0\">Helvetica</gmr:Font>\n    </gmr:Style>\n    <gmr:Style No=\"2\" HAlign=\"1\" VAlign=\"4\" Fit=\"0\" Orient=\"1\" Shade=\"0\" Format=\"General\">\n     <gmr:Font Unit=\"12.000000\" Bold=\"0\" Italic=\"0\">Helvetica</gmr:Font>\n    </gmr:Style>\n    <gmr:Style No=\"3\" HAlign=\"8\" VAlign=\"4\" Fit=\"0\" Orient=\"1\" Shade=\"0\" Format=\"General\">\n     <gmr:Font Unit=\"12.000000\" Bold=\"0\" Italic=\"0\">Helvetica</gmr:Font>\n    </gmr:Style>\n   </gmr:CellStyles>\n   <gmr:Cols>\n    <gmr:ColInfo No=\"0\" Unit=\"80.000000\" MarginA=\"1.000000\" MarginB=\"1.000000\" HardSize=\"0\"/>\n    <gmr:ColInfo No=\"1\" Unit=\"80.000000\" MarginA=\"1.000000\" MarginB=\"1.000000\" HardSize=\"0\"/>\n   </gmr:Cols>\n   <gmr:Rows>\n    <gmr:RowInfo No=\"1\" Unit=\"18.000000\" MarginA=\"1.000000\" MarginB=\"1.000000\" HardSize=\"0\"/>\n    <gmr:RowInfo No=\"2\" Unit=\"18.000000\" MarginA=\"1.000000\" MarginB=\"1.000000\" HardSize=\"0\"/>\n    <gmr:RowInfo No=\"3\" Unit=\"18.000000\" MarginA=\"1.000000\" MarginB=\"1.000000\" HardSize=\"0\"/>\n    <gmr:RowInfo No=\"4\" Unit=\"18.000000\" MarginA=\"1.000000\" MarginB=\"1.000000\" HardSize=\"0\"/>\n    <gmr:RowInfo No=\"5\" Unit=\"18.000000\" MarginA=\"1.000000\" MarginB=\"1.000000\" HardSize=\"0\"/>\n    <gmr:RowInfo No=\"6\" Unit=\"18.000000\" MarginA=\"1.000000\" MarginB=\"1.000000\" HardSize=\"0\"/>\n    <gmr:RowInfo No=\"7\" Unit=\"18.000000\" MarginA=\"1.000000\" MarginB=\"1.000000\" HardSize=\"0\"/>\n   </gmr:Rows>\n   <gmr:Cells>\n    <gmr:Cell Col=\"1\" Row=\"7\" Style=\"1\">\n     <gmr:Content>36524</gmr:Content>\n    </gmr:Cell>\n    <gmr:Cell Col=\"0\" Row=\"4\" Style=\"2\">\n     <gmr:Content>4</gmr:Content>\n    </gmr:Cell>\n    <gmr:Cell Col=\"1\" Row=\"4\" Style=\"3\">\n     <gmr:Content>d</gmr:Content>\n    </gmr:Cell>\n    <gmr:Cell Col=\"0\" Row=\"1\" Style=\"2\">\n     <gmr:Content>1</gmr:Content>\n    </gmr:Cell>\n    <gmr:Cell Col=\"1\" Row=\"1\" Style=\"3\">\n     <gmr:Content>x</gmr:Content>\n    </gmr:Cell>\n    <gmr:Cell Col=\"1\" Row=\"5\" Style=\"3\">\n     <gmr:Content>sd</gmr:Content>\n    </gmr:Cell>\n    <gmr:Cell Col=\"0\" Row=\"2\" Style=\"2\">\n     <gmr:Content>2</gmr:Content>\n    </gmr:Cell>\n    <gmr:Cell Col=\"0\" Row=\"6\" Style=\"2\">\n     <gmr:Content>5</gmr:Content>\n    </gmr:Cell>\n    <gmr:Cell Col=\"1\" Row=\"2\" Style=\"3\">\n     <gmr:Content>s</gmr:Content>\n    </gmr:Cell>\n    <gmr:Cell Col=\"1\" Row=\"6\" Style=\"3\">\n     <gmr:Content>dsa</gmr:Content>\n    </gmr:Cell>\n    <gmr:Cell Col=\"0\" Row=\"3\" Style=\"2\">\n     <gmr:Content>3</gmr:Content>\n    </gmr:Cell>\n    <gmr:Cell Col=\"1\" Row=\"3\" Style=\"3\">\n     <gmr:Content>as</gmr:Content>\n    </gmr:Cell>\n   </gmr:Cells>\n  </gmr:Sheet>\n </gmr:Sheets>\n</gmr:Workbook>"