各位,我刚接触XML,对此技术很感兴趣,也觉得其应用前景很好!
可不可以给一些具体的应用实例,最好有Delphi源代码!
可不可以给一些具体的应用实例,最好有Delphi源代码!
解决方案 »
- INDY9->INDY10代码转换问题。。
- “拨号连接”设置里面如何判断“连接后在通知区域显示图标(&W)”这个Button是否选中?
- 联想在美遭戴尔DELL幕后黑手
- 在做主从表更新取消的时候出现的问题。。。。。。。
- 今天奶奶过寿,散740分,以示庆祝!!
- 组件事件问题:Assigned(FOnReceiveData)=false 怎么办?
- 大家看看看啊,好奇怪的一个思路.
- 一个急得要命的问题,好心人帮帮忙,有高分相送,关于地址!
- 怎样得到当前dbgrid选择列,行的 位置,
- 动态查询数据库。
- 那位大哥提供一下像TMxOutLookBar一样的控件,要用Delphi7的!
- 请问各位在websnap中都用什么方法做报表?
// Name: ADOXMLFromDataSet(Source: TDataSet): String;
// Description: Transfer the specified dataset into the XML
// document which supplied by microsoft's ADO;
// Input Para: 1) Source: Dataset -- Original dataset
// Output Par: 1) String -- XML document's string;
// Comment: 1) 把数据集转换为ADO支持的XML格式;
// 2) 注意xml文档中的microsoft的name-space;
// --------------------------------------------------------- //
function ADOXMLFromDataSet(Source: TDataSet): String;
const
BoolToStrMAP: array[boolean] of string = ('true','false');
var
FieldIndex: Integer;
slst: TStringList;
begin
result := ''; slst := TStringList.Create;
try
// ADO XML Prolog -- Note is microsoft's type!!!
slst.Add('<xml xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882"');
slst.Add('xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"');
slst.Add('xmlns:rs="urn:schemas-microsoft-com:rowset"');
slst.Add('xmlns:z="#RowsetSchema">'); // Schema
slst.Add('<s:Schema id="RowsetSchema">');
slst.Add('<s:ElementType name="row" content="eltOnly" rs:updatable="true">'); // Loop through each of the Fields in the DataSet
for FieldIndex := 0 to Source.FieldCount-1 do
begin
slst.Add(Source.Fields[FieldIndex].FieldName + '="' + Source.Fields[FieldIndex].AsString + '" ');
slst.Add('<s:AttributeType name="' + Source.Fields[FieldIndex].FieldName + '" rs:number="' + IntToStr(FieldIndex) + '" rs:write="' + BoolToStrMAP[Source.Fields[FieldIndex].ReadOnly] + '">');
slst.Add('<s:datatype dt:type="' + FieldTypeToADOString(Source.Fields[FieldIndex].DataType) + '" dt:maxLength="' + IntToStr(Source.Fields[FieldIndex].Size) + '"');
slst.Add(' rs:maybenull="' + BoolToStrMAP[Source.Fields[FieldIndex].Required] + '"/>');
// rs:precision='0' rs:long='true'
slst.Add('</s:AttributeType>');
end; slst.Add('<s:extends type="rs:rowbase"/>');
slst.Add('</s:ElementType>');
slst.Add('</s:Schema>'); // Data
slst.Add('<rs:data>');
slst.Add('<rs:insert>'); while not Source.EOF do
begin
// Generic tag identifying new record
slst.Add('<z:row '); // Loop through each of the Fields in the DataSet
for FieldIndex := 0 to Source.FieldCount-1 do
// Add the Param for the Field
slst.Add(Source.Fields[FieldIndex].FieldName + '="' + Source.Fields[FieldIndex].AsString + '" '); // Close record tag
slst.Add(' />');
// Go to the next record
Source.Next;
end; // while slst.Add('</rs:insert>');
slst.Add('</rs:data>');
slst.Add('</xml>'); // return the result
result := slst.Text;
finally
slst.free;
end;
end;
// Name: FieldTypeToADOString(p_FieldType: TFieldType): string;
// Description: 把各种数据格式(Delphi supported)转换成ADO字符串;
// Input Para: 1) p_FieldType: TFieldType;
// Output Par: 1) String -- only has value 'string';
// Comment:
// --------------------------------------------------------- //
function FieldTypeToADOString(p_FieldType: TFieldType): string;
begin
{ TODO : Real values }
case p_FieldType of
ftUnknown, ftString, ftSmallint, ftInteger, ftWord,
ftBoolean, ftFloat, ftCurrency, ftBCD, ftDate, ftTime, ftDateTime,
ftBytes, ftVarBytes, ftAutoInc, ftBlob, ftMemo, ftGraphic, ftFmtMemo,
ftParadoxOle, ftDBaseOle, ftTypedBinary, ftCursor, ftFixedChar, ftWideString,
ftLargeint, ftADT, ftArray, ftReference, ftDataSet, ftOraBlob, ftOraClob,
ftVariant, ftInterface, ftIDispatch, ftGuid : result := 'string';
end;
end;
// Name: XMLFromDataSet(Source: TDataSet): String;
// Description: Transfer the specified dataset into the XML
// document which self-definition;
// Input Para: 1) Source: Dataset -- Original dataset
// Output Par: 1) String -- XML document's string;
// Comment: 1) 把数据集转换为自定义的XML格式;
// --------------------------------------------------------- //
function XMLFromDataSet(Source: TDataSet): String;
var
FieldIndex: Integer;
slst: TStringList;
begin
result := ''; slst := TStringList.Create;
try
// Simple XML header
slst.Add('<?xml version = "1.0" ?>'); // Generic name for set of all records
slst.Add('<RecordSet tablename="' + Source.Name + '">'); while not Source.EOF do
begin
// Generic tag identifying new record
slst.Add('<Record>'); // Loop through each of the Fields in the DataSet
for FieldIndex := 0 to Source.FieldCount-1 do
// Generate the XML of the data
slst.Add('<' + Source.Fields[FieldIndex].FieldName + '>' + Source.Fields[FieldIndex].AsString + '</' + Source.Fields[FieldIndex].FieldName + '>'); // Closing record tag
slst.Add('</Record>');
// Go to the next record
Source.Next;
end; // while slst.Add('</RecordSet>');
// return the result
result := slst.Text;
finally
slst.free;
end;
end;