Creating XML from Databases


2004-12-30 10:44:55 PM
delphi230
I have created some classes for converting database results to XML. I am
curious if anyone is interested in these classes and would like to use them. In
exchange, I want to know how well these classes suite your needs.
Here is some of what they support:
1. XML generation from ado recordsets (but a future version can abstract out the
record source in order to support borlands DataSets or your own custom record
source)
2. Parent child relationships between 2 recordsets
3. Custom fields (fields are abstracted out)
4. Script Fields (These are fields that return a value by executing a pascal
script)
5. Format specification. for example custom Date formats, digit packing formats
(taking dashes out of ss#'s or phone numbers), formatting of integer (uses
borland format function)
6. Easy to use
High level function:
function RowText(ARecordset: Recordset; BuildScript: string; FieldChar: char =
':'): string;
Example Usage:
PersonLine:= RowText(Person, '<person fname=":fName" addr1=":addr1"/>')
or
PersonLine:= RowText(Person, '<person Name=":lName, :fName :middleName"
addr1=":addr1"/>')
Anything starting with a ":" marks a field name.
There are more params that can be passed after the : mark
Object usage:
with TADORecordsetXML.Create(PersonRec) do
try
AddFromstript('<person fname=":fName" addr1=":addr1">');
Result:= GetText;
// Result:= GetAllRowsText;
finally
Free;
end;
Parent Child relationship:
============================
Parent:= TADORecordsetXML.Create(PersonRec);
Accounts:= TADORecordsetXML.Create(AcctRec);
Parent.AddFromScript('<person fname=":fName" addr1=":addr1">');
Accounts.SetParent(['Person_ID'], Parent);
Accounts.AddFromScript('<acct bal=":balance"/>');
Parent.Add(Accounts);
Parent.AddRawText('</person>');
XML:= Parent.GetAllRowsText;
Example Result
<person fname="Joe" addr1="cool lane 1">
<acct bal="200.00"/>
<acct bal="150.00"/>
</person>
<person fname="Fred" addr1="Fantasy Lane 5">
<acct bal="0"/>
</person>
These are just simple examples, there is more functionality.
Does this interest anyone?
William Egge
www.eggcentric.com