ColdFusion
  Home arrow ColdFusion arrow Page 4 - CFXML: Probing XMLDOM in ColdFusion
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 
Sun Developer Network 
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? 
COLDFUSION

CFXML: Probing XMLDOM in ColdFusion
By: Jayaram Krishnaswamy
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 3
    2006-04-03

    Table of Contents:
  • CFXML: Probing XMLDOM in ColdFusion
  • Create a ColdFusion Object Using the Microsoft.XMLDOM Class
  • On accessing a structure
  • How do we get to the attributes?
  • How do we get at the Comment node?

  • 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


    CFXML: Probing XMLDOM in ColdFusion - How do we get to the attributes?


    (Page 4 of 5 )

    You dig a little deeper to get the attributes, which are also represented as a structure in ColdFusion as follows. Here I am trying to locate the attribute of the first child of the root element.

    <cffile action="read" file="C:\Inetpub\wwwroot\webstudents.xml"
    variable="xmldoc">
    <cfset mydoc = XmlParse(xmldoc)>
    <cfset rootchild1=#mydoc.xmlroot.xmlchildren[1].XMLAttributes#>
    <cfdump var="#rootchild1#">
    

    The display for the above snippet will come out as shown below:

    It is also possible to navigate through the document using the element names as shown in the following example.

    <cffile action="read" file="C:\Inetpub\wwwroot\webstudents.xml"
    variable="xmldoc">
    <cfset mydoc = XmlParse(xmldoc)>
    <cfset childs=#mydoc.XMLRoot.student.XMLChildren#>
    <cfdump var="#childs#">
    

    The result shows that it picks the first student node it finds as shown below.

    Can we home in on a named node?

    If you look at the above picture you will see that individual items for the student node can be picked out as shown below.

    <cfset mydoc = XmlParse(xmldoc)>
    <cfset childsChild1=#mydoc.XMLRoot.student.XMLChildren[1].XMLName#>
    <cfoutput>
    mydoc.XMLRoot.student.XMLChildren[1].XMLName=
    #childsChild1#
    </cfoutput>
    <br/>
    <cfset childsChild2=#mydoc.XMLRoot.student.XMLChildren[2].XMLName#>
    <cfoutput>
    mydoc.XMLRoot.student.XMLChildren[2].XMLName=
    #childsChild2#
    </cfoutput>
    <br/>
    <cfset childsChild1t=#mydoc.XMLRoot.student.XMLChildren[1].XMLText#>
    <cfoutput>
    mydoc.XMLRoot.student.XMLChildren[1].XMLText=
    #childsChild1t#
    </cfoutput>
    <br/>
    <cfset childsChild2t=#mydoc.XMLRoot.student.XMLChildren[2].XMLText#>
    <cfoutput>
    mydoc.XMLRoot.student.XMLChildren[2].XMLText=
    #childsChild2t#
    </cfoutput>
    

    The above code will display the following on the browser.

    How can we then access the individual students? Well, it is an extension of the same idea. We have to closely follow the Macromedia documentation to delineate the details as shown below for the second child of the root element. With more than one way to access, and with syntaxes that are quite different, it can be quite confusing, although it adds to flexibility.

    <cffile action="read" file="C:\Inetpub\wwwroot\webstudents.xml"
    variable="xmldoc">
    <cfset mydoc = XmlParse(xmldoc)>
    <cfset rootchild2=#mydoc.xmlroot.xmlchildren[2]#>
    <cfdump var="#rootchild2#">
    

    This will show the structure of the second student node as shown below.

    More ColdFusion Articles
    More By Jayaram Krishnaswamy


       · The tutorial discusss two ways to access an XML document using ColdFusion. The...
     

    COLDFUSION ARTICLES

    - How to Access a SQL Anywhere Database with C...
    - CFXML: Probing XMLDOM in ColdFusion
    - Creating a Web Service with ColdFusion: the ...
    - CFAjax: What it is and How to Use it
    - Querying SQL 2000 Server from ColdFusion
    - Introduction to ColdFusion Markup Language, ...
    - Introduction to ColdFusion Markup Language
    - Databases and Dreamweaver MX 2004, concluded
    - Databases and Dreamweaver MX 2004
    - Welcome to Coldfusion MX 6.1, concluded
    - Welcome to Coldfusion MX 6.1
    - What You Must Know About ColdFusion Flow-Con...
    - What You Must Know About Operators in ColdFu...
    - Everything You Must Know About ColdFusion Va...
    - My First Application on ColdFusion MX Server






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