Delphi-Kylix
  Home arrow Delphi-Kylix arrow Delphi Wrapper Classes and XML
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
DELPHI-KYLIX

Delphi Wrapper Classes and XML
By: David Web
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2008-11-17

    Table of Contents:
  • Delphi Wrapper Classes and XML
  • XML Properties, Methods, and Interface
  • A Demonstration
  • Second Part of Code

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Delphi Wrapper Classes and XML


    (Page 1 of 4 )

    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.

    Below is a listing of the xmlintf unit that we discussed in the previous article. It is one of the main XML units that form part of the wrapper classes in Delphi. I will only show the functions, procedures and properties definitions and not their implementation, because it would fill the entire article if I did:


    unit XMLIntf;


    interface


    {$IFDEF MSWINDOWS}

    { MSXML.H defines another IXMLDocument and references the type...

    The compiler must see this before it sees the IXMLDocument

    introduced in this unit - otherwise, references will cause

    ambiguity errors }

    (*$HPPEMIT '#include <msxml.h>' *)

    {$ENDIF}


    uses SysUtils, Classes, xmldom;


    type


    { Data types }


    TNodeType = (ntReserved, ntElement, ntAttribute, ntText, ntCData,

    ntEntityRef, ntEntity, ntProcessingInstr, ntComment, ntDocument,

    ntDocType, ntDocFragment, ntNotation);


    { Forward Declarations }


    IXMLNode = interface;

    IXMLNodeList = interface;

    IXMLNodeCollection = interface;

    IXMLDocument = interface;


    { EXMLDocError }


    EXMLDocError = class(Exception)

    end;


    { IXMLNode }


    IXMLNode = interface

    ['{395950C0-7E5D-11D4-83DA-00C04F60B2DD}']

    { Property Accessors }

    function GetAttribute(const AttrName: DOMString): OleVariant;

    function GetAttributeNodes: IXMLNodeList;

    function GetChildNodes: IXMLNodeList;

    function GetChildValue(const IndexOrName: OleVariant): OleVariant;

    function GetCollection: IXMLNodeCollection;

    function GetDOMNode: IDOMNode;

    function GetHasChildNodes: Boolean;

    function GetIsTextElement: Boolean;

    function GetLocalName: DOMString;

    function GetNamespaceURI: DOMString;

    function GetNodeName: DOMString;

    function GetNodeType: TNodeType;

    function GetNodeValue: OleVariant;

    function GetOwnerDocument: IXMLDocument;

    function GetParentNode: IXMLNode;

    function GetPrefix: DOMString;

    function GetReadOnly: Boolean;

    function GetText: DOMString;

    function GetXML: DOMString;

    procedure SetAttribute(const AttrName: DOMString; const Value: OleVariant);

    procedure SetChildValue(const IndexOrName: OleVariant; const Value: OleVariant);

    procedure SetNodeValue(const Value: OleVariant);

    procedure SetReadOnly(const Value: Boolean);

    procedure SetText(const Value: DOMString);

    { Methods }

    function AddChild(const TagName: DOMString; Index: Integer = -1): IXMLNode; overload;

    function AddChild(const TagName, NamespaceURI: DOMString;

    GenPrefix: Boolean = False; Index: Integer = -1): IXMLNode; overload;

    function CloneNode(Deep: Boolean): IXMLNode;

    procedure DeclareNamespace(const Prefix, URI: DOMString);

    function FindNamespaceURI(const TagOrPrefix: DOMString): DOMString;

    function FindNamespaceDecl(const NamespaceURI: DOMString): IXMLNode;

    function GetAttributeNS(const AttrName, NamespaceURI: DOMString): OleVariant;

    function HasAttribute(const Name: DOMString): Boolean; overload;

    function HasAttribute(const Name, NamespaceURI: DOMString): Boolean; overload;

    function NextSibling: IXMLNode;

    procedure Normalize;

    function PreviousSibling: IXMLNode;

    procedure Resync;

    procedure SetAttributeNS(const AttrName, NamespaceURI: DOMString; const Value: OleVariant);

    procedure TransformNode(const stylesheet: IXMLNode; var output: WideString); overload;

    procedure TransformNode(const stylesheet: IXMLNode; const output: IXMLDocument); overload;


    The functions and procedures above define some of the elements that make up the wrapper class. Below are the properties and attributes of the class:

    { Properties }

    property Attributes[const AttrName: DOMString]: OleVariant read GetAttribute write SetAttribute;

    property AttributeNodes: IXMLNodeList read GetAttributeNodes;

    property ChildNodes: IXMLNodeList read GetChildNodes;

    property ChildValues[const IndexOrName: OleVariant]: OleVariant read GetChildValue write SetChildValue; default;

    property Collection: IXMLNodeCollection read GetCollection;

    property DOMNode: IDOMNode read GetDOMNode;

    property OwnerDocument: IXMLDocument read GetOwnerDocument;

    property HasChildNodes: Boolean read GetHasChildNodes;

    property IsTextElement: Boolean read GetIsTextElement;

    property LocalName: DOMString read GetLocalName;

    property NamespaceURI: DOMString read GetNameSpaceURI;

    property NodeName: DOMstring read GetNodeName;

    property NodeType: TNodeType read GetNodeType;

    property NodeValue: OleVariant read GetNodeValue write SetNodeValue;

    property ParentNode: IXMLNode read GetParentNode;

    property Prefix: DOMString read GetPrefix;

    property ReadOnly: Boolean read GetReadOnly write SetReadOnly;

    property Text: DOMString read GetText write SetText;

    property XML: DOMString read GetXML;

    end;


    { IXMLNodeList }


    Below I've defined the interface to the XML wrapper class. It will be used by the other classes and units to interface. The methods and properties are also defined:

    IXMLNodeList = interface

    ['{395950C1-7E5D-11D4-83DA-00C04F60B2DD}']

    { Property Accessors }

    function GetCount: Integer;

    function GetNode(const IndexOrName: OleVariant): IXMLNode;

    function GetUpdateCount: Integer;

    { Methods }

    function Add(const Node: IXMLNode): Integer;

    procedure BeginUpdate;

    procedure Clear;

    function Delete(const Index: Integer): Integer; overload;

    function Delete(const Name: DOMString): Integer; overload;

    function Delete(const Name, NamespaceURI: DOMString): Integer; overload;

    procedure EndUpdate;

    function First: IXMLNode;

    function FindNode(NodeName: DOMString): IXMLNode; overload;

    function FindNode(NodeName, NamespaceURI: DOMString): IXMLNode; overload;

    function FindNode(ChildNodeType: TGuid): IXMLNode; overload;

    function FindSibling(const Node: IXMLNode; Delta: Integer): IXMLNode;

    function Get(Index: Integer): IXMLNode;

    function IndexOf(const Node: IXMLNode): Integer; overload;

    function IndexOf(const Name: DOMString): Integer; overload;

    function IndexOf(const Name, NamespaceURI: DOMString): Integer; overload;

    procedure Insert(Index: Integer; const Node: IXMLNode);

    function Last: IXMLNode;

    function Remove(const Node: IXMLNode): Integer;

    function ReplaceNode(const OldNode, NewNode: IXMLNode): IXMLNode;

    { Properties }

    property Count: Integer read GetCount;

    property Nodes[const IndexOrName: OleVariant]: IXMLNode read GetNode; default;

    property UpdateCount: Integer read GetUpdateCount;

    end;


    The XMLnode collection interface is then created:


    { IXMLNodeCollection }


    IXMLNodeCollection = interface(IXMLNode)

    ['{395950C2-7E5D-11D4-83DA-00C04F60B2DD}']

    { Property Accessors }

    function GetCount: Integer;

    function GetNode(Index: Integer): IXMLNode;

    { Public properties }

    procedure Clear;

    procedure Delete(Index: Integer);

    function Remove(const Node: IXMLNode): Integer;

    property Count: Integer read GetCount;

    property Nodes[Index: Integer]: IXMLNode read GetNode; default;

    end;

    More Delphi-Kylix Articles
    More By David Web


     

    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...







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
    Stay green...Green IT