unit uPSI_XMLDocument;
{
This file has been generated by UnitParser v0.7, written by M. Knight
and updated by NP. v/d Spek and George Birbilis.
Source Code from Carlo Kok has been used to implement various sections of
UnitParser. Components of ROPS are used in the construction of UnitParser,
code implementing the class wrapper is taken from Carlo Kok's conv utility

}
interface



uses
   SysUtils
  ,Classes
  ,uPSComponent
  ,uPSRuntime
  ,uPSCompiler
  ;

type
(*----------------------------------------------------------------------------*)
  TPSImport_XMLDocument = class(TPSPlugin)
  public
    procedure CompileImport1(CompExec: TPSScript); override;
    procedure ExecImport1(CompExec: TPSScript; const ri: TPSRuntimeClassImporter); override;
  end;


{ compile-time registration functions }
procedure SIRegister_TXMLDoc(CL: TPSPascalCompiler);
procedure SIRegister_TNodeList(CL: TPSPascalCompiler);
procedure SIRegister_TNode(CL: TPSPascalCompiler);
procedure SIRegister_XMLDocument(CL: TPSPascalCompiler);

{ run-time registration functions }
procedure RIRegister_TXMLDoc(CL: TPSRuntimeClassImporter);
procedure RIRegister_TNodeList(CL: TPSRuntimeClassImporter);
procedure RIRegister_TNode(CL: TPSRuntimeClassImporter);
procedure RIRegister_XMLDocument(CL: TPSRuntimeClassImporter);

function PSPluginCreate(): TPSPlugin; stdcall;

implementation


uses
   XMLDocument
  ;


function PSPluginCreate(): TPSPlugin; stdcall;
var
  Import: TPSImport_XMLDocument;
begin
  Import:= TPSImport_XMLDocument.Create(nil);
  Result := Import;
end;

(* === compile-time registration functions === *)
(*----------------------------------------------------------------------------*)
procedure SIRegister_TXMLDoc(CL: TPSPascalCompiler);
begin
  //with RegClassS(CL,'TObject', 'TXMLDoc') do
  with CL.AddClassN(CL.FindClass('TObject'),'TXMLDoc') do
  begin
    RegisterMethod('Constructor Create');
    RegisterMethod('Function AddChild( const TagName : string) : TNode');
    RegisterMethod('Function CreateElement( const TagOrData, NamespaceURI : string) : TNode');
    RegisterMethod('Function CreateNode( const NameOrData : string; NodeType : TNodeType; const AddlData : string) : TNode');
    RegisterMethod('Function GetDocBinding( const TagName : string; DocNodeClass : TClass; NamespaceURI : string) : TNode');
    RegisterMethod('Function IsEmptyDoc : Boolean');
    RegisterMethod('Procedure LoadFromFile( const AFileName : string)');
    RegisterMethod('Procedure LoadFromStream( const Stream : TStream; EncodingType : TXMLEncodingType)');
    RegisterMethod('Procedure LoadFromXML( const XML : string)');
    RegisterMethod('Procedure Refresh');
    RegisterMethod('Procedure RegisterDocBinding( const TagName : string; DocNodeClass : TClass; NamespaceURI : string)');
    RegisterMethod('Procedure Resync');
    RegisterMethod('Procedure SaveToFile( const AFileName : string)');
    RegisterMethod('Procedure SaveToStream( const Stream : TStream)');
    RegisterMethod('Procedure SaveToXML( var XML : string)');
    RegisterProperty('ChildNodes', 'TNodeList', iptr);
    RegisterProperty('DocumentElement', 'TNode', iptrw);
    RegisterProperty('Encoding', 'string', iptrw);
    RegisterProperty('Node', 'TNode', iptr);
    RegisterProperty('Version', 'string', iptrw);
    RegisterProperty('Active', 'Boolean', iptrw);
    RegisterProperty('FileName', 'string', iptrw);
    RegisterProperty('Options', 'TXMLDocOptions', iptrw);
    RegisterProperty('ParseOptions', 'TParseOptions', iptrw);
    RegisterProperty('XML', 'TStrings', iptrw);
  end;
