在delphi中使用xml文件有兩種方法
使用xml代理,是delphi內建的。
單元ShowXML;
介面
使用類別 HTTPApp Db DbClient Midas
XMLBrokr WebComp MidItems;
類型
TCustomShowXMLButton = 類別(TXMLButton IScriptComponent)
受保護
XML方法名稱:字串;
{ IScript元件 }
過程 AddElements(AddIntf: IAddScriptElements);
函數 GetSubComponents: TObject;
{ IWebContent 實作 }
函數 ImplContent(選項:TWebContentOptions;
父佈局:TLayout):字串;覆蓋;
結尾;
TShowXMLButton = 類別(TCustomShowXMLButton)
民眾
建構子 Create(AOwner: TComponent);覆蓋;
發表
財產定制;
屬性風格;
屬性樣式規則;
屬性標題;
屬性 XMLBroker;
屬性 XMLUseParent;
結尾;
TShowDeltaButton = 類別(TCustomShowXMLButton)
民眾
建構子 Create(AOwner: TComponent);覆蓋;
發表
財產定制;
屬性風格;
屬性樣式規則;
屬性標題;
屬性 XMLBroker;
屬性 XMLUseParent;
結尾;
執行
使用 sysutils MidProd;
資源字串
sShowXML = '顯示 XML';
sShowDelta = '顯示增量';
過程 TCustomShowXMLButton.AddElements(
AddIntf: IAddScriptElements);
開始
AddIntf.AddIncludeFile('xmlshow.js');
結尾;
函數 TCustomShowXMLButton.GetSubComponents: TObject;
開始
結果:=零;
結尾;
函數 TCustomShowXMLButton.ImplContent(選項: TWebContentOptions;
父佈局:TLayout):字串;
變數
屬性:字串;
Intf:ILayoutWebContent;
表單變數名稱:字串;
RowSetVarName:字串;
開始
AddQuotedAttrib(Attrs 'NAME' 名稱);
AddQuotedAttrib(Attrs 'STYLE' 樣式);
AddQuotedAttrib(Attrs 'CLASS' StyleRule);
AddQuotedAttrib(Attrs 'VALUE' Self.Caption);
AddCustomAttrib(屬性自訂);
如果已指派(XMLData.XMLBroker) 那麼
開始
FormVarName := XMLData.XMLBroker.SubmitFormVarName;
RowSetVarName := XMLData.XMLBroker.RowSetVarName(nil); // 行行集變數名稱
結尾;
如果不是(Options.Flags 中的 coNoScript)則
結果:=
格式(''#13#10
[屬性 RowSetVarName XMLMethodName sXMLReadyVar])
別的
結果:=
格式(''#13#10
[屬性]);
如果分配(ParentLayout)和ParentLayout.GetInterface(ILayoutWebContent Intf)然後
結果 := Intf.LayoutButton(結果 GetLayoutAttributes);
結尾;
{ TShowXMLButton }
建構子 TShowXMLButton.Create(AOwner: TComponent);
開始
遺傳;
預設標題 := sShowXML;
XMLMethodName := '根';
結尾;
{ TShowDeltaButton }
建構子 TShowDeltaButton.Create(AOwner: TComponent);
開始
遺傳;
預設標題 := sShowDelta;
XMLMethodName := 'getDelta()';
結尾;
另一種方法使用msxml.dll如下:
....
....
過程 TDHEDForm.OpenBtnClick(寄件者: TObject);
變數
pVIn:油變體;
提示:OleVariant;
開始
pVIn := '';
提示:=真;
DHTMLEdit1.LoadDocument(pVIn 提示);
結尾;
過程 TDHEDForm.SaveBtnClick(寄件者: TObject);
變數
vo vb:OleVariant;
開始
vo := DHTMLEdit1.CurrentDocumentPath;
如果 (vo <> '') 那麼
開始
vb := 假;
結尾
別的
開始
沃:='';
vb := 真;
結尾;
DHTMLEdit1.SaveDocument(vo vb);
結尾;
流程 TDHEDForm.SaveAsClick(寄件者: TObject);
變數
vo vb:OleVariant;
開始
沃:='';
vb := 真;
DHTMLEdit1.SaveDocument(vo vb);
結尾;
……
//為論文轉貼,作者不詳,僅供大家參考