-
Notifications
You must be signed in to change notification settings - Fork 1
/
encoding_script.cfm
76 lines (53 loc) · 2.66 KB
/
encoding_script.cfm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<!--- read in xml --->
<cfhttp url="http://www2-dev.ad.sl.nsw.gov.au/apps/trove-newspaper-map/newspapers.xml">
<cfset xmlData = xmlparse(trim(cfhttp.FileContent))>
<!--- ok read in csv file of data with lat / long's --->
<cfhttp name="latLongData"
url="http://www2-dev.ad.sl.nsw.gov.au/apps/trove-newspaper-map/data/Australian_Post_Codes_Lat_Lon.csv"
firstRowAsHeaders="true"
method="get" />
<!---<cfdump var="#latLongData#" />--->
<!--- now loop through the xml and add in the town, post code and lat / long values for those items that match --->
<!--- get an array of book nodes using xmlSearch --->
<cfset Newspapers = xmlSearch(xmlData,'/response/newspaper')>
<!--- loop through the array and output the data --->
<cfoutput>
<cfset missedItems = 0>
<cfloop from="1" to="#arraylen(Newspapers)#" index="i">
<!--- add elements into xml node at this position --->
<cfset ArrayInsertAt(xmlData.response.newspaper[i].XmlChildren, 3, XmlElemNew(xmlData, "town"))>
<cfset ArrayInsertAt(xmlData.response.newspaper[i].XmlChildren, 4, XmlElemNew(xmlData, "postcode"))>
<cfset ArrayInsertAt(xmlData.response.newspaper[i].XmlChildren, 5, XmlElemNew(xmlData, "latlong"))>
<cfset matchFound = false>
<cfset newspaperXML = xmlparse(Newspapers[i])>
<cfset title = newspaperXML.newspaper.title.XmlText>
<cfset titleItems = listtoarray(title, " ", false)>
<cfloop from="1" to="#arraylen(titleItems)#" index="a">
<cfset titleCleaned = Replace(titleItems[a], "(", "", "All")>
<cfset titleCleaned = Replace(titleCleaned, ")", "", "All")>
<cfset titleCleaned = Replace(titleCleaned, ",", "", "All")>
<cfif not matchFound>
<cfquery name="getData" dbtype="query">
select * from latLongData
where suburb like '#ucase(titleCleaned)#%'
</cfquery>
<cfif getData.recordcount>
<cfset matchFound = true>
<cfbreak>
</cfif>
</cfif>
</cfloop>
<cfif not matchFound>
#title#<br />
<cfset missedItems++>
<cfelse>
<cfset xmlData.response.newspaper[i].town.XMLText = trim(getData.suburb)>
<cfset xmlData.response.newspaper[i].postcode.XMLText = trim(getData.postcode)>
<cfset xmlData.response.newspaper[i].latlong.XMLText = trim(getData.lat) & ',' & trim(getData.lon)>
</cfif>
</cfloop>
<cfdump var="#missedItems#">
</cfoutput>
<!--- write out new xml file --->
<cfset xmlString = toString(xmlData)>
<cffile action="write" addnewline="yes" file="#getdirectoryfrompath(getbasetemplatepath())#newspaperDataLatLong.xml" output="#xmlString#" fixnewline="yes">