end;

(*----------------------------------------------------------------------------*)
procedure SIRegister_TNodeList(CL: TPSPascalCompiler);
begin
  //with RegClassS(CL,'TObject', 'TNodeList') do
  with CL.AddClassN(CL.FindClass('TObject'),'TNodeList') do
  begin
    RegisterMethod('Function Add( const Node : TNode) : Integer');
    RegisterMethod('Procedure Clear');
    RegisterMethod('Function Delete( const Index : Integer) : Integer');
    RegisterMethod('Function DeleteByName( const Name : string) : Integer');
    RegisterMethod('Function First : TNode');
    RegisterMethod('Function FindNode( NodeName : string) : TNode');
    RegisterMethod('Function FindSibling( const Node : TNode; Delta : Integer) : TNode');
    RegisterMethod('Function Get( Index : Integer) : TNode');
    RegisterMethod('Function GetNode( const IndexOrName : Variant) : TNode');
    RegisterMethod('Function GetCount : Integer');
    RegisterMethod('Function IndexOf( const Node : TNode) : Integer');
    RegisterMethod('Function IndexOfByName( const Name : string) : Integer');
    RegisterMethod('Procedure Insert( Index : Integer; const Node : TNode)');
    RegisterMethod('Function Last : TNode');
    RegisterMethod('Function Remove( const Node : TNode) : Integer');
    RegisterMethod('Function ReplaceNode( const OldNode, NewNode : TNode) : TNode');
    RegisterProperty('Count', 'Integer', iptr);
    RegisterProperty('Nodes', 'TNode Variant', iptr);
    SetDefaultPropery('Nodes');
    RegisterMethod('Constructor Create( XMLDoc : TXMLDoc)');
  end;
end;

(*----------------------------------------------------------------------------*)
procedure SIRegister_TNode(CL: TPSPascalCompiler);
begin
  //with RegClassS(CL,'TObject', 'TNode') do
  with CL.AddClassN(CL.FindClass('TObject'),'TNode') do
  begin
    RegisterMethod('Function GetAttributeNodes : TNodeList');
    RegisterMethod('Function GetAttributeNS( const AttrName, NamespaceURI : string) : Variant');
    RegisterMethod('Function GetChildNodes : TNodeList');
    RegisterMethod('Function AddChild( const TagName : string; Index : Integer) : TNode');
    RegisterMethod('Function CloneNode( Deep : Boolean) : TNode');
    RegisterMethod('Procedure DeclareNamespace( const Prefix, URI : string)');
    RegisterMethod('Function FindNamespaceDecl( const NamespaceURI : string) : TNode');
    RegisterMethod('Function FindNamespaceURI( const TagOrPrefix : string) : string');
    RegisterMethod('Function HasAttribute( const Name : string) : Boolean');
    RegisterMethod('Function NextSibling : TNode');
    RegisterMethod('Procedure Normalize');
    RegisterMethod('Function PreviousSibling : TNode');
    RegisterMethod('Procedure SetAttributeNS( const AttrName, NamespaceURI : string; const Value : Variant)');
    RegisterMethod('Constructor Create( const AParentNode : TXMLNode; const OwnerDoc : TXMLDoc)');
    RegisterProperty('Attributes', 'Variant string', iptrw);
    RegisterProperty('ChildValues', 'Variant Variant', iptrw);
    SetDefaultPropery('ChildValues');
    RegisterProperty('HasChildNodes', 'Boolean', iptr);
    RegisterProperty('IsTextElement', 'Boolean', iptr);
    RegisterProperty('LocalName', 'string', iptr);
    RegisterProperty('NamespaceURI', 'string', iptr);
    RegisterProperty('NodeName', 'string', iptr);
    RegisterProperty('NodeType', 'TNodeType', iptr);
    RegisterProperty('NodeValue', 'Variant', iptrw);
    RegisterProperty('ParentNode', 'TNode', iptr);
    RegisterProperty('Prefix', 'string', iptr);
    RegisterProperty('ReadOnly', 'Boolean', iptrw);
    RegisterProperty('Text', 'string', iptrw);
    RegisterProperty('XML', 'string', iptr);
    RegisterProperty('AttributeNodes', 'TNodeList', iptr);
    RegisterProperty('ChildNodes', 'TNodeList', iptr);
  end;
