Xorn
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
Public Member Functions | Public Attributes | List of all members
xorn.xml_writer.XMLWriter Class Reference

Writing XML documents. More...

Public Member Functions

def __init__
 Create an XMLWriter instance. More...
 
def is_done
 Return whether the document written so far is complete. More...
 
def write
 Callback for writing out data. More...
 
def start_element
 Write an opening tag for a new element. More...
 
def end_element
 Write a closing tag for the innermost element. More...
 
def write_attribute
 Write an attribute for the innermost element. More...
 
def write_character_data
 Write character data. More...
 
def write_cdata_section
 Write a CDATA section. More...
 

Public Attributes

 write
 
 is_initialized
 
 has_root_element
 
 stack
 
 preserve_depth
 
 state
 
 current_attrs
 

Detailed Description

Writing XML documents.

This class is used for creating XML documents and writing them to some output function in a stream-like fashion. It does not create an in-memory representation of the document.

Example usage:

1 w = xorn.xml_writer.XMLWriter(f.write)
2 w.start_element('document')
3 w.write_attribute('attribute', 'value')
4 w.write_character_data('some text')
5 w.end_element()
6 assert w.is_done()

This yields the following output:

1 <?xml version="1.0" encoding="UTF-8"?>
2 <document attribute="value">
3  some text
4 </document>
Note
The caller must only pass characters which are valid in XML, i.e. none of 00-1f (except 09, 0a, and 0d), d800-dfff, fffe, ffff, or 110000 and above.

Definition at line 97 of file xml_writer.py.

Constructor & Destructor Documentation

def xorn.xml_writer.XMLWriter.__init__ (   self,
  write 
)

Create an XMLWriter instance.

write must be a function accepting a single unicode object as an argument which is called to write the actual data.

You need to create a separate XMLWriter instance for each XML document.

Definition at line 106 of file xml_writer.py.

Member Function Documentation

def xorn.xml_writer.XMLWriter.end_element (   self)

Write a closing tag for the innermost element.

Definition at line 169 of file xml_writer.py.

def xorn.xml_writer.XMLWriter.is_done (   self)

Return whether the document written so far is complete.

Definition at line 117 of file xml_writer.py.

def xorn.xml_writer.XMLWriter.start_element (   self,
  name,
  preserve_whitespace = False 
)

Write an opening tag for a new element.

name must be a valid XML element name. If preserve_whitespace is True, no extra formatting whitespace will be inserted inside this element.

Definition at line 146 of file xml_writer.py.

def xorn.xml_writer.XMLWriter.write (   self,
  data 
)

Callback for writing out data.

When creating an instance, this is set to the write argument to the XMLWriter constructor.

Definition at line 125 of file xml_writer.py.

def xorn.xml_writer.XMLWriter.write_attribute (   self,
  name,
  value 
)

Write an attribute for the innermost element.

name must be a valid XML element name. In value, the characters '&', '<', '>', and '"' are replaced with their entity representations.

All attributes must be written before any character data, CDATA sections, or child elements are written.

Definition at line 199 of file xml_writer.py.

def xorn.xml_writer.XMLWriter.write_cdata_section (   self,
  data 
)

Write a CDATA section.

Special characters in this section are not escaped except for the character sequence ']]>'.

Definition at line 240 of file xml_writer.py.

def xorn.xml_writer.XMLWriter.write_character_data (   self,
  data 
)

Write character data.

The characters '&', '<', '>', and '"' are replaced with their entity representations.

Definition at line 221 of file xml_writer.py.

Member Data Documentation

xorn.xml_writer.XMLWriter.current_attrs

Definition at line 113 of file xml_writer.py.

xorn.xml_writer.XMLWriter.has_root_element

Definition at line 109 of file xml_writer.py.

xorn.xml_writer.XMLWriter.is_initialized

Definition at line 108 of file xml_writer.py.

xorn.xml_writer.XMLWriter.preserve_depth

Definition at line 111 of file xml_writer.py.

xorn.xml_writer.XMLWriter.stack

Definition at line 110 of file xml_writer.py.

xorn.xml_writer.XMLWriter.state

Definition at line 112 of file xml_writer.py.

xorn.xml_writer.XMLWriter.write

Definition at line 107 of file xml_writer.py.


The documentation for this class was generated from the following file: