XML Tutorial

This is a method for reading in variables and constants from an XML file. In this example, we are reading them in to the application scope. This can be useful for sharing variables across applications or servers, and to keep things organized.

Take the following XML file with some application constants.


Take the following Application.cfm (set the XMLPath to be the location of your XML file):

<cfapplication name="myApp" applicationtimeout="20">

<cfif not(isDefined("application.vars.dsn")) or isDefined("url.flush")>
	<cfset XMLpath =U:\CFusionMX\wwwroot\tutorial\myXMLFile.xml">
	<cffile action="read" file="#XMLpath#" variable="x">
	<cfset x = xmlparse(x)>
	<cfset var_array="#x.myApplication.xmlchildren#"> 
	<cfloop from="1" to="#arraylen(var_array)#" index="i">
			<cfset var_name = var_array[i].xmlname>
			<cfset "application.vars.#var_name#" = #var_array[i].xmltext#> 

If application.vars.dsn is not defined or we pass in url.flush to a page in our application, the code will parse the XML file and assign application variables accordingly. The url.flush mechanism is a handy way to reflect changes in the XML file without waiting for the application to timeout or a server reboot.

If you <cfdump var="#application.vars#">, you will see the two application variables defined in the XML file.

About This Tutorial
Author: Redmanz
Skill Level: Beginner 
Platforms Tested: CF5
Total Views: 116,516
Submission Date: November 23, 2002
Last Update Date: June 05, 2009
All Tutorials By This Autor: 6
Discuss This Tutorial
  • Hashmi herbs indian supplier botanical herbal products natural exporter medicinal manufacturer seeds raw product unani herbs ayurved.

  • unaniherbalist company ayurved company natural Remedies Raw Herbs herbal exporter botanical indian manufacturer spices.

  • Alternatice herbal medicine Manufacturers and exporters of Unani, Herbal and Ayurvedic medicines experienced Unani

  • Penis enlargement, Penis Enhancement, big penis, large penis ,largest

  • "piles pile herbal unani product formula guaranted piles health, indigestion, piles reduce haemorrhoids bawasir hyper acidity, lever, disorder, constipation chronic cought ,Unani

  • Penis enlargement, Penis Enhancement, big penis, large penis ,largest penis ,length of penis,penis,

  • -------------------------------------- #evaluate(url.keyword)# #PreserveSingleQuotes(quer)#

    BGAmaker History

    menu pitchcolumn BC1 pitchrow ballmil SLD
    #pitchhistory.menu# #pitchhistory.pitchcolumn# #pitchhistory.BC1# #pitchhistory.pitchrow# #pitchhistory.ballmil# #pitchhistory.SLD#
    #pitchhistory.menu# #pitchhistory.pitchcolumn# #pitchhistory.BC1# #pitchhistory.pitchrow# #pitchhistory.ballmil# #pitchhistory.SLD#


    ---------------------------- if i use method=get it works fine but, i need post ,i dont want my variables to shown in URl , help

  • I tried to use the codes given. Once I upload it to server. It keeps giving me the error. I have cut copied and pasted the the error. please help Element ADDY is undefined in URL. The error occurred in D:\Webserver\j12h1.com\www\test\cfpage.cfm: line 11 9 :
    10 : Today's date is #DateFormat(Now())# 11 : 12 :

  • Good Job!

  • Hello I have several url variables, but when i try to add them to the emailed like, the first one just appear. does this have anything to do with the urlTOKEN.


Website Designed and Developed by Pablo Varando.