end;

(*----------------------------------------------------------------------------*)
procedure SIRegister_XMLDocument(CL: TPSPascalCompiler);
begin
  CL.AddClassN(CL.FindClass('TOBJECT'),'TNodeList');
  CL.AddClassN(CL.FindClass('TOBJECT'),'TXMLDoc');
  SIRegister_TNode(CL);
  SIRegister_TNodeList(CL);
  SIRegister_TXMLDoc(CL);
end;

(* === run-time registration functions === *)
(*----------------------------------------------------------------------------*)
procedure TXMLDocXML_W(Self: TXMLDoc; const T: TStrings);
begin Self.XML := T; end;

(*----------------------------------------------------------------------------*)
procedure TXMLDocXML_R(Self: TXMLDoc; var T: TStrings);
begin T := Self.XML; end;

(*----------------------------------------------------------------------------*)
procedure TXMLDocParseOptions_W(Self: TXMLDoc; const T: TParseOptions);
begin Self.ParseOptions := T; end;

(*----------------------------------------------------------------------------*)
procedure TXMLDocParseOptions_R(Self: TXMLDoc; var T: TParseOptions);
begin T := Self.ParseOptions; end;

(*----------------------------------------------------------------------------*)
procedure TXMLDocOptions_W(Self: TXMLDoc; const T: TXMLDocOptions);
begin Self.Options := T; end;

(*----------------------------------------------------------------------------*)
procedure TXMLDocOptions_R(Self: TXMLDoc; var T: TXMLDocOptions);
begin T := Self.Options; end;

(*----------------------------------------------------------------------------*)
procedure TXMLDocFileName_W(Self: TXMLDoc; const T: string);
begin Self.FileName := T; end;

(*----------------------------------------------------------------------------*)
procedure TXMLDocFileName_R(Self: TXMLDoc; var T: string);
begin T := Self.FileName; end;

(*----------------------------------------------------------------------------*)
procedure TXMLDocActive_W(Self: TXMLDoc; const T: Boolean);
begin Self.Active := T; end;

(*----------------------------------------------------------------------------*)
procedure TXMLDocActive_R(Self: TXMLDoc; var T: Boolean);
begin T := Self.Active; end;

(*----------------------------------------------------------------------------*)
procedure TXMLDocVersion_W(Self: TXMLDoc; const T: string);
begin Self.Version := T; end;

(*----------------------------------------------------------------------------*)
procedure TXMLDocVersion_R(Self: TXMLDoc; var T: string);
begin T := Self.Version; end;

(*----------------------------------------------------------------------------*)
procedure TXMLDocNode_R(Self: TXMLDoc; var T: TNode);
begin T := Self.Node; end;

(*----------------------------------------------------------------------------*)
procedure TXMLDocEncoding_W(Self: TXMLDoc; const T: string);
begin Self.Encoding := T; end;

(*----------------------------------------------------------------------------*)
procedure TXMLDocEncoding_R(Self: TXMLDoc; var T: string);
begin T := Self.Encoding; end;

(*----------------------------------------------------------------------------*)
procedure TXMLDocDocumentElement_W(Self: TXMLDoc; const T: TNode);
begin Self.DocumentElement := T; end;

(*----------------------------------------------------------------------------*)
procedure TXMLDocDocumentElement_R(Self: TXMLDoc; var T: TNode);
begin T := Self.DocumentElement; end;

(*----------------------------------------------------------------------------*)
procedure TXMLDocChildNodes_R(Self: TXMLDoc; var T: TNodeList);
begin T := Self.ChildNodes; end;

