Delphi Wrapper Classes and XML - XML Properties, Methods, and Interface (Page 2 of 4 )
The XML document properties, methods and interface are then defined. The functions help us to manipulate the document elements.
{ IXMLDocument }
TXMLDocOption = (doNodeAutoCreate, doNodeAutoIndent, doAttrNull,
doAutoPrefix, doNamespaceDecl, doAutoSave);
TXMLDocOptions = set of TXMLDocOption;
TParseOption = (poResolveExternals, poValidateOnParse, poPreserveWhiteSpace,
poAsyncLoad);
TParseOptions = set of TParseOption;
TXMLEncodingType = (xetUnknown, xetUCS_4BE, xetUCS_4LE, xetUCS_4Order2134,
xetUCS_4Order3412, xetUTF_16BE, xetUTF_16LE, xetUTF_8, xetUCS_4Like,
xetUTF_16BELike, xetUTF_16LELike, xetUTF_8Like, xetEBCDICLike);
IXMLDocument = interface(IInterface)
['{395950C3-7E5D-11D4-83DA-00C04F60B2DD}']
{ Property Accessors }
function GetActive: Boolean;
function GetAsyncLoadState: Integer;
function GetChildNodes: IXMLNodeList;
function GetDocumentElement: IXMLNode;
function GetDocumentNode: IXMLNode;
function GetDOMDocument: IDOMDocument;
function GetEncoding: DOMString;
function GetFileName: DOMString;
function GetModified: Boolean;
function GetNodeIndentStr: DOMString;
function GetOptions: TXMLDocOptions;
function GetParseOptions: TParseOptions;
function GetSchemaRef: DOMString;
function GetStandAlone: DOMString;
function GetVersion: DOMString;
function GetXML: TStrings;
procedure SetActive(const Value: Boolean);
procedure SetDocumentElement(const Value: IXMLNode);
procedure SetDOMDocument(const Value: IDOMDocument);
procedure SetEncoding(const Value: DOMString);
procedure SetFileName(const Value: DOMString);
procedure SetNodeIndentStr(const Value: DOMString);
procedure SetOptions(const Value: TXMLDocOptions);
procedure SetParseOptions(const Value: TParseOptions);
procedure SetStandAlone(const Value: DOMString);
procedure SetVersion(const Value: DOMString);
procedure SetXML(const Value: TStrings);
The methods of the XML document object are defined here. You will recognize some of them in the application that we will build later on:
{ Methods }
function AddChild(const TagName: DOMString): IXMLNode; overload;
function AddChild(const TagName, NamespaceURI: DOMString): IXMLNode; overload;
function CreateElement(const TagOrData, NamespaceURI: DOMString): IXMLNode;
function CreateNode(const NameOrData: DOMString;
NodeType: TNodeType = ntElement; const AddlData: DOMString = ''): IXMLNode;
function GeneratePrefix(const Node: IXMLNode): DOMString;
function GetDocBinding(const TagName: DOMString;
DocNodeClass: TClass; NamespaceURI: DOMString = ''): IXMLNode;
function IsEmptyDoc: Boolean;
procedure LoadFromFile(const AFileName: DOMString);
procedure LoadFromStream(const Stream: TStream; EncodingType:
TXMLEncodingType = xetUnknown);
procedure LoadFromXML(const XML: string); overload;
procedure LoadFromXML(const XML: DOMString); overload;
procedure Refresh;
procedure RegisterDocBinding(const TagName: DOMString;
DocNodeClass: TClass; NamespaceURI: DOMString = '');
procedure Resync;
procedure SaveToFile(const AFileName: DOMString);
procedure SaveToStream(const Stream: TStream);
procedure SaveToXML(var XML: DOMString); overload;
procedure SaveToXML(var XML: string); overload;
procedure SetOnAsyncLoad(const Value: TAsyncEventHandler);
The properties of the document object are defined here. Again, you will notice some of them in the application that we will build shortly:
{ Properties }
property Active: Boolean read GetActive write SetActive;
property AsyncLoadState: Integer read GetAsyncLoadState;
property ChildNodes: IXMLNodeList read GetChildNodes;
property DocumentElement: IXMLNode read GetDocumentElement write SetDocumentElement;
property DOMDocument: IDOMDocument read GetDOMDocument write SetDOMDocument;
property Encoding: DOMString read GetEncoding write SetEncoding;
property FileName: DOMString read GetFileName write SetFileName;
property Modified: Boolean read GetModified;
property Node: IXMLNode read GetDocumentNode;
property NodeIndentStr: DOMString read GetNodeIndentStr write SetNodeIndentStr;
property Options: TXMLDocOptions read GetOptions write SetOptions;
property ParseOptions: TParseOptions read GetParseOptions write SetParseOptions;
property SchemaRef: DOMString read GetSchemaRef;
property StandAlone: DOMString read GetStandAlone write SetStandAlone;
property Version: DOMString read GetVersion write SetVersion;
property XML: TStrings read GetXML write SetXML;
end;
Some constants are then declared that will be used in the implementation of the unit:
const
NodeTypeNames: array[TNodeType] of string = { Do not localize }
('', 'Element','Attribute','Text','CDATASection', 'EntityRef','Entity',
'ProcessingInstr', 'Comment','Document','DocumentType',
'DocumentFragment','Notation');
implementation
end.
Please enable JavaScript to view the comments powered by Disqus. blog comments powered by