unit xmlunit;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls,
Db,MSXML_TLB,ComObj,DBTables, ADODB;
type
TForm1 =
class(TForm)
Button1: TButton;
Memo1: TMemo;
ADOConnection1: TADOConnection;
ADOTable1: TADOTable;
ADODataSet1: TADODataSet;
procedure Button1Click(Sender: TObject);
private
function makeXml(table:TADOTable):Integer;
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
DataList:TWideStringField;
doc:IXMLDOMDocument;
root,child,child1:IXMLDomElement;
text1,text2:IXMLDOMText;
nlist:IXMLDOMNodelist;
dataRecord:
String;
implementation
{$R *.DFM}
function TForm1.makeXml(table:TADOTable):Integer;
var
i : Integer;
xml :
String;
temp,temp2 : WideString;
begin
try
ADOTable1.close;
ADOTable1.open;
xml := ADOTable1.TableName;
doc := CreateOleObject('
Microsoft.XMLDOM')
as IXMLDomDocument;
//root name of the xml file = table name
root := doc.createElement(
xml);
doc.appendchild(root);
while not ADOTable1.eof
do
begin
child:= doc.createElement('
Records');
root.appendchild(child);
for i:=0
to ADOTable1.FieldCount-1
do
begin
child1:=doc.createElement(ADOTable1.Fields[i].FieldName);
child.appendchild(child1);
//*******************************************************************
//EDatabaseError!!!!!!!
//im FieldByName steht der richtige Wert
//beim Debugging steht bei Value: Ungültiger Ausdruck im Evaluator
temp2 := ((AdoDataset1.FieldByName(ADOTable1.Fields[i].AsVariant))
as TWideStringField).Value;
//*******************************************************************
if temp2 ='
'
then
temp :='
null'
//a default string
else
temp := temp2;
child1.appendChild(doc.createTextNode(UTF8encode(temp)));
end;
ADOTable1.Next;
end;
doc.save(
xml+'
.xml');
//just for test
memo1.lines.Append(doc.xml);
Result:=1;
except
on e:
Exception do
Result:=-1;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if makeXml(ADOTable1)=1
then
showmessage('
XML wurde erstellt')
else
showmessage('
Fehler beim Erstellen des XML-Files');
end;
end.