Monday, July 20, 2009
ColdFusion Program to Read XML File
With XML, a structural model of the data in a file can be encoded along with the data. The structure can be as simple as name and phone or much more complex, with fields like name and phone embedded in other fields like employee. A style sheet, an XSL, can be used to transform the tagged data in an XML file into a Web page. Likewise, a schema file, an XSD, can communicate database information in database operations.
ColdFusion provides a subset of functions that enable a programmer to operate on XML files. A typical operation would be to read an XML file, work on it and write it, perhaps to a database. A datatype in ColdFusion has been created for XML and is known as the XML document object. By doing this, Adobe extends the reach of its already existing ColdFusion structure functions to encompass XML data as well.
Structures consist of objects, properties, and objects embedded in other objects. Name and phone embedded in employee is an example. The dot operator is used to delimit what object in a structure you want to access. The general syntax is <object>.<object>, <object>.<property>. These can be combined to get for instance <object>.<child object>.<property>, so to access my phone number, we would use the dot operator: <employee>.<phone>
The following ColdFusion code uses some of the XML functions to read an XML file. It starts by validating the XML data file to ensure that it is consistent with its schema.
<cfset myResults= XMLValidate ("wits.xml", "wits.xsd")>
<cfoutput> Is Valid? #myResults.status#!
</cfoutput>
Next, a file handle is obtained.
<cffile variable="gmrXML" file=" “wits.xml" action="read">
Then we get a ColdFusion XML Document Object datatype using our file handle and the xmlParse() function:
<cfset myxml=" xmlParse(gmrXML)">
Now we are ready to loop through the data, and display different field values. This test file consists of a series of incidents embedded in an incident list. In addition to its own properties, an incident will have an embedded list, or object, of one or more incident types. In addition to this, it will have, an embedded facilities list, of zero or more facilities involved in the incident. These embedded lists correspond to embedded objects or to child tables in a database.
<cfoutput>
<cfloop index="i" from="1" to="#arrayLen(myXML.incidentList.Incident)#">
Incident<br>
#myXml.incidentlist.incident[i].ICN#<br>
#myXml.incidentlist.incident[i].Subject#<br>
#myXml.incidentlist.incident[i].Summary#<br>
#myXml.incidentlist.incident[i].IncidentDate#<br>
Event Type<br>
<!---Here is an inner loop to get all Event Types for the Incident--->
<cfloop index="j" from="1" to=
"#arrayLen(myXML.incidentList.Incident[i]. EventTypeList.EventType)#">
#myXml.incidentlist.incident[i].EventTypeList.EventType[j]#<br>
</cfloop>
<br>Facilities<br>
<cfif StructKeyExists(myXml.incidentlist.incident[i].FacilityList,"Facility")>
<!---Here is an inner loop to get all Facilities for the Incident--->
<cfloop index="j" from="1" to
"#arrayLen(myXML.incidentList.Incident[i]. FacilityList.Facility)#">
#myXml.incidentlist.incident[i].FacilityList.Facility[j].FacilityType#<br>
#myXml.incidentlist.incident[i].FacilityList.Facility[j].Indicator#<br>
</cfloop>
<cfelse>
No facility for this one
</cfif>
</cfloop>
</cfoutput>
The ColdFusion arraylen is used in the “To” parameter of our loop to return the number of Incidents in this incidentlist. There is one incidentlist per file. Our dot operator starts with the file handle, then refers to the incidentlist we know to be in file (because we validated), and the particular incident is referenced with our index variable [i]:
myXml.incidentlist.incident[i].ICN
The incident number property, ICN, is accessed from the record just read from the file. For EventType, it is very similar. Since we know we will have at least one Event Type in every incident (one or more), the following code is sufficient:
myXml.incidentlist.incident[i].EventTypeList.EventType[j]
On the other hand, we may not have a facility (zero or more) and will get a null pointer exception if we try to dereference a facility in an empty facilitylist. We need to use the ColdFusion StructKeyExists function to test if a facility object is embedded in the facilitylist for the current record.
<cfif StructKeyExists(myXml.incidentlist.incident[i].FacilityList,"Facility")>
If so, then we loop through the facilities involved in the incident, else we indicate no facility.
Sunday, September 7, 2008
Data Warehouse Support in Crisis Management
Duncan (2005, pp 562-3) recommends a crisis management plan be in place before a critical event strikes so the company is not improvising while the media and public are expecting a well-reasoned response. He says the plan should address the following elements:
- Internal notification list
- Roles and responsibilities
- Who is assigned to address communications with each separate public
- Who is authorized to talk to the press
- General guidelines on what to say
- Examples of discussion that has legal implications
- General actions for different scenarios
Adelman (2003, p 16) describes the very beneficial use of data warehouses and business intelligence during crisis or issue management. Data warehouses can help upper management answer questions related to the crisis or issue. Too many times they are put on the spot, and end up doing a song-and-dance in front of the press instead of dealing with facts. Without a data warehouse it is more difficult to find information on the background and/or to justify a course of action.
It’s important to investors, to employees, to customers, and the other relevant publics that management acts in an informed manner. Too often they appear unaware of the situation. Here IT can help.
A prime example of successfully handling a crisis is the well-known Diet Pepsi case (see crisispublicrelations blog for background). Diet Pepsi ran into trouble when consumers began “finding” foreign objects in cans of Diet Pepsi. A variety of different objects were found including a syringe, a bullet, and even a crack cocaine vial. The corporation knew that there was no possible way for these objects to be inserted during the bottling process. As a result, Diet Pepsi used a defensive strategy claiming its innocence. They communicated openly with the public, attacked the accusers, and allowed their bottling process to be shown on the news. Temporary damage had been done to Diet Pepsi, but they quickly rebounded from the situation.
Many believe the “victims” tried hoodwinking their way to prosperity.
According to Mansky,
“Because Pepsi took immediate action to create a crisis communications plan that involved several departments and focused on four key principles, it was able to resolve the crisis while defending its position and upholding its reputation. Pepsi’s plan included specific goals and objectives, targeted four precise publics and was the result of valuable research, all which helped it to be successful. The support of the FDA as an intervening public was also crucial for Pepsi’s success in this case.”
References
Adelman, Sid (2003). Measuring Data Warehouse Return on Investment. Retrieved on April 16, 2008 from http://www.teradata.com/t/pdf.aspx?a=83673&b=86833
Duncan, Tom (2005). Principles of Advertising and IMC. New York: McGraw-Hill Irwin.
Mansky, Amy (2003). There’s a Syringe in my Pepsi Can. Retrieved on April 17, 2008 from http://www.unc.edu/~mansky/J131casebrief2.pdf
Friday, September 5, 2008
My Coke Rewards
"Coke has invested in the collection and mining of consumer information. This data is already fueling customization on the site, and is also being used for e-mail and mobile promotions and other types of communication."Coke is using Enterprise Decision Management (EDM) software with its new data store to automate operational decisions concerning promotional activities. Radan and Taylor (2008, ¶ 3) describe EDM as a new approach, that integrates Business Intelligence data analysis with business processes, combining operational and analytical processing. This is in contrast to the separation of data from business process inherent in data warehousing.
EDM is avant-garde and Coke is being applauded for its vision and mastery (see EDM Blog). Taylor (2007, ¶ 2) notes that data generated from loyalty programs can be infused with energy from an EDM “to improve marketing, store-layout and many other decisions.” One example he gives is its application to decide what rewards or rebates actually result in a change in customer behavior.
References
Radan, N. and J. Taylor (June 2008). Enterprise decision management uses BI to power up operational systems. Teradata Magazine. Retrieved on September 3, 2008 at (http://www.teradata.com/tdmo/v08n02/Viewpoints/EnterpriseView/Choices.aspx
Taylor, J (July 26, 2007). Growing your business with decision management. Retrieved on September 3, 2008 at http://edm.findtechblogs.com/default.asp?item=656748
Fan Traps and Chasm Traps
In many consolidated, operational data stores, we typically end up with a core record in a “fact” table that is associated with multiple “dimension” tables with characteristics for each record in the fact table. For example, a university Alumni table as our “fact”/core table, a Donations table and a Financial Aid table, among others that tell us more about the person in the fact table.
Someone in the Alumni table may have made 0, 1 or many donations and so have 0 to many associated records in the Donations table. Likewise, someone in the Alumni table may have received 0, 1 or many scholarships or loans to attend college. Many of our data associations in this type of consolidated customer database will have this 1 to many or 1-M quality.

This can result in very subtle errors and very misleading interpretations in the analysis we do on the database or in the more mundane operations such as mailings. Let’s say we want to test the hypothesis that Alumni who received financial aid are more likely to donate money than those who did not, a propensity to donate. The correct way to accomplish this is to run two queries, one a list of alumni and the sum of all amounts they donated, and the other a list of alumni and the sum of all financial aid they received. Then we merge the two results sets.
It is tempting instead to run one query that reads our alumni table and simultaneously sums both donations and financial aid in the related tables. In a SQL database we have just stepped into a chasm trap. Such a query will disproportionally count both the donations and the financial aid for those friends who have made more than 1 donation AND received more than 1 loans or scholarships. (see Business Intelligence Blog, p 1 or IDS, pp 1-3 or http://db.grussell.org/resources/pdf/co22001%20notes.pdf
References
International Documentation Solution (April 14, 2000). Recognizing and resolving Chasm and Fan traps when designing. Retrieved on August 28, 2008 from http://www.eagle.co.nz/businessobjects/pdfs/ttchasm.pdf
Napier University (August 2002). Database SystemsStudent Notes. Retrieved on August 28, 2008 from http://db.grussell.org/resources/pdf/co22001%20notes.pdf