(*----------------------------------------------------------------------------*)
procedure TNodeListNodes_R(Self: TNodeList; var T: TNode; const t1: Variant);
begin T := Self.Nodes[t1]; end;

(*----------------------------------------------------------------------------*)
procedure TNodeListCount_R(Self: TNodeList; var T: Integer);
begin T := Self.Count; end;

(*----------------------------------------------------------------------------*)
procedure TNodeChildNodes_R(Self: TNode; var T: TNodeList);
begin T := Self.ChildNodes; end;

(*----------------------------------------------------------------------------*)
procedure TNodeAttributeNodes_R(Self: TNode; var T: TNodeList);
begin T := Self.AttributeNodes; end;

(*----------------------------------------------------------------------------*)
procedure TNodeXML_R(Self: TNode; var T: string);
begin T := Self.XML; end;

(*----------------------------------------------------------------------------*)
procedure TNodeText_W(Self: TNode; const T: string);
begin Self.Text := T; end;

(*----------------------------------------------------------------------------*)
procedure TNodeText_R(Self: TNode; var T: string);
begin T := Self.Text; end;

(*----------------------------------------------------------------------------*)
procedure TNodeReadOnly_W(Self: TNode; const T: Boolean);
begin Self.ReadOnly := T; end;

(*----------------------------------------------------------------------------*)
procedure TNodeReadOnly_R(Self: TNode; var T: Boolean);
begin T := Self.ReadOnly; end;

(*----------------------------------------------------------------------------*)
procedure TNodePrefix_R(Self: TNode; var T: string);
begin T := Self.Prefix; end;

(*----------------------------------------------------------------------------*)
procedure TNodeParentNode_R(Self: TNode; var T: TNode);
begin T := Self.ParentNode; end;

(*----------------------------------------------------------------------------*)
procedure TNodeNodeValue_W(Self: TNode; const T: Variant);
begin Self.NodeValue := T; end;

(*----------------------------------------------------------------------------*)
procedure TNodeNodeValue_R(Self: TNode; var T: Variant);
begin T := Self.NodeValue; end;

(*----------------------------------------------------------------------------*)
procedure TNodeNodeType_R(Self: TNode; var T: TNodeType);
begin T := Self.NodeType; end;

(*----------------------------------------------------------------------------*)
procedure TNodeNodeName_R(Self: TNode; var T: string);
begin T := Self.NodeName; end;

(*----------------------------------------------------------------------------*)
procedure TNodeNamespaceURI_R(Self: TNode; var T: string);
begin T := Self.NamespaceURI; end;

(*----------------------------------------------------------------------------*)
procedure TNodeLocalName_R(Self: TNode; var T: string);
begin T := Self.LocalName; end;

(*----------------------------------------------------------------------------*)
procedure TNodeIsTextElement_R(Self: TNode; var T: Boolean);
begin T := Self.IsTextElement; end;

(*----------------------------------------------------------------------------*)
procedure TNodeHasChildNodes_R(Self: TNode; var T: Boolean);
begin T := Self.HasChildNodes; end;

(*----------------------------------------------------------------------------*)
procedure TNodeChildValues_W(Self: TNode; const T: Variant; const t1: Variant);
begin Self.ChildValues[t1] := T; end;

(*----------------------------------------------------------------------------*)
procedure TNodeChildValues_R(Self: TNode; var T: Variant; const t1: Variant);
begin T := Self.ChildValues[t1]; end;

(*----------------------------------------------------------------------------*)
procedure TNodeAttributes_W(Self: TNode; const T: Variant; const t1: string);
begin Self.Attributes[t1] := T; end;

(*----------------------------------------------------------------------------*)
procedure TNodeAttributes_R(Self: TNode; var T: Variant; const t1: string);
begin T := Self.Attributes[t1]; end;

