Home arrow Delphi-Kylix arrow Page 2 - Delphi Wrapper Classes and XML
DELPHI-KYLIX

Delphi Wrapper Classes and XML


In this article we will look at a partial listing of the xmlintf unit and then write a program to demonstrate how to use DOM in Delphi. We began our discussion of this topic in the previous article. This is part three of a four-part series.

Author Info:
By: David Web
Rating: 5 stars5 stars5 stars5 stars5 stars / 7
November 17, 2008
TABLE OF CONTENTS:
  1. · Delphi Wrapper Classes and XML
  2. · XML Properties, Methods, and Interface
  3. · A Demonstration
  4. · Second Part of Code

print this article
SEARCH DEVARTICLES

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.


blog comments powered by Disqus
DELPHI-KYLIX ARTICLES

- Loading an XML Document into the DOM
- Delphi Wrapper Classes and XML
- Delphi and the DOM
- Delphi and XML
- Internet Access: Client Service
- Finishing the Client for an Internet Access ...
- The Client for an Internet Access Control Ap...
- User Management for an Internet Access Contr...
- Important Procedures for an Internet Access ...
- Server Code for an Internet Access Control A...
- Constructing the Interface for an Internet A...
- Building a Server Application for an Interne...
- Building an Internet Access Control Applicat...
- Client Dataset: Working with Data Packets an...
- Using the Client Dataset in an N-Tiered Appl...

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials