Contains classes, types, and routines used to implement an XML serialization driver.

Copyright (c) 2000 by Sebastian Guenther, sg@freepascal.org

Extended by Mattias Gaertner:

  • Reading/Writing children, all kinds of properties,
  • Custom properties (via DefineProperties).

laz_xmlstreaming.pas is part of the LazUtils package.

Compiler version-specific alias for String values used in TXMLObjectWriter.

TXMLObjectWriterString is the type passed as an argument to the WriteString method in TXMLObjectWriter.

For FPC version 3.3.1 and later, it is an alias to the RawByteString type. For previous FPC versions, it is an alias to the String type.

Added in LazUtils version 3.0.
Represents element types used in stack elements for an XML object writer. Element is an unknown type. Element represents a property in a list of properties. Element represents a child component in a list of child components. Represents a stack element for an XML object writer.

TXMLObjectWriterStackEl is a class used to represent an element pushed onto the stack for an XML object writer. Members in the class instance contain the TDOMElement instances for the stack element and its Parent, the stack element type, an inner list of stack elements which it contains, and the name of the property represented in the class instance.

TXMLObjectWriterStackEl is used in the implementation of the TXMLObjectWriter class to represent the current element being processed in the XML object writer.

DOM Element which represents the component or property in the stack element.

Element is a TDOMElement member used to store the values from the property or component represented in the stack element. Element is created and populated when TXMLObjectWriter processes properties, components, collections, and lists in the class instance.

Use PropertyName to get the name of the property represented in the stack element.

Use ElemType to determine whether the stack element represents a property list, child component list, or other type.

Use Parent to access the TDOMElement which is the parent for the current stack element.

TDOMElement
Contains the TDOMElement that is the parent node for the stack element. Indicates the element type for the stack element. Name of the property represented in the stack element. Serializes an object instance using an XML storage format.

TXMLObjectWriter is a TAbstractObjectWriter descendant which implements an object serialization writer using XML as the storage format. TXMLObjectWriter implements abstract methods defined in the ancestor class, and provides access to the DOM document and the DOM Node tree used to store values generated in the class instance. It maintains an internal stack used to capture and process the hierarchical node tree needed to represent a class instance.

TAbstractObjectWriter
Gets a TDOMElement used to serialize a property using the specified type name.

GetPropertyElement returns a TDOMElement configured to represent a property using the specified type.

The TagName in the element is set to the specified TypeName argument. The property name is retrieved from the internal element stack in the class instance and stored as the 'name' attribute in the element. If the property name has not been assigned (''), the name attribute is omitted from the element.

The TDomElement in the return value is appended as a child node to the element stack.

GetPropertyElement is used in the implementation of write methods in the object instance. Such as:

  • BeginCollection
  • WriteBinary
  • WriteBoolean
  • WriteFloat
  • WriteSingle
  • WriteCurrency
  • WriteInteger
  • WriteUInt64
  • WriteIdent
  • WriteDate
  • WriteMethodName
  • WriteSet
  • WriteString
  • WriteWideString
  • WriteUnicodeString
  • WriteVariant

These calling routines set the 'value' attribute for the element returned from the method. Tehety may set set additional attribute values, like 'class', as needed for a component or type.

Raises an Exception if the DOM elment already exists, and has therefore already been saved.
TDOMElement used to represent the type and property name. Name for the type represented in the property element. Constructor for the class instance.

Create is the constructor for the class instance. It provides arguments which identify the XML document where the XML content is stored, an optional path to a node in the document where the content is stored, and a flag to indicate the content is appended to or replaces the content for the root node in the document.

TDomDocument instance where the XML content is stored. Path expression to the node where the XML content is stored. True to append the content to the root node in the document, False to replace it. Starts serialization of a Collection using the XML format for the writer. Starts serialization of a Component using the XML format for object writer. The component instance written in the method. Not used in the current LCL implementation. Not used in the current LCL implementation. Starts serialization of a list using the XML format for the writer. Finishes serialization of a list using the XML format for the writer. Starts serialization for a property using the XML format for the object writer. Name for the property used as the value for the name attribute in the element. Ends serialization for a property using the XML format for the writer. Serializes a binary value from the specified buffer.

