Delphi-Kylix
  Home arrow Delphi-Kylix arrow Page 2 - Delphi and the DOM
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 and the DOM
By: David Web
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 3
    2008-11-10

    Table of Contents:
  • Delphi and the DOM
  • Coding with the DOM in Delphi
  • XMLDOM.pas Unit continued
  • Even More XMLDOM.pas Unit

  • 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 and the DOM - Coding with the DOM in Delphi


    (Page 2 of 4 )

    The tree-like structure of an XML document makes it a fantastic fit in memory; this is exactly what the DOM is good for. It is a standard interface, so when you have written code that uses a DOM, you can switch DOM implementations without changing your source code. One of the most commonly used DOM engines on Windows is the one provided by Microsoft as part of the MSXML SDK, and also installed by Internet Explorer and many other Microsoft applications.Other DOM engines that are available in Delphi7 include Apache Foundation's Xerces and the open-source OpenXML.

    Delphi embeds the DOM implementation into a component called XMLdocument. The idea behind using this component is that you remain independent from the implementation and can work with some simplified methods or helpers. You will probably want to work with these because the DOM interface is very complex to use.

    A document is a collection of nodes, each having a name, a text element, a collection of attributes, and a collection of child nodes. Each collection of nodes lets you access elements by position or search for them by name. Notice that the text within the tags of a node, if any, is rendered as a child of that node and listed in its collection of child nodes. The root nodes have some extra methods for creating new nodes, values or attributes.

    Delphi's XMLDocument components gives you two levels to work on:

    • At the lower level you are able to use the DOMDocument property to access a standard W3C Document Object Model Interface. The Official DOM is defined in the xmldom unit and includes interfaces such as IDOMNode, IDOMNodeList, IDOMAttr, IDOMElement, and IDOMText. With these DOM interfaces, Delphi supports a lower-level, but standard programming model. The DOM implementation is indicated by the XMLDocument component in the DOMVendor property.

    • As a higher-level alternative, the XMLDocument component also implements the IXMLDocument interface. This is a custom DOM-like API defined by Borland in the XMLintf unit, and comprising interfaces like XMLNode, XMLNodeList, and XMLNodeCollection. This Borland interface simplifies some of the DOM operations by replacing multiple method calls, which are repeated often in sequence, with a single property or method.

    Below is a partial listing of the XMLDOM.pas unit:


    Unit xmldom;


    interface


    uses

    {$IFDEF MSWINDOWS}

    Windows, ActiveX,

    {$ENDIF}

    {$IFDEF LINUX}

    Types,

    {$ENDIF}

    SysUtils, Variants, Classes, XMLConst;


    const


    { Wrapper Versioning }


    DOMWrapperVersion = 1.2;

     

    { NodeType Values }


    ELEMENT_NODE = 1;

    ATTRIBUTE_NODE = 2;

    TEXT_NODE = 3;

    CDATA_SECTION_NODE = 4;

    ENTITY_REFERENCE_NODE = 5;

    ENTITY_NODE = 6;

    PROCESSING_INSTRUCTION_NODE = 7;

    COMMENT_NODE = 8;

    DOCUMENT_NODE = 9;

    DOCUMENT_TYPE_NODE = 10;

    DOCUMENT_FRAGMENT_NODE = 11;

    NOTATION_NODE = 12;


    { ExceptionCode Values }


    INDEX_SIZE_ERR = 1;

    DOMSTRING_SIZE_ERR = 2;

    HIERARCHY_REQUEST_ERR = 3;

    WRONG_DOCUMENT_ERR = 4;

    INVALID_CHARACTER_ERR = 5;

    NO_DATA_ALLOWED_ERR = 6;

    NO_MODIFICATION_ALLOWED_ERR = 7;

    NOT_FOUND_ERR = 8;

    NOT_SUPPORTED_ERR = 9;

    INUSE_ATTRIBUTE_ERR = 10;

    INVALID_STATE_ERR = 11; { DOM Level 2 }

    SYNTAX_ERR = 12; { DOM Level 2 }

    INVALID_MODIFICATION_ERR = 13; { DOM Level 2 }

    NAMESPACE_ERR = 14; { DOM Level 2 }

    INVALID_ACCESS_ERR = 15; { DOM Level 2 }


    const

    NSDelim = ':';

    SXML = 'xml';

    SVersion = 'version';

    SEncoding = 'encoding';

    SStandalone = 'standalone';

    SXMLNS = 'xmlns';

    SHttp = 'http:/';

    SXMLNamespaceURI = SHttp+'/www.w3.org/2000/xmlns/';

    SXMLPrefixNamespaceURI = SHttp+'/www.w3.org/XML/1998/namespace';


    type


    { Misc. Types }


    DOMNodeType = Word;

    {$EXTERNALSYM DOMNodeType}

    DOMString = WideString;

    {$EXTERNALSYM DOMString}

    DOMTimeStamp = Int64;


    { Forward Declarations }


    IDOMImplementation = interface;

    IDOMNode = interface;

    IDOMNodeList = interface;

    IDOMNamedNodeMap = interface;

    IDOMCharacterData = interface;

    IDOMAttr = interface;

    IDOMElement = interface;

    IDOMText = interface;

    IDOMComment = interface;

    IDOMCDATASection = interface;

    IDOMDocumentType = interface;

    IDOMNotation = interface;

    IDOMEntity = interface;

    IDOMEntityReference = interface;

    IDOMProcessingInstruction = interface;

    IDOMDocumentFragment = interface;

    IDOMDocument = interface;

    { DOM Extensions }

    IDOMNodeEx = interface;

    IDOMPersist = interface;

    IDOMParseError = interface;


    { DOMException }


    DOMException = class(Exception)

    public

    code: Word;

    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 6 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek