How it works#
How ProRock works with XML and SOAP: from a schema to Delphi classes.
Excel workbooks work out of the box
Calcite needs no schema and no generator: the classes for Excel's own schemas are already generated and part of ProRock's source.
An XML schema (XSD) already says exactly what a document may contain. ProRock turns that description into Delphi classes, and from then on you work with objects: no parsing code, no node walking.
⇅
Delphi objects
Nothing of the generator ends up in your program
It works before you compile. What your program carries is the generated units and the library, as ordinary Delphi source.
From a schema to working code#
A small schema, shortened to what matters here:
<xs:simpleType name="Status">
<xs:restriction base="xs:string">
<xs:enumeration value="new"/>
<xs:enumeration value="shipped"/>
</xs:restriction>
</xs:simpleType>
<xs:element name="order">
<xs:complexType>
<xs:sequence>
<xs:element name="customer" type="xs:string"/>
<xs:element name="item" type="Item" maxOccurs="unbounded"/>
<xs:element name="note" type="xs:string" minOccurs="0"/>
</xs:sequence>
<xs:attribute name="status" type="Status"/>
</xs:complexType>
</xs:element>
Generating is one click in the GUI or one command:
ProRocketCli.exe order.xsd
Out comes ProRock.Xmlite.Schema.Order.pas. The heart of it:
TStatusST = (sNew, sShipped);
TOrderE = class(TXmliteElement)
published
property Status: TStatusST read fStatus write fStatus;
[TXmliteElement]
[TRequired]
property Customer: TStringST read fCustomer write fCustomer;
property Item: TItemCTList read fItem;
[TXmliteElement]
property Note: TStringST read fNote write fNote;
end;
The schema's enumeration is a Delphi enum, the repeating element a typed list, and every name is there for code completion. Using it:
var order := TOrderE.Create;
try
order.FromXmlFile('order.xml'); // with ProRock.Xmlite in uses
// Ann: 2 x Rocket
Writeln(order.Customer, ': ', order.Item[0].Quantity, ' x ', order.Item[0].Title);
order.Status := sShipped;
order.Note := 'Left at the door';
Writeln(order.ToXml([woPretty])); // indented; ToXml alone writes one line
finally
order.Free;
end;
<?xml version="1.0" encoding="UTF-8"?>
<order xmlns="urn:shop:order" status="shipped">
<customer>Ann</customer>
<item>
<title>Rocket</title>
<quantity>2</quantity>
</item>
<note>Left at the door</note>
</order>
That is the whole idea. The real schemas are bigger, not different: all of FHIR R4 or an electronic invoice work the same way.
A WSDL goes the same road and gives one more unit: a client class with a method for each operation of the service. From there, calling the service is a method call (Getting started).
The objects are yours#
The generated classes are plain Delphi objects with explicit ownership:
- You free what you create.
- A parent creates and frees its children, so the one
order.Freeabove frees the items as well. - No DOM stays behind them, no interfaces, no reference counting.
Reading and writing back also keep to what the document had: a value that was absent stays absent (details), and parts the schema does not describe are kept.
When the schema changes#
Schemas move: a new e-invoicing version, a service adding fields. You run the generator again on the new schema, and two tools you already have tell you the rest:
- your diff tool: the output is deterministic, so the units change only where the schema changed (
--no-timestampleaves out the time in the header) - the compiler: an element that was renamed or removed is now a compile error at every place that used it
Nothing to hunt for by hand.
Which part does what#
| What it is | You get it | |
|---|---|---|
| ProRocket Lite | the generator: XSD and WSDL in, Delphi units out, GUI and command line | a free download, also for commercial use |
| ProRock | the library the units compile against, pure Delphi source | open source (Apache 2.0): add its Source folder to the search path |
| Your units | the generated classes | the code is yours, no strings attached |
Try it on your own schema: from an XSD or from a WSDL.