WriteBinary calls GetPropertyElement to create the DOM element used to serialize the property. The content in Buffer is converted to a String type and stored in the 'value' attribute for the DOM element.

Untyped buffer with the binary value serialized in the method. Number of bytes in the untyped buffer. Serializes a Boolean value using the XML format for the writer. Boolean value written in the method. Serializes a floating point value using the XML format for the writer. Floating point value written in the method. Serializes a Single value using the XML format for the writer. Single value written in the method. Serializes a Currency value using the XML format for the writer. Currency value written in the method. Serializes a TDateTime value using the XML format for the writer. TDateTime value written in the method. Serializes an Identifier using the XML format for the writer. String with the identifier written in the method. Serializes an Integer value using the XML format for the object writer. Integer value written in the method. Serializes the specified method name using the XML format for the object writer. Method name written in the method. Serializes a set values from the specified type using the XML format for the object writer. LongInt with the bit values for the set type. Pointer to the type for the set. Serializes a string value using the XML format for the object writer.

WriteString is an overridden method in TXMLObjectWriter used to store the specified string value to the XML storage format used in the writer class. WriteString calls GetPropertyElement to get or create a TDOMElement stack entry where the Value argument is stored. In the TDOMElement, the string value is stored in a tag with the name 'string' using the 'value' attribute to store the passed value.

WriteString implements the abstract virtual method defined in TAbstractObjectWriter.

Modified in LazUtils version 3.0 to use the TXMLObjectWriterString type instead of the String type in the Value argument. TAbstractObjectWriter
String value stored in the method. Serializes a wide string value using the XML format for the object writer. WideString value written in the method. Not needed for the XML format used in TXMLObjectWriter.

Contains an empty implementation in TXMLObjectWriter.

Serializes an Int64 value using the XML format for the object writer.

Included when USE_NEW_READER_WRITER has been defined in the LCL.

Unsigned 64-bit Integer (QWord) value serialized in the method. Serializes an UnicodeString value using the XML format for the object writer.

Included when USE_NEW_READER_WRITER has been defined in the LCL.

UnicodeString value serialized in the method. Converted to UTF-8 encoding. Serializes a Variant value using the XML format for the object writer.

Supports the following variant types:

varEmpty
Stores 'nil' in the value attribute.
varNull
Stores 'null' in the value attribute.
varShortInt, varSmallInt, varInteger, varInt64
Calls WriteInteger to store the value attribute.
varQWord
Calls WriteUInt64 to store the value attribute.
varBoolean
Calls WriteBoolean to store the value attribute.
varCurrency
Calls WriteCurrency to store the value attribute.
varSingle
Calls WriteSingle to store the value attribute.
varDouble
Calls WriteFloat to store the value attribute.
varDate
Calls WriteDate to store the value attribute.
varOleStr, varString
Calls WriteWideString to store the value attribute.

Raises an EWriteError exception if any other variant type is encountered in the method.

Included when USE_NEW_READER_WRITER has been defined in the LCL.

Raises an EWriteError exception if any other variant type is encountered in the method.
Variant value serialized in the method. Raises an exception in the current LCL version.

Raises an Exception when HasReadWriteBuf has been defined in the LCL.

Untyped buffer with the value written in the method. Number of bytes in the untyped buffer. TDOMDocument used to create and store elements in the XML object writer.

Doc is a read-only TDOMDocument property which contains the DOM document used to create and store the DOM elements written in XML object writer. The value in Doc is assigned in the Create constructor, and uses the TDOMDocument instance passed as an argument to the constructor.

Class type used to create new instances of the XML object writer. De-serializes an object instance from its XML storage format. TAbstractObjectReader Constructor for the class instance.

Create is the constructor for the object instance. It uses values passed in the ADoc and APath arguments to access the DOM document and node(s) where the XML content for the object reader is stored.

