![]() |
![]() |
![]() |
Current Revision : 1999.7.14
Author : Marc Bir (ughh)
Original Concept : Chad Z Hower (kudzu)
ATTENTION : XMLWorks is now officially part of the Delphi Jedi initiative. For more information on JEDI check out their website at: www.delphi-jedi.org
XMLWorks is a collection of OpenSource utilities designed to help Delphi developers create XML documents. Click here for a full copy of the license.
NOTE: Due to the move to JEDI, XMLWorks is now published under a dual license. The second license is MPL 1.1, the full text is this license is available here
We now have two mailing lists setup for XMLWorks, check out JEDI-XMLWorks and JEDI-XMLWorks-Announce at www.OneList.com
I have recently changed jobs and times have been very hectic, which of course means my time on XMLWorks has been rather limited. I will be full force back into XMLWorks by the second week of the new year, after things have settled down at work. However if you have any questions or comments always feel free to email me, or post to the mailing list.
XMLWorks is in no way designed to be an all encompassing package for XML, but it does offer many features that should help Delphi developers working with XML.
The basic idea behind XMLWorks is to use Delphi Collections to generate DTD and entity information. All you have to do is create a descendant class of TXMLCollection to define your new list type, and a descendant class of TXMLCollectionItem to define the fields of each record.
In general you don't need to do more than declare a descendant class of TXMLCollection named something like TAuthorCollection. When generating the DTD it will automatically use the name 'Author' (whatever text is between the 'T' and 'Collection') + '-list'.
For the TXMLCollectionItem descendant class, you must publish all the properties you want saved in the entity information. Just like the collection class, XMLWorks will automatically use the name between 'T' and 'Collection'.
For example with the following type declarations:
----------------------------------
TAuthorCollection = class(TXMLCollection) end; TAuthorCollectionItem = class(TXMLCollectionItem) private fphone: String; fau_id: String; faddress: String; fcity: String; fpostalcode: String; fau_lname: String; fstate: String; fau_fname: String; ftestint : Integer; ftestchar: char; ftestfloat: real; ftestint64: Int64; ftestenum: TAuthorType; ftestvariant: Variant; published property au_id : String read fau_id write fau_id; property au_lname : String read fau_lname write fau_lname; property au_fname : String read fau_fname write fau_fname; property phone : String read fphone write fphone; property address : String read faddress write faddress; property city : String read fcity write fcity; property state : String read fstate write fstate; property postalcode : String read fpostalcode write fpostalcode; property TestInt : Integer read ftestint write ftestint; property TestFloat : real read ftestfloat write ftestfloat; property TestVariant : Variant read ftestvariant write ftestvariant; property TestInt64 : Int64 read ftestint64 write ftestint64; property TestChar : char read ftestchar write ftestchar; property TestEnum : TAuthorType read ftestenum write ftestEnum; end;----------------------------------
XMLWorks will generate the following DTD
----------------------------------
<!-- Author-list --> <?XML version = "1.0" ?> <!DOCTYPE Author-list [ <!ELEMENT Author-list (Author)* > <!ELEMENT Author (address,au_fname,au_id,au_lname,city,phone,postalcode,state,TestChar,TestEnum,TestFloat,TestInt,TestInt64,TestVariant) > <!ELEMENT address (#PCDATA)> <!ELEMENT au_fname (#PCDATA)> <!ELEMENT au_id (#PCDATA)> <!ELEMENT au_lname (#PCDATA)> <!ELEMENT city (#PCDATA)> <!ELEMENT phone (#PCDATA)> <!ELEMENT postalcode (#PCDATA)> <!ELEMENT state (#PCDATA)> <!ELEMENT TestChar (#PCDATA)> <!ELEMENT TestEnum (#PCDATA)> <!ELEMENT TestFloat (#PCDATA)> <!ELEMENT TestInt (#PCDATA)> <!ELEMENT TestInt64 (#PCDATA)> <!ELEMENT TestVariant (#PCDATA)> ]>----------------------------------
A sample entity generated by XMLWorks of the above data
----------------------------------
<Author-list> <Author> <address>9919 Hornpipe</address> <au_fname>Marc</au_fname> <au_id></au_id> <au_lname>Bir</au_lname> <city>Houston</city> <phone>713-827-8931</phone> <postalcode>77080</postalcode> <state>TX</state> <TestChar>Z</TestChar> <TestEnum>atWorthless</TestEnum> <TestFloat>1.1</TestFloat> <TestInt>20</TestInt> <TestInt64>205876666</TestInt64> <TestVariant>TestVariant</TestVariant> </Author> </Author-list>----------------------------------
Example code for using the collections
----------------------------------
with TAuthorCollection.Create(TAuthorCollectionItem) do try with TAuthorCollectionItem(Add)do begin au_fname := 'Marc'; au_lname := 'Bir'; phone := '713-827-8931'; address := '9919 Hornpipe'; city := 'Houston'; state := 'TX'; postalcode := '77080'; TestInt := 20; TestFloat := 1.1; TestVariant := 'TestVariant'; TestInt64 := 205876666; TestChar := 'Z'; TestEnum := atWorthless; end; Memo1.Lines.Add(XML); finally Free; end;----------------------------------
In the above example I create an instance of the Collection then add an item to it, and set the values for the item. This can easily be modified to integrate with TTables(or any data type) in a for loop.
To generate the XML for the data stored in the collection simply read the XML property of the collection. The DTD property is just the Document Type Definition for the collection, and Entities is for
I'm currently working on the reading of the entity information into the collection (you can see the beginnings of this in the demo). The next major feature will be the automatic generation of the class declarations (TAuthorCollection and TAuthorCollectionItem) from a DTD.
Currently when generating a DTD all supported types are translated to PCDATA (parsed character data). I plan to fix this in the near future.
Currently supported types are : String, Integer, Float, Variant, Int64, Char, Enumeration
For those that missed the conference this year, Delphi 5 has been officially announced. There is also news of the port of Delphi to Linux, including a demo of the backend compiler running on Linux. Borland has just announced a beta of their 'Community' project. You can check it out at community.borland.com. XML was discussed at a few of the sessions this year (I expect it to be a big part of next years conference). Including some new tools in Delphi 5 that are supposed to make creating XML easier. I'll report back when I know more. But don't worry, unless I see something amazing with their XML tools, I'm still working full force on XMLWorks. Check back next week, I plan to post an update soon.
One of the cool new features in Delphi 5 is nested tables. Utilizing this feature can alleviate some of the problems I've had in designing a fully featured TDataSet descendant for XML. I'll keep you posted as I play with this feature.
There was some interest at the conference on an intro to XML for Delphi developers. So I'm working on some ideas on this now, to give you a better understanding of XML, XSL, DTD, and all the other buzz words.
As always, if you have any suggestions, questions, comments, thoughts, wishes, complaints, or you're just bored you can drop me an email at Ughh
![]() |
![]() |
Marc Bir |