xmlWriter

XmlWriter Methods

Before working with the methods below, you may wish to read our documentation about Writing extracted data to XML, which contains examples of scripts that utilize these methods.

addElement

(enterprise edition only)
Element XmlWriter.addElement( String name )
Element XmlWriter.addElement( String name, String text )
Element XmlWriter.addElement( String name, String text, Hashtable attributes )
Element XmlWriter.addElement( Element elementToAppendTo, String name )
Element XmlWriter.addElement( Element elementToAppendTo, String name, String text )
Element XmlWriter.addElement( Element elementToAppendTo, String name, String text, Hashtable attributes )
Description
Writes out a single element to the XML file. Each of these method calls return an Element object, which can subsequently be passed to other calls in order to add sub-nodes to an element.
Example
The best way to see this in action is to refer to the examples in the main XmlWriter documentation page.

addElements

(enterprise edition only)
Element XmlWriter.addElements( Element elementToAppendTo, String name, Hashtable subElements )
Element XmlWriter.addElements( Element elementToAppendTo, String name, String text, Hashtable subElements )
Element XmlWriter.addElements( Element elementToAppendTo, String name, String text, Hashtable attributes, Hashtable subElements )
Element XmlWriter.addElements( String name, Hashtable subElements )
Element XmlWriter.addElements( String name, String text, Hashtable subElements )
Element XmlWriter.addElements( String name, String text, Hashtable attributes, Hashtable subElements )
Element XmlWriter.addElements( String containingTagName, DataSet dataSet )
Element XmlWriter.addElements( String containingTagName, String containingTagText, DataSet dataSet )
Element XmlWriter.addElements( String containingTagName, String containingTagText, Hashtable attributes, DataSet dataSet )
Description
Writes out multiple elements to the XML file. Each of these method calls return an Element object, which can subsequently be passed to other calls in order to add sub-nodes to an element.
Example
The best way to see this in action is to refer to the examples in the main XmlWriter documentation page.

close

XmlWriter.close() (enterprise edition only)
Description
Writes out the closing root element tag and closes up the XML file.
Example
// Assuming the variable "xmlWriter" points to an existing

// instance of XmlWriter, this will close up the file.

xmlWriter.close();

xmlWriter

(enterprise edition only)
XmlWriter( String fileName, String rootElementName )
XmlWriter( String fileName, String rootElementName, String rootElementText )
XmlWriter( String fileName, String rootElementName, String rootElementText, Hashtable attributes )
Description
Creates a new XmlWriter. The fileName is the path to the XML file that should be written. The root element can be given a name and text as well as attributes by using the various constructors.
Example
// Creates a new writer that will write it's XML file to
// C:\myfile.xml. The root element will be named "root_element"
// and the text of the root element will be "This is the root."
// Note that the forward slash after the "C:" is necessary
// as it must be escaped out for the script interpreter.
xmlWriter = new com.screenscraper.xml.XmlWriter( "C:/myfile.xml", "root_element", "This is the root." );