You'll have to do some testing for attribute existence, but you'd have
to do that either way.

<cfset variables.locations = XMLSearch ( variables.parsedDoc,
'//dir_office_atm_locations' ) />
<cfset variables.cLocations = arrayLen ( variables.locations ) />

<cfloop index="iLocation" from="1" to="#variables.cLocations#">
   <cfif [pseudocode: the name attribute exists>
      <cfset temp = querySetCell ( locquery, "name",
#variables.locations[variables.iLocation].attributes.name#,#variables.iLocation#)
/>

</cfloop>


On 8/22/06, Crow T Robot <[EMAIL PROTECTED]> wrote:
> Here's my code, sort of.  (My notebook's at home with the real code on it)
> <cffile action="read" file="#ExpandPath('xml/locXML.xml')#"
> variable="locXML">
> <cfset locDoc = XMLParse(locXML)>
> <cfset numItems =
> ArrayLen(locDoc.officelocations.dir_office_atm_locations.XmlChildren)>
>
> <cfset locquery =
> QueryNew("id,name,address,office,atm,link,sort,phone,fax,city,state,zip")>
> <cfset temp = QueryAddRow(locquery, #numItems#)>
> <cfloop index="i" from = "1" to = #numItems#>
>    <cfset temp = QuerySetCell(locquery, "id",
> #locDoc.officelocations.dir_office_atm_locations[i].XmlAttributes.id#,#i#)>
>    <cfset temp = QuerySetCell(locquery, "name",
> #locDoc.officelocations.dir_office_atm_locations[i].XmlAttributes.name#,#i#)
> >
>    <cfset temp = QuerySetCell(locquery, "address",
> #locDoc.officelocations.dir_office_atm_locations[i].XmlAttributes.address#,#
> i#)>
>    <cfset temp = QuerySetCell(locquery, "office",
> #locDoc.officelocations.dir_office_atm_locations[i].XmlAttributes.office#,#i
> #)>
>    <cfset temp = QuerySetCell(locquery, "atm",
> #locDoc.officelocations.dir_office_atm_locations[i].XmlAttributes.atm#,#i#)>
>    <cfset temp = QuerySetCell(locquery, "link",
> #locDoc.officelocations.dir_office_atm_locations[i].XmlAttributes.link#,#i#)
> >
>    <cfset temp = QuerySetCell(locquery, "sort",
> #locDoc.officelocations.dir_office_atm_locations[i].XmlAttributes.sort#,#i#)
> >
>    <cfset temp = QuerySetCell(locquery, "phone",
> #locDoc.officelocations.dir_office_atm_locations[i].XmlAttributes.phone#,#i#
> )>
>    <cfset temp = QuerySetCell(locquery, "fax",
> #locDoc.officelocations.dir_office_atm_locations[i].XmlAttributes.fax#,#i#)>
>    <cfset temp = QuerySetCell(locquery, "city",
> #locDoc.officelocations.dir_office_atm_locations[i].XmlAttributes.city#,#i#)
> >
>    <cfset temp = QuerySetCell(locquery, "state",
> #locDoc.officelocations.dir_office_atm_locations[i].XmlAttributes.state#,#i#
> )>
>    <cfset temp = QuerySetCell(locquery, "zip",
> #locDoc.officelocations.dir_office_atm_locations[i].XmlAttributes.zip#,#i#)>
> </cfloop>
>
> <cfdump var=#locquery#>
>
> I'll try your way tonight.
>
> Thanks,
>
> Ray
> ==========================
> Ray Champagne
> Senior Application Developer
> CrystalVision Web Site Design
> http://www.cvwp.com
> [EMAIL PROTECTED]
> 603.433.9559
> ==========================
>
> -----Original Message-----
> From: Rob Wilkerson [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, August 22, 2006 8:34 AM
> To: CF-Talk
> Subject: Re: XML looping problems
>
> No, the XML is fine (or, at the very least, the inconsistency won't
> make it invalid).  How are you trying to loop if the name attribute is
> causing problems?  What about just looping over the
> dir_office_atm_locations nodes?
>
> <cfset variables.locations = XMLSearch ( variables.parsedDoc,
> '//dir_office_atm_locations' ) />
> <cfdump var="#variables.locations#" />
>
> On 8/22/06, Ray Champagne <[EMAIL PROTECTED]> wrote:
> > I've been given an XML document that needs to be parsed into a query, and
> > I'm having some issues I need help with.
> >
> >
> >
> > XML sample:
> >
> >
> >
> > <officelocations>
> >
> > <dir_office_atm_locations id="1" name="Headquarters" address="Ten Post
> > Office Square" office="1" atm="1" link="http://www.mapquest.com"; sort="1"
> > phone="(123) 123-1919" fax="(123)123-4550" city="Boston"
> > state="Massachusetts" zip="02109"/>
> >
> > <dir_office_atm_locations id="2" address="Boylston Street" office="1"
> > atm="1" link="http://www.mapquest.com"; sort="2" phone="(123)123-4500"
> > fax="(123)123-4290" city="Boston" state="Massachusetts" zip="02116"/>
> >
> > </officelocations>
> >
> >
> >
> > Notice that the second node has "name" attribute.  That's what is giving
> me
> > fits when looping over the XML.  Seems like no matter what I try, if that
> > "name" attribute isn't defined, the loop will throw an error.  I have no
> > control over the XML creation, or I'd just make name="" if there is no
> > location and this would be done with.
> >
> >
> >
> > I'm not really an expert when it comes to XML, so any help with this is
> > appreciated.  Is this considered to be an invalid XML document because of
> > the inconsistency?
> >
> >
> >
> > Ray
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
>
>
>
> 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Introducing the Fusion Authority Quarterly Update. 80 pages of hard-hitting,
up-to-date ColdFusion information by your peers, delivered to your door four 
times a year.
http://www.fusionauthority.com/quarterly

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:250606
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4

Reply via email to