(*----------------------------------------------------------------------------*)
procedure RIRegister_TXMLDoc(CL: TPSRuntimeClassImporter);
begin
  with CL.Add(TXMLDoc) do
  begin
    RegisterConstructor(@TXMLDoc.Create, 'Create');
    RegisterMethod(@TXMLDoc.AddChild, 'AddChild');
    RegisterMethod(@TXMLDoc.CreateElement, 'CreateElement');
    RegisterMethod(@TXMLDoc.CreateNode, 'CreateNode');
    RegisterMethod(@TXMLDoc.GetDocBinding, 'GetDocBinding');
    RegisterMethod(@TXMLDoc.IsEmptyDoc, 'IsEmptyDoc');
    RegisterMethod(@TXMLDoc.LoadFromFile, 'LoadFromFile');
    RegisterMethod(@TXMLDoc.LoadFromStream, 'LoadFromStream');
    RegisterMethod(@TXMLDoc.LoadFromXML, 'LoadFromXML');
    RegisterMethod(@TXMLDoc.Refresh, 'Refresh');
    RegisterMethod(@TXMLDoc.RegisterDocBinding, 'RegisterDocBinding');
    RegisterMethod(@TXMLDoc.Resync, 'Resync');
    RegisterMethod(@TXMLDoc.SaveToFile, 'SaveToFile');
    RegisterMethod(@TXMLDoc.SaveToStream, 'SaveToStream');
    RegisterMethod(@TXMLDoc.SaveToXML, 'SaveToXML');
    RegisterPropertyHelper(@TXMLDocChildNodes_R,nil,'ChildNodes');
    RegisterPropertyHelper(@TXMLDocDocumentElement_R,@TXMLDocDocumentElement_W,'DocumentElement');
    RegisterPropertyHelper(@TXMLDocEncoding_R,@TXMLDocEncoding_W,'Encoding');
    RegisterPropertyHelper(@TXMLDocNode_R,nil,'Node');
    RegisterPropertyHelper(@TXMLDocVersion_R,@TXMLDocVersion_W,'Version');
    RegisterPropertyHelper(@TXMLDocActive_R,@TXMLDocActive_W,'Active');
    RegisterPropertyHelper(@TXMLDocFileName_R,@TXMLDocFileName_W,'FileName');
    RegisterPropertyHelper(@TXMLDocOptions_R,@TXMLDocOptions_W,'Options');
    RegisterPropertyHelper(@TXMLDocParseOptions_R,@TXMLDocParseOptions_W,'ParseOptions');
    RegisterPropertyHelper(@TXMLDocXML_R,@TXMLDocXML_W,'XML');
  end;
end;

(*----------------------------------------------------------------------------*)
procedure RIRegister_TNodeList(CL: TPSRuntimeClassImporter);
begin
  with CL.Add(TNodeList) do
  begin
    RegisterMethod(@TNodeList.Add, 'Add');
    RegisterMethod(@TNodeList.Clear, 'Clear');
    RegisterMethod(@TNodeList.Delete, 'Delete');
    RegisterMethod(@TNodeList.DeleteByName, 'DeleteByName');
    RegisterMethod(@TNodeList.First, 'First');
    RegisterMethod(@TNodeList.FindNode, 'FindNode');
    RegisterMethod(@TNodeList.FindSibling, 'FindSibling');
    RegisterMethod(@TNodeList.Get, 'Get');
    RegisterMethod(@TNodeList.GetNode, 'GetNode');
    RegisterMethod(@TNodeList.GetCount, 'GetCount');
    RegisterMethod(@TNodeList.IndexOf, 'IndexOf');
    RegisterMethod(@TNodeList.IndexOfByName, 'IndexOfByName');
    RegisterMethod(@TNodeList.Insert, 'Insert');
    RegisterMethod(@TNodeList.Last, 'Last');
    RegisterMethod(@TNodeList.Remove, 'Remove');
    RegisterMethod(@TNodeList.ReplaceNode, 'ReplaceNode');
    RegisterPropertyHelper(@TNodeListCount_R,nil,'Count');
    RegisterPropertyHelper(@TNodeListNodes_R,nil,'Nodes');
    RegisterConstructor(@TNodeList.Create, 'Create');
  end;
