Managing the default XML DOM
Scanning the whats new in RAD Studio XE7 (Delphi, C++ Builder) it covers the introduction of a new XML Dom (OmniXML) meaning there are now 3 XML DOMS to choose from when setting the default XML DOM.
- MSXML
- ADOM
- OmniXML
The XML Dom defines which engine in essence is used to work with your XML documents.
Should I read on? Well if your using SOAP or XML in your projects, then this could make a difference to your speed and performance of the applications, and it takes seconds to implement.
How to set the DOM?
To make it easy to pick which DOM to use in the project by default, you can set the default DOM for the application using the “DefaultDOMVendor” global variable. (This lives in unit Xml.xmldom)
To set the Default XML DOM via code you need to add Xml.xmldom to your uses clause and in code set DefaultDOMVendor.
Each DOM has a constant that is stored in its retrospective unit defining the XML dom, so the SUDO code to set each DOM is as follows;
MSXML
uses Xml.xmldom, Xml.Win.msxmldom; DefaultDOMVendor := SMSXML;
OmniXML
uses Xml.xmldom, Xml.omnixmldom; DefaultDOMVendor := sOmniXmlVendor;
ADOM
uses Xml.xmldom, Xml.adomxmldom; DefaultDOMVendor := sAdom4XmlVendor;
How to set this for my project?
You can easily set this in the Project Source, e.g. View > Project Source (or select the project name in the Project Manager and press Ctrl + V).
The following is an example set this the default to OmniXML.
program Project1; uses System.StartUpCopy, FMX.Forms, Unit1 in 'Unit1.pas' {Form1}, Xml.xmldom, XML.OmniXMLDom; {$R *.res} begin DefaultDOMVendor := sOmniXmlVendor; Application.Initialize; Application.CreateForm(TForm1, Form1); Application.Run; end.
Which DOM should I use?
In short it depends on your project, but as a simple rule, MSXML on Windows and VCL applications and OmniXML for x-platform projects. A break down of the DOMs follows:
MSXML
Fastest of the built-in RAD Studio XML vendors. Windows only. Default.
For cross-platform support, you must choose a different XML vendor. If you do not specify a different XML vendor, your application does not have XML support on other platforms than Windows, and you see a run-time exception when you run your application in other platforms.
OmniXML
Much faster than ADOM, but slightly slower than MSXML. Cross-platform.
ADOM
Slower than the other built-in RAD Studio XML vendors. Cross-platform.
Which DOM am I using?
There are two ways to find out which DOM is being used.
TDOMVendor.Description is one way. You can get the current TDOMVendor using the GetDOMVendor function.
Alternatively, after GetDOMVendor has been called in code you can use the CurrentDOMVendor global variable.
You can also get a list of the current available DOM’s at run time using the DOMVendors global that returns a TDOMVendorList.
Is it possible to add other DOM’s in the future?
In short, Yes! TDOMVendor implements IDOMImplementation interface that is used by DOM’s to provide functionality – in the future additional DOM’s could be added that implement this interface and thus plumb directly in.
Choose MSXML when you want to have to install another runtime dependency, which might already be installed and be a different version on half your customer’s systems, and which has random errors like “Out of Storage Space” that pop up while you run it.
In short don’t use MSXML.