_xmllib.py - ZMS XML Parsing and Serialization Utilities
Provides functions for converting ZMS objects to/from XML representation, including support for complex data types (dictionaries, lists, blobs), multilingual attributes, and CDATA handling. Contains the XmlAttrBuilder parser for complex Python attributes and the XmlBuilder parser for custom XML structures.
License: GNU General Public License v2 or later, Organization: ZMS Publishing
| Class | |
XML parser for complex Python attributes (dictionaries, lists, blobs). |
| Class | |
XML parser for custom XML structures. |
| Exception | |
Exception class to indicate XML parsing errors. |
| Function | get |
Convert a single ZMS object attribute to its XML representation. |
| Function | get |
Convert a ZMS object property to XML, handling multilingual attributes. |
| Function | get |
Export a ZMS object and optionally its children to XML. |
| Function | get |
Extract text content from a list of DOM nodes. |
| Function | get |
Return an XML type attribute string for a Python value. |
| Function | get |
Convert a string value to the appropriate Python type based on XML attrs. |
| Function | parse |
Parse an XML string into a DOM document. |
| Function | serialize |
Serialize a DOM node to an XML string. |
| Function | to |
Wrap a string value in a CDATA section for safe XML embedding. |
| Function | to |
Convert a Python value to its XML string representation. |
| Function | xml |
Return an XML declaration header. |
| Function | xml |
Initialize a ZMS object property with a value during XML import. |
| Function | xml |
Retrieve node-set for given tag-name from dictionary of XML-Node-Structure. |
| Function | xml |
Handle character data during XML import parsing. |
| Function | xml |
Handle unknown end tags during ZMS XML import. |
| Function | xml |
Handle unknown start tags during ZMS XML import. |
| Function | xml |
Parse arbitrary XML-Structure into dictionary. |
| Constant | INDENTSTR |
Undocumented |
Convert a single ZMS object attribute to its XML representation.
| Parameters | |
| self | ZMS object |
| base | Base path for resolving blob references |
| data2hex:bool | Whether to hex-encode binary data |
| obj | Object attribute definition dict |
| REQUEST | Zope request object |
| Returns | |
| str | XML string for the attribute value |
Convert a ZMS object property to XML, handling multilingual attributes.
| Parameters | |
| self | ZMS object |
| REQUEST | Zope request object |
| base | Base path for resolving references |
| data2hex:bool | Whether to hex-encode binary data |
| obj | Object attribute definition dict |
| multilang:bool | Whether to export all language variants |
| Returns | |
| str | XML string for the property |
Export a ZMS object and optionally its children to XML.
| Parameters | |
| self | ZMS object to export |
| REQUEST | Zope request object |
| deep:bool | Whether to recursively export child nodes |
| base | Base path for resolving references |
| data2hex:bool | Whether to hex-encode binary data |
| multilang:bool | Whether to export all language variants |
| Returns | |
| str | XML string for the object tree |
Extract text content from a list of DOM nodes.
| Parameters | |
| nodelist | DOM node or list of DOM nodes |
| encoding:str | Character encoding (unused, kept for compatibility) |
| Returns | |
| str | Concatenated text content |
Return an XML type attribute string for a Python value.
| Parameters | |
| v | Python value to determine XML type for |
| Returns | |
| str | XML type attribute (e.g. ' type="int"') or empty string |
Convert a string value to the appropriate Python type based on XML attrs.
| Parameters | |
| v:str | Value to convert (typically a string from XML parsing) |
| attrs:dict | Dictionary of XML attributes, expects 'type' key |
| Returns | |
| Converted value (int, float, datetime, or stripped string) | |
Parse an XML string into a DOM document.
| Parameters | |
| s:str | XML string to parse |
| Returns | |
| xml.dom.minidom.Document | Parsed DOM document |
Serialize a DOM node to an XML string.
| Parameters | |
| node:xml.dom.Node | DOM node to serialize |
| Returns | |
| str | XML string representation |
Wrap a string value in a CDATA section for safe XML embedding.
Returns the string as-is if it contains no special characters, otherwise wraps it in <![CDATA[...]]>.
| Parameters | |
| self | ZMS context object |
| s:str or bytes | String value to wrap |
| xhtml:bool | Whether output is XHTML (unused) |
| Returns | |
| str | CDATA-wrapped string or original string |
Convert a Python value to its XML string representation.
Handles images, files, dictionaries, lists, datetime tuples, numbers, and string values.
| Parameters | |
| self | ZMS context object |
| value | Python value to convert |
| indentlevel:int | Current XML indentation level |
| xhtml:bool | Whether output is XHTML |
| encoding:str | Character encoding |
| Returns | |
| str | XML string representation |
Return an XML declaration header.
| Parameters | |
| encoding:str | Character encoding for the header |
| Returns | |
| str | XML declaration string |
Initialize a ZMS object property with a value during XML import.
Handles type conversion for date, integer, float, and string fields.
| Parameters | |
| self | ZMS object being imported |
| key:str | Property key/attribute name |
| value | Property value to set |
| lang:str or None | Language identifier (optional) |
Retrieve node-set for given tag-name from dictionary of XML-Node-Structure.
| Returns | |
| list | List of dictionaries of XML-Structure. |
Handle character data during XML import parsing.
Appends character data to the current tag on the tag stack.
| Parameters | |
| self | ZMS object being imported |
| s | Character data string |
| b | Whether data is inside a CDATA section |
| Returns | |
| int | 1 to accept any character data |
Handle unknown end tags during ZMS XML import.
Processes the completed element by popping it from the tag stack and handling its data according to element type (dict/list items, data blobs, language variants, conf-properties, or object attributes).
| Parameters | |
| self | ZMS object being imported |
| s | XML element name |
| Returns | |
| int | 1 to accept matching end tag, 0 on mismatch |
Handle unknown start tags during ZMS XML import.
Manages the tag stack and value stack for nested XML elements including dictionaries, lists, data blobs, and language variants.
| Parameters | |
| self | ZMS object being imported |
| s | XML element name |
| d | Dictionary of element attributes |
| Returns | |
| int | 1 to accept any unknown tag |