end;

(*----------------------------------------------------------------------------*)
procedure RIRegister_TNode(CL: TPSRuntimeClassImporter);
begin
  with CL.Add(TNode) do
  begin
    RegisterMethod(@TNode.GetAttributeNodes, 'GetAttributeNodes');
    RegisterMethod(@TNode.GetAttributeNS, 'GetAttributeNS');
    RegisterMethod(@TNode.GetChildNodes, 'GetChildNodes');
    RegisterMethod(@TNode.AddChild, 'AddChild');
    RegisterMethod(@TNode.CloneNode, 'CloneNode');
    RegisterMethod(@TNode.DeclareNamespace, 'DeclareNamespace');
    RegisterMethod(@TNode.FindNamespaceDecl, 'FindNamespaceDecl');
    RegisterMethod(@TNode.FindNamespaceURI, 'FindNamespaceURI');
    RegisterMethod(@TNode.HasAttribute, 'HasAttribute');
    RegisterMethod(@TNode.NextSibling, 'NextSibling');
    RegisterMethod(@TNode.Normalize, 'Normalize');
    RegisterMethod(@TNode.PreviousSibling, 'PreviousSibling');
    RegisterMethod(@TNode.SetAttributeNS, 'SetAttributeNS');
    RegisterConstructor(@TNode.Create, 'Create');
    RegisterPropertyHelper(@TNodeAttributes_R,@TNodeAttributes_W,'Attributes');
    RegisterPropertyHelper(@TNodeChildValues_R,@TNodeChildValues_W,'ChildValues');
    RegisterPropertyHelper(@TNodeHasChildNodes_R,nil,'HasChildNodes');
    RegisterPropertyHelper(@TNodeIsTextElement_R,nil,'IsTextElement');
    RegisterPropertyHelper(@TNodeLocalName_R,nil,'LocalName');
    RegisterPropertyHelper(@TNodeNamespaceURI_R,nil,'NamespaceURI');
    RegisterPropertyHelper(@TNodeNodeName_R,nil,'NodeName');
    RegisterPropertyHelper(@TNodeNodeType_R,nil,'NodeType');
    RegisterPropertyHelper(@TNodeNodeValue_R,@TNodeNodeValue_W,'NodeValue');
    RegisterPropertyHelper(@TNodeParentNode_R,nil,'ParentNode');
    RegisterPropertyHelper(@TNodePrefix_R,nil,'Prefix');
    RegisterPropertyHelper(@TNodeReadOnly_R,@TNodeReadOnly_W,'ReadOnly');
    RegisterPropertyHelper(@TNodeText_R,@TNodeText_W,'Text');
    RegisterPropertyHelper(@TNodeXML_R,nil,'XML');
    RegisterPropertyHelper(@TNodeAttributeNodes_R,nil,'AttributeNodes');
    RegisterPropertyHelper(@TNodeChildNodes_R,nil,'ChildNodes');
  end;
end;

(*----------------------------------------------------------------------------*)
procedure RIRegister_XMLDocument(CL: TPSRuntimeClassImporter);
begin
  with CL.Add(TNodeList) do
  with CL.Add(TXMLDoc) do
  RIRegister_TNode(CL);
  RIRegister_TNodeList(CL);
  RIRegister_TXMLDoc(CL);
end;



{ TPSImport_XMLDocument }
(*----------------------------------------------------------------------------*)
procedure TPSImport_XMLDocument.CompileImport1(CompExec: TPSScript);
begin
  SIRegister_XMLDocument(CompExec.Comp);
end;
(*----------------------------------------------------------------------------*)
procedure TPSImport_XMLDocument.ExecImport1(CompExec: TPSScript; const ri: TPSRuntimeClassImporter);
begin
  RIRegister_XMLDocument(ri);
end;
(*----------------------------------------------------------------------------*)


end.
