Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Parse and output XML

Posted on 2004-10-29
4
Medium Priority
?
234 Views
Last Modified: 2013-12-24
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
0
Comment
Question by:areola
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 7

Expert Comment

by:INSDivision6
ID: 12447815
Not clear what is your problem/question.
0
 
LVL 17

Accepted Solution

by:
Tacobell777 earned 1000 total points
ID: 12469636
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
 

Author Comment

by:areola
ID: 12471361
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
 
LVL 17

Expert Comment

by:Tacobell777
ID: 12471396
your welcome
0

Featured Post

Understanding Web Applications

Without even knowing it, most of us are using web applications on a daily basis. Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We often confuse these web applications tools for websites.  So, what is the difference?

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL several years ago, it seemed like now was a good time to update it for object-oriented PHP.  This article does that, replacing as much as possible the pr…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question