Parse and output XML

Hello all,

I'm trying to build an address look up app from xml files provided from postcodeanywhere.co.uk. I know I need to execute a lookup query with cfhttp and then parse it  but I need some help on how to output the address options... I keep on running into a multitude of errors. The format of the xml files can be viewed here: http://www.postcodeanywhere.co.uk/downloads/developer/samples/xml_examples.doc

Can anyone provide me with some pointers for the first two xml docs detailed?

Cheers, P
areolaAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Tacobell777Connect With a Mentor Commented:
This data should come from a cfhttp request, but for demonstration purposes I put the xml in a variable
<cfset variables.myXMLString = "<PostcodeAnywhere>
         <Schema Items="3">
                    <Field Name="id" />
                    <Field Name="seq" />
                   <Field Name="description" />
         </Schema>
         <Data Items="45">
              <Item id="47264561" seq="0" description="Arthur Amos Associates, Unit 5, Elgar Business Centre, Moseley Road, Worcester WR2 6NJ" />
              <Item id="47264564" seq="1" description="Axis Milk Ltd, 11-13 Elgar Business Centre, Moseley Road, Hallow, Worcester WR2 6NJ" />
              <Item id="47264560" seq="2" description="Computer Counter Ltd, Monkwood House, Moseley Road, Hallow, Worcester WR2 6NJ" />
              <Item id="47264566" seq="3" description="Fernhill Solutions Ltd, Enigma House, Elgar Business Centre, Moseley Road, Worcester WR2 6NJ" />
              <Item id="47264565" seq="4" description="Microtrol Ltd, Unit 16, Elgar Business Centre, Moseley Road, Worcester WR2 6NJ" />
              <Item id="47264547" seq="5" description="Moseley Saw Mills, Moseley Road, Hallow, Worcester WR2 6NJ" />
              <Item id="47264563" seq="6" description="Premier Recoveries Ltd, Premier House, Elgar Business Centre, Moseley Road, Worcester WR2 6NJ" />
              <Item id="47264556" seq="7" description="Robin Pearce, Worlds End Nurseries, Moseley Road, Hallow, Worcester WR2 6NJ" />
              <Item id="47264562" seq="8" description="Willowbrook, Mill House, Elgar Business Centre, Moseley Road, Worcester WR2 6NJ" />
              <Item id="47264546" seq="9" description="Worlds End Nurseries, Moseley Road, Hallow, Worcester WR2 6NJ" />
              <Item id="48040720" seq="10" description="Wychburn Engineering Services Ltd, Unit 2, Elgar Business Centre, Moseley Road, Worcester WR2 6NJ" />
              <Item id="47264555" seq="11" description="(Cottrell), Moseley Road, Hallow, Worcester WR2 6NJ" />
              <Item id="47264559" seq="12" description="1 The Cottages, Moseley Road, Hallow, Worcester WR2 6NJ" />
              <Item id="47264558" seq="13" description="2 The Cottages, Moseley Road, Hallow, Worcester WR2 6NJ" />
              <Item id="29459748" seq="14" description="3 Elgar Business Centre, Moseley Road, Hallow, Worcester WR2 6NJ" />
              <Item id="47264527" seq="15" description="Beaumont, Moseley Road, Hallow, Worcester WR2 6NJ" />
              <Item id="47264528" seq="16" description="Brook Cottage, Moseley Road, Hallow, Worcester WR2 6NJ" />
              <Item id="47264529" seq="17" description="Cherry Tree Cottage, Moseley Road, Hallow, Worcester WR2 6NJ" />
              <Item id="48276297" seq="18" description="Unit 7, Elgar Business Centre, Moseley Road, Worcester WR2 6NJ" />
              <Item id="47264530" seq="19" description="Essfield, Moseley Road, Hallow, Worcester WR2 6NJ" />
              <Item id="47264531" seq="20" description="Fairfields, Moseley Road, Hallow, Worcester WR2 6NJ" />
              <Item id="47264544" seq="21" description="Flatten Bank, Moseley Road, Hallow, Worcester WR2 6NJ" />
              <Item id="47264545" seq="22" description="Four Acres, Moseley Road, Hallow, Worcester WR2 6NJ" />
              <Item id="47264532" seq="23" description="Grosmont Cottage, Moseley Road, Hallow, Worcester WR2 6NJ" />
              <Item id="47264526" seq="24" description="Holly Cottage, Moseley Road, Hallow, Worcester WR2 6NJ" />
              <Item id="47264549" seq="25" description="Hollymount, Moseley Road, Hallow, Worcester WR2 6NJ" />
              <Item id="47264533" seq="26" description="Inglemere, Moseley Road, Hallow, Worcester WR2 6NJ" />
              <Item id="47264534" seq="27" description="Ivy Cottage, Moseley Road, Hallow, Worcester WR2 6NJ" />
              <Item id="47264535" seq="28" description="Kothi, Moseley Road, Hallow, Worcester WR2 6NJ" />
              <Item id="47264536" seq="29" description="Leacroft, Moseley Road, Hallow, Worcester WR2 6NJ" />
              <Item id="47264537" seq="30" description="Lyncroft, Moseley Road, Hallow, Worcester WR2 6NJ" />
              <Item id="47264538" seq="31" description="Maryville, Moseley Road, Hallow, Worcester WR2 6NJ" />
              <Item id="47264539" seq="32" description="Moseley Cottage, Moseley Road, Hallow, Worcester WR2 6NJ" />
              <Item id="47264552" seq="33" description="Orchard View, Moseley Road, Hallow, Worcester WR2 6NJ" />
              <Item id="47264557" seq="34" description="Pump Cottage, Moseley Road, Hallow, Worcester WR2 6NJ" />
              <Item id="47264525" seq="35" description="Rose Cottage, Moseley Road, Hallow, Worcester WR2 6NJ" />
              <Item id="47264548" seq="36" description="Rose Dale, Moseley Road, Hallow, Worcester WR2 6NJ" />
              <Item id="47264540" seq="37" description="Sandfield, Moseley Road, Hallow, Worcester WR2 6NJ" />
              <Item id="47264541" seq="38" description="Stilecroft, Moseley Road, Hallow, Worcester WR2 6NJ" />
              <Item id="47264553" seq="39" description="The Haven, Moseley Road, Hallow, Worcester WR2 6NJ" />
              <Item id="47264554" seq="40" description="The Old Bakery, Moseley Road, Hallow, Worcester WR2 6NJ" />
              <Item id="47264551" seq="41" description="The Orchard, Moseley Road, Hallow, Worcester WR2 6NJ" />
              <Item id="47264550" seq="42" description="The Willows, Moseley Road, Hallow, Worcester WR2 6NJ" />
              <Item id="47264542" seq="43" description="Whitegates, Moseley Road, Hallow, Worcester WR2 6NJ" />
              <Item id="47264543" seq="44" description="Wylcotts, Moseley Road, Hallow, Worcester WR2 6NJ" />
        </Data>
