XMLWorks

Current Revision : 1999.7.14
Author : Marc Bir (ughh)
Original Concept : Chad Z Hower (kudzu)

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.




Download XMLWorks 2 Marc Bir