Delphi-Kylix
  Home arrow Delphi-Kylix arrow Page 2 - Loading an XML Document into 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

Loading an XML Document into the DOM
By: David Web
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 2
    2008-11-24

    Table of Contents:
  • Loading an XML Document into the DOM
  • Code Explained
  • Adding Nodes
  • Checking the file

  • 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


    Loading an XML Document into the DOM - Code Explained


    (Page 2 of 4 )


    The aim of the program is to make it easy for us to manipulate XML documents. This process starts by loading or opening up an XML document. Naturally this will be the first step that this code will take.

    Below is the procedure that does just that. The first part of this procedure defines an initial path for the application using the application.exename function:


    procedure TForm1.Button1Click(Sender: TObject);

    begin

    od.InitialDir := ExtractFilePath (Application.ExeName);


    Then we execute the opendialog component. This component will open up a dialog window that will enable you to choose an XML file to open:


    if od.Execute then

    begin


    Once you've selected a file, you load it into the xmldocument component. The file, up to this point, would have been stored in the opendialog components filename property.


    xd.LoadFromFile(od.FileName);


    The next line of code clears the treeview control in which we want to load the XML document:


    tv.Items.Clear;


    Then we call the DOMShow procedure that actually does the job of loading the XML document into the relevant treeview together with its structure:


    DOMShow (xd.DocumentElement, nil);

    tv.FullExpand;

    end;


    end;


    The DOMShow procedure is at the heart of the entire program. It is responsible for loading, reading and organizing the structure of the XML document. It is also responsible for showing it in the treeview control:


    procedure TForm1.DOMShow(Anode: IXMLNode; TNode: TTreeNode);



    First, we define some variables that we are going to need throughout this procedure:



    var

    I: Integer;

    NTNode: TTreeNode;

    NText: string;

    AttrNode: IXMLNode;






    begin

    We then skip text nodes and other special cases:

    if not (Anode.NodeType = ntElement) then

    Exit;



    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
    Stay green...Green IT