</PostcodeAnywhere>
">

<cfset objXML = xmlParse( variables.myXMLString ) />
You now have an in memory representation of the XML, and you can now access its values.

#variables.myXMLString.xmlRoot.Data.Item[ 1 ].xmlAttributes.description#
This is how you output a attribute

<cfloop from="1" to="#arrayLen( variables.myXMLString.xmlRoot.Data.Item )#" index="i">
#variables.myXMLString.xmlRoot.Data.Item[ variables.i ].xmlAttributes.description#
</cfloop>
this is how you access the array of items...

Make sense???
0
 
INSDivision6Commented:
Not clear what is your problem/question.
0
 
areolaAuthor Commented:
First off sorry to INSDivision6 for not replying to your request for more information sooner, I was away on a long weekend and didn't have a chance to reply.

Secondly big thanks to Tacobell777 for understanding what I was whittering on about. Yes it makes perfect sense to me, it was how to reference the "xmlRoot.Data.Item" bit that was really throwing me.

Also to anyone that finds this post later I inserted the cfhttp request with <cfhttp url="#urlAddress#" method="GET" timeout="15"> I then changed the first instance of "variables.myXMLString" to "cfhttp.filecontent" and later referneces to "objXML"

Many thanks Tacobell777, I'm beginning to get my head round XML with Coldfusion, one big "A" to you!
0
 
Tacobell777Commented:
your welcome
0
All Courses

From novice to tech pro — start learning today.