The XmlWriter class
The om.XmlWriter class implements methods to write XML to a
stream.
The om.XmlWriter class implements methods to create a om.SaxDocumentHandler object.
Steps to use a XML writer:
- Declare a variable with the
om.SaxDocumentHandlertype. - Create the writer object with one of the class methods of
om.XmlWriterand assign the reference to the variable.om.XmlWriter.createFileWriter(filename)creates an object writing to a file.om.XmlWriter.createPipeWriter(command)creates an object writing to a pipe opened by a sub-process.om.XmlWriter.createSocketWriter(hostname,portnum)creates an object writing to the TCP socket.
- Output XML data with the methods of the
om.SaxDocumentHandlerobject:- Use the method
startDocument()to start writing to the output. - From this point, the order of method calls defines the structure of the XML
document. To write an element, fill an
om.SaxAttributesobject with attributes. - Then, initiate the element output with the method
startElement(). - Write element data with the
characters()method. - Entity nodes are created with the
skippedEntity()method. - Finish element output with a call to the
endElement()method. - Repeat these steps as many times as you have elements to write.
- Instead of using the
startElement()method, you can generate processing instruction elements withprocessingInstruction(). - Finally, you must finish the document output with a
endDocument()call.
- Use the method