July 12, 2004
Reading an XML doc & Mach II
Reading an XML doc & Mach II
Let’s say it has come to a time, when you would like to read in an XML doc as a data source within the MachII framework. I'm going to use the XML doc from this previous post.
How does one go about doing that?
First within the model folder, set up the following structure
\input\xmlListener.cfc
\input\xmlGateway.cfc
Your xmlListener will look like:
<cfcomponent extends="MachII.framework.Listener" displayname="XML Listener" hint="I am the listener for xml Documents">
<cffunction name="configure" access="public" returntype="void" output="true" displayname="Blog Constructor" hint="I initialize this listener as part of the framework startup.">
<cfscript>
variables.xmlGateway = createObject("component","xmlReader.model.input.xmlGateway").init();
</cfscript>
</cffunction>
<cffunction name="getAll" access="public" returntype="query" output="false" displayname="Get XML doc" hint="I return a query containing the XML Doc.">
<cfreturn variables.xmlGateway.findAll() />
</cffunction>
<cffunction name="getTotalChildren" access="public" returntype="numeric" output="false" displayname="Get the Number of Aggregated Blogs" hint="I return the number of xmlChildren of the root">
<cfreturn variables.xmlGateway.findTotal() />
</cffunction>
</cfcomponent>
Your xmlGateway will appear as:
<cfcomponent displayname="XML Gateway" hint="I am a data gateway to Summarize an XML document">
<cffunction name="init" access="public" returntype="xmlReader.model.input.xmlGateway" output="false" displayname="Gateway Constructor" hint="I initialize the XML gateway.">
<cfset var inputXML = "" />
<cfset variables.structXML = 0 />
<cffile action="read" variable="inputXML" file="#ExpandPath("data\xmlDOC.xml")#" />
<cfset variables.structXML = XMLParse(inputXML) />
<cfreturn this />
</cffunction>
<cffunction name="findAll" access="public" returntype="query" output="false" displayname="Find All" hint="I return a query containing the XML Doc">
<cfset var qrySelect = 0 />
<cfset var structListing = 0 />
<cfset var patientName = 0 />
<cfset var patientID = 0 />
<cfset var visitID = 0 />
<cfset var admitDate = 0 />
<cfset var payor = 0 />
<cfset var nurseStation = 0 />
<cfset var roomBed = 0 />
<cfset var service = 0 />
<cfset var previousDischargeDate = 0 />
<cfset var selectRow = 0 />
<cfset structListing = XMLSearch(structXML, "/ReadmissionReport/Readmission") />
<cfset qrySelect = QueryNew("patientName, patientID, visitID, admitDate, payor, nurseStation, roomBed, service, perviousDischargeDate") />
<cfloop from="1" to="#ArrayLen(structListing)#" index="i">
<cfset patientName = structListing[i].PatientName.XmlText />
<cfset patientID = structListing[i].PatientID.XmlText />
<cfset visitID = structListing[i].VisitID.XmlText />
<cfset admitDate = structListing[i].AdmitDate.XmlText />
<cfset payor = structListing[i].Payor.XmlText />
<cfset nurseStation = structListing[i].NurseStation.XmlText />
<cfset roomBed = structListing[i].RoomBed.XmlText />
<cfset service = structListing[i].Service.XmlText />
<cfset selectRow = QueryAddRow(qrySelect) />
<cfset QuerySetCell(qrySelect, "patientName", patientName, selectRow) />
<cfset QuerySetCell(qrySelect, "patientID", patientID, selectRow) />
<cfset QuerySetCell(qrySelect, "visitID", visitID, selectRow) />
<cfset QuerySetCell(qrySelect, "admitDate", admitDate, selectRow) />
<cfset QuerySetCell(qrySelect, "payor", payor, selectRow) />
<cfset QuerySetCell(qrySelect, "nurseStation", nurseStation, selectRow) />
<cfset QuerySetCell(qrySelect, "roomBed", roomBed, selectRow) />
<cfset QuerySetCell(qrySelect, "service", service, selectRow) />
</cfloop>
<cfreturn qrySelect />
</cffunction>
<cffunction name="findTotal" access="public" returntype="numeric" output="false" displayname="Find Total" hint="I return the number of readmits in the xml file">
<cfset var xmlNode = 0 />
<cfset xmlNode = structXML.XMLRoot>
<cfreturn ArrayLen(xmlNode.xmlChildren)>
</cffunction>
</cfcomponent>
Next within the config folder, add the following to the machii.xml under Listeners.
<listener name="xmlListener" type="xmlReader.model.input.xmlListener"> <invoker type="MachII.framework.invokers.CFCInvoker_Event" /> </listener>
And add this under event handler to call the listener to the desired event
<notify listener="xmlListener" method="getTotalChildren” resultKey="request.intTotal" /> <notify listener="xmlListener" method="getAll" resultKey="request.qryAll" />
And within the view add the following logic to see the total and query
#request.intTotalChildren# #request.qryAll#
I am not sure this would be how I would model it -- Data manipulations would be in the DAO and Gateway helper objects to a more real-world modelled listener, like let's say a "User" object.
Posted by: Hugo Ahlenius at July 15, 2004 12:15 AMFinally passed the test
Managing in light of McGregor's Theory X and Theory Y
CMMI
Kicking HIT Leadership Up a Notch
That's just some mumbo jumbo project management BS
Outcomes - The tactic to get to the strategy
Nurse Call, VOIP, and Wi-Fi: Its just cool when things come together!
December 2007
November 2007
October 2007
September 2007
August 2007
July 2007
June 2007
May 2007
April 2007
March 2007
February 2007
January 2007
December 2006
November 2006
August 2006
June 2006
May 2006
April 2006
March 2006
February 2006
January 2006
November 2005
October 2005
September 2005
August 2005
June 2005
May 2005
April 2005
March 2005
February 2005
January 2005
December 2004
November 2004
October 2004
September 2004
August 2004
July 2004
June 2004
May 2004
April 2004
March 2004
February 2004
January 2004
December 2003
November 2003
October 2003
Joel on Software
David Ross
Edward Prevost
Martin Fowler
The Health Care Blog
The Tales of Hoffman
The Business Word
Medical Rants
Christina's Considerations
Paul Levy
HIS Talk
Appropriate IT
Candid CIO
RSS feed




