OXml - The next generation XML library for Pascal (Delphi, FPC, Lazarus)

OXml 2.1

OXml 2.1
OXml 2.1


OXml is a new XML library for Delphi and Lazarus, developed in late 2013. I took some inspiration from OmniXML but wrote the library completely from scratch. The aim of OXml is to be the most versatile and fastest XML library for the Pascal language.

OXml features:

XML DOM with XPath and namespace support
sequential XML DOM parser
XML SAX parser with class handlers for specific objects
XML serializer (with and without enhanced RTTI)
direct XML reader/writer
vendor for Delphi's XmlIntf.TXMLDocument
XML DataBinding engine
JSON Tree ("DOM")
JSON Event ("SAX") parser with class handlers for specific objects
direct JSON reader and writer with JSON serialization and deserialization
fast buffered text reader and writer with encoding support
lots of useful helper classes like integer and string lists and dictionaries
encoding support for pre-2009 Delphi
OXml supports all Delphi versions starting from Delphi 5 on all platforms: Win32, Win64, OSX, iOS, Android, Linux.
OXml supports Lazarus 1.0 and newer on all platforms (tested Win32, Win64, Linux, MacOSX).

Library design
Use the same XML library for all your Pascal projects including:
Delphi for Win32, Win64 and OSX (Delphi 5 and newer).
Delphi ARC/NEXTGEN for iOS and Android (Delphi XE4 and newer).
Delphi ARC/NEXTGEN for Linux (Delphi 10.2 and newer).
Lazarus on Win32, Win64, Linux, OSX (Lazarus 1.0 and newer).
Native pascal object oriented code.
No external dll libraries are required.
No dependency on a visual library like VCL, LCL or FMX.
Full unicode support even for D5-D2007.
Powerful XPath engine.
Fast, powerful and easy-to-use namespace support for reading documents.
Faster than everything else on all platforms thanks to various optimizations.
OXml is able to read and write invalid XML documents and correct errors in them (if wanted). If not wanted, OXml throws an exception when you are trying to read/write an invalid XML document.
Supports all on the platform available encodings (UTF-16, UTF-8, single-byte ISO, WIN, KOI8...) by all parsers automatically. That means that the encoding is read and set from the <?xml encoding="" ?> tag during both reading and writing.
Readers and writers included in OXml
OXml features 7 classes/units for working with XML documents:
TXMLWriter (OXmlReadWrite.pas): Basic XML writer. All other classes use it.
Use it directly if performance is crucial for you.
TXMLReader (OXmlReadWrite.pas): Basic XML reader. All other classes use it.
Don't use it directly. If performance is crucial for you, use SAX which has the same performance but is much more comfortable to work with.
TSAXParser (OXmlSAX.pas): Event-based parser according to the SAX specification.
Anonymous methods are supported for modern Delphi versions, too. It's very fast and needs practically no memory.
IXMLDocument (OXmlPDOM.pas): Record-based DOM according to the W3C DOM Level 1 specification. (Not strict - some small changes have been made to maximize performance).
The fastest and most memory-friendly DOM for Pascal.
IXMLDocument (OXmlCDOM.pas): TObject-based DOM according to the W3C DOM Level 1 specification. (Not strict - some small changes have been made to maximize performance).
For those who don't like the "old-school" approach of OXmlPDOM.pas. There is some performance and memory consumption penalty, though.
TXMLSeqParser (OXmlSeq.pas): Sequential DOM parser based on OXmlPDOM.pas.
Read huge XML files into the DOM sequentionally. This method combines DOM capabilities without the need to load the whole document at once.
OXmlSeq is even a little bit faster than OXmlPDOM.
sOXmlDOMVendor (OXmlDOMVendor.pas): fastest DOM vendor for Delphi's own TXMLDocument.
Use TXMLDocument(MyXmlDoc).DOMVendor := GetDOMVendor(sOXmlDOMVendor) if you want to use Delphi's default TXMLDocument with the fastest and cross-platform vendor.
What are the differences between OXmlPDOM and OmniXML / MS XML?
In general OXmlPDOM is very close to both implementations. They share the same functions and properties.
OmniXML and MS XML are interfaced-based. That means that nodes are created one-by-one and when they are not referenced any more, they are automatically destroyed.
OXmlPDOM is record-based. Nodes are created by groups of 1024 items, which offers stunning performance. They are automatically destroyed only when the owner XML document is destroyed. Therefore such functions do not free memory used by a node:
TXMLNode.RemoveChild()
TXMLNode.ReplaceChild()
When using OXmlPDOM you should call TXMLNode.DeleteChild(), TXMLNode.DeleteAttribute() or TXMLNode.DeleteSelf in order to be sure the node memory is marked as free and can be reused again.
The nodes are of PXMLNode type - pointer to TXMLNode structure. Strictly speaking, PXMLNode nodes have to be dereferenced to TXMLNode when used but Delphi does this dereferencing for you, so you can easily use: XML.DocumentElement.AddChild('child');
If you use FPC/Lazarus in Delphi mode ({$MODE DELPHI}), the nodes get dereferenced too. But if you use FPC/Lazarus in default mode, you have to dereference it manually with the "^" operator: XML.DocumentElement^.AddChild('child');
If you don't like this approach, use OXmlCDOM.pas instead of OXmlPDOM.pas.
OXmlPDOM does not store child nodes and attributes in AttributeNodes and ChildNodes lists.
That means that the lists are created only when they are needed by the user. AttributeNodes and ChildNodes are not typical TList descendants but they are doubly linked lists with fast index iteration and count function support.

KNOW MORE ABOUT THIS PRODUCT



Only for V.I.P
Warning! You are not allowed to view this text.


Information
Users of Guests are not allowed to comment this publication.