【delphi开源代码栏目提醒】:网学会员,鉴于大家对delphi开源代码十分关注,论文会员在此为大家搜集整理了“XMLBuilderWriter.pas”一文,供大家参考学习!
unit XMLBuilderWriter;
interface
uses
SysUtils, Variants, Classes,
WebAdapt, WebComp, DBAdapt, XMLDoc, XMLIntf, Contnrs, XMLBuilderComp;
type
TXMLWriter = class(TInterfacedObject, IXMLWriter)
private
FXMLDocument: IXMLDocument;
FXMLNode: IXMLNode;
FList: TStack;
protected
{ IXMLWriter }
procedure PushNode;
procedure PopNode;
procedure AddNode(const AName: WideString);
procedure WritePropertyValue(AName: WideString; AValue: Variant);
function GetXMLDocument: IXMLDocument;
public
property XMLDocument: IXMLDocument read GetXMLDocument;
constructor Create;
destructor Destroy; override;
end;
implementation
uses SiteComp, WebAuto, AutoAdap, ActiveX, ms
xmldom;
{ TXMLWriter }
constructor TXMLWriter.Create;
var
Temp: TXMLDocument;
begin
Temp := TXMLDocument.Create(nil);
FXMLDocument := Temp;
FXMLDocument.Active := True;
FXMLNode := FXMLDocument.GetDocumentElement;
FList := TStack.Create;
inherited;
end;
destructor TXMLWriter.Destroy;
begin
while FList.Count > 0 do
PopNode;
FList.Free;
inherited;
end;
procedure TXMLWriter.WritePropertyValue(AName: WideString; AValue: Variant);
begin
if not VarIsClear(AValue) then
FXMLNode.Attributes[AName] := AValue
else
FXMLNode.Attributes[AName] := WideString('');
end;
procedure TXMLWriter.PopNode;
begin
FXMLNode := IXMLNode(FList.Pop);
if FXMLNode <> nil then
FXMLNode._Release;
end;
procedure TXMLWriter.PushNode;
begin
if FXMLNode <> nil then
FXMLNode._AddRef;
FList.Push(Pointer(FXMLNode));
end;
procedure TXMLWriter.AddNode(const AName: WideString);
begin
if FXMLNode = nil then
FXMLNode := FXMLDocument.AddChild(AName, WideString(''))
else
FXMLNode := FXMLNode.AddChild(AName);
end;
function TXMLWriter.GetXMLDocument: IXMLDocument;
begin
Result := FXMLDocument;
end;
end.