VerySimpleXML 2.0 – a lightweight, cross-platform, one-unit XML reader/writer for Delphi 2010 – 10.1 Berlin
There are lot of possibilities if you’re in need to parse or write XML files:
- use TXMLDocument (the MS XML wrapper)
- or use a xml component like OmniXML, NativeXml, ADOM, SAX, libxml2, DIXml, fcl-XML, Fast XMLParser, SimpleXML, OXml, or VerySimpleXML 1.0
Now here comes another one: the updated VerySimpleXML 2.0 – a lightweight, cross-platform, one-unit XML reader/writer for Delphi 2010 – 10.1 Berlin targeting at Win32, Win64, iOS, MacOSX and Android. Use it for well-formed XML files (like configuration files, interprocess communication protocols, etc.).
VerySimpleXML 2.0 is still open sourced and open for anyone to participate in the further development.
What’s new in version 2.0?
- Support for these nodes types: ntElement (default node type), ntComment (comment nodes), ntDocType (Document Type Definition, but not parsed/evaluated), ntText (text only nodes), ntCData (CDATA sections), ntProcessingInstr (processing instructions)
- Windows 32 bit, Windows 64 bit, Mac OSX, iOS and Android compatible
- Support for headless xml files
- Reduced memory consumption
- Allows now processing of large xml files without line breaks
- Node content is now read exactly as found (including line breaks)
- Case sensitive/insensitve node and attribute name handling (use doCaseInsensitive option)
- Write UTF-8 files with or without BOM (doWriteBOM option)
- Support for attributes without values (single attribute type)
- Support for the Delphi “nextgen compiler” and weak references for ARC
- Added a lot of TXMLDocument compatible methods
- Support for parsing the ntProcessingInstr nodes (processing instructions)
- Support for Windows, Unix and even custom line breaks
- Improved fluent interfaces
What’s the difference between version 1.x and version 2.0?
a) Root and Header nodes
There is no
XmlDoc.Root element any more (it’s still there but hidden in the private declarations part) because it’s renamed to
XmlDoc.DocumentElement to be more TXMLDocument compatible and it’s not created by default now.
Old version 1.0
Xml := TXmlVerySimple.Create;
Xml.Header.Attribute['encoding'] := 'utf-8';
Xml.Root.NodeName := 'books';
Node := Xml.Root.AddChild('book');
Node.Attribute['id'] := 'bk103';
Node.Text := 'A book';
New version 2.0
Xml := TXmlVerySimple.Create; // Create a new XmlDocument with default encoding "utf-8"
//Xml.Encoding := 'utf-8'; // A more convinient way to change the encoding
//Xml.Header.Attribute['encoding'] := 'utf-8'; // is still valid
// Add a new child node, the first child node is the DocumentElement
// Add a new book node to the document root
Node := Xml.DocumentElement.AddChild('book');
Node.Attributes['id'] := 'bk103';
Node.Text := 'A book';
You may have noticed that
Node.Attribute['someattrib'] is now renamed to
Node.Attributes['someattrib'] as well.
The above example still works by using fluent interfaces:
Xml := TXmlVerySimple.Create;
Xml.AddChild('books').AddChild('book').SetAttribute('id', 'bk103').Text := 'A book';
or even written as a one liner : -)
The next gen compiler hints “H2593: code has no effect”, so you may omit the last
b) Last line break
As VerySimpleXML 2.0 operates now on read and write buffers instead of string lines, it omits the last line break of a xml file when written.
How to upgrade to version 2.0?
VerySimpleXml.paswith the new
Come on – yet another XML parser?
About 3 years ago I was in a need for parsing some xml files, so I’ve started using TXMLDocument. But because it was a little bit slow, I’ve decided to write my own very simple xml parser (hence the name) because I couldn’t find an easy to use, “unbloated” xml component. VerySimpleXML was done in about two afternoons – I’m good in writing parsers ; -) and is still used in a lot of projects. At the end of last year I’ve upgraded to Delphi XE5 and startet porting the xml parser to the next gen compiler. And added a lot more features – mainly support for different node types like comments and cdata. VerySimpleXML is not “feature-complete”, nor is it the fastest delphi xml parser found (but still faster than TXmlDocument) – it is just a small and simple parser for small and simple xml files. If you need something more versatile, I highly recommend OXml – The next generation XML library for Pascal written by Ondřej Pokorný (the same author who updated and bug fixed the great OmniXML component) which even runs with Delphi 6 and FPC, Lazarus and C++Builder.
Found a bug or need help?
28 Comments to VerySimpleXML 2.0 – a lightweight, cross-platform, one-unit XML reader/writer for Delphi 2010 – 10.1 Berlin
Leave a comment
About Dennis D. Spreen
- Pass a multidimensional array as a parameter (with a hidden caveat)
- Behavior3 client library for Delphi (Behavior Trees for Delphi)
- LibBLP v1.0 – A BLP image reader library for Delphi 10.1 Berlin+ with DXT3/5 decompression support
- Convert your Gamebase64 C64 ROM files to Emulationstation (RetroPie & Recalbox) format
- How to fix the “api-ms-win-crt-runtime-l1-1.0.dll is missing” error for Delphi 10 Seattle
- VerySimple.Lua 2.0 – a cross-platform Lua 5.3.0 wrapper for Delphi XE5-10.1 Berlin
- How to compile Lua 5.3.0 as an iOS static library
- How to compile Lua 5.3.0 for Android as a dynamic library
- How to compile Lua 5.3.0 as a Mac OS X dynamic library
- How to compile Lua 5.3.0 for Windows
- August 2016
- July 2016
- June 2016
- January 2016
- September 2015
- February 2015
- January 2015
- October 2014
- September 2014
- August 2014
- May 2014
- March 2014
- February 2014
- November 2011
- June 2011
- February 2011
- March 2010
- September 2009
- August 2009
- July 2009
- May 2009
- March 2009
- February 2009
- January 2009
- November 2008
- October 2008
- February 2008
- June 2007
- Perth Meeting – February 2017
- Castle Game Engine 6.0 released
- The New Embarcadero MVP Feed
- Anonymous Classes: Identity Exposed!
- Resizing TImageList Bitmaps to Fit High-DPI Scaling Size (for Menus, Toolbars, Trees, etc.)
- Key Traits of the Coming Delphi For Linux Compiler
- OmniThreadLibrary 3.07
- Yet another surprise from Delphi compiler
- Now that Delphi will reintroduce Linux as a target: what features / support do you expect in the compiler and libraries?
- Musings on TIOBE