ADoc is assigned to the Doc property in the class instance, and its DocumentElement is used to access nodes in the DOM tree.

APath contains an expression used to locate the DOM node with the content for the object reader. It provides the hierarchy of DOM nodes used to access the XML content for the class instance.

Create raises an Exception in the constructor if a node cannot be located using the path in APath, or when the node is not a valid TDOMElement instance. Use exception handling when calling the method.
TDOMNode TDOMElement TDOMDocument
TDOMDocument instance with the values read in the object reader. Path to the node in ADoc where the object instance is stored. Destructor for the class instance.

Calls the inherited destructor on entry.

Gets the class name from the node which is the root element for the object instance.

GetRootClassName raises an Exception if a component node cannot be located in the root element, or the node is not a valid TDOMElement instance.

Value from the class attribute in the element. Not used in the current LCL implementation. Reads the value type for the next element in the XML DOM tree. TValueType TValueType for the next element in the DOM tree, or vaNull when a value type cannot be determined. Reads the value for the next element in the XML DOM tree after the value type has been read. TValueType for the element read from the DOM tree, or vaNull when a value type cannot be determined. Locates the DOM node for the component in the document element.

Raises an Exception if Element has not been assigned, or a node using a "component" tag is not found in the Element.

Gets the DOM element for the component, gets the class type and component name, and sets Element to the properties node. TFilerFlag values. Not used in the current implementation. Not used in the current implementation. Returns the value from the 'class' attribute in the DOM Element. Returns the value from the 'name' attribute in the DOM Element. Reads the property name from Element and prepares for the property value(s). Name for the property read from the XML content in the Element. Reads a binary value from Element and stores it in the specified stream. TMemoryStream instance where the binary value is stored. Reads a string value from Element and converts it to a floating point value. Floating point value converted in the method, or 0 as the default. Converts a string value in Element to a Single data type. Single value converted in the method, or 0 as the default. Converts a string value in Element to a Currency data type. Currency value converted in the method, or 0 as the default. Reads a TDateTime value from the DOM Element. TDateTime value from the 'value' attribute in the DOM Element. Reads an Identifier from Element. String with content from the 'value' attribute in the DOM Element. Not used in the current implementation. Reads a ShortInt value from Element. ShortInt value for the 'value' attribute in the DOM Element. Reads a SmallInt value from Element. SmallInt value for the 'value' attribute in the DOM Element. Reads a LongInt value from Element. LongInt value for the 'value' attribute in the DOM Element. Reads an Int64 type from Element. Int64 value for the 'value' attribute in the DOM Element. Reads values for a set type from Element. Integer value representing the OR-ed enumeration values for the set type. Pointer to the RTTI Type with the enumeration values handled in the method. Reads a String value from Element. String representing the 'value' attribute in the DOM Element. Reads a string value from Element. Why the exception when the string has more than 255 characters? String representing the 'value' attribute in the DOM Element. TValueType for the string type handled in the method. vaString is limited to 255 characters. Reads a WideString value from Element.

Converts the UTF-8-encoded content in Element to the WideString type used in the return value.

WideString value for the 'value' attribute in the DOM element. Not implemented and not needed in TXMLObjectReader. Reads a UnicodeString value from Element.

Converts the UTF-8-encoded value in Element to the UnicodeString type used in the return value.

UnicodeString value read in the method. Positions the reader to the next sibling DOM node in Element. Not used in the current implementation. Reads and discards the value in Element. Raises an exception in the current LCL implementation. Untyped buffer where the values read in the method are stored. Number of bytes to read and store in the buffer. TDomDocument instance with the XML content read in the object reader. Contains the DOM element currently being processed in the XML object reader. Indicates whether the object reader is processing an element name or its value.

0 indicates that the element name is being processed. 1 indicates that the name processing has been completed, and the value(s) in the element are being processed.

Class type used to create new instances of the XML object reader. Serializes the specified component to a stream using an XML object writer. Component with values written to the stream. TStream instance where the XML content is stored.