Originally Posted by kiteless
Use cfdump to dump the XML Document Object and determine the correct path to the node you want. It may be something like "xmlfile.PersonData.Person.xmlchildren".
Thanks it now working but I am calling a web service in ColdFusion 8 that outputs an xml (phonebook.xml) with almost 1,000 records.
Since I dont quite understand how it works I would like to know if the below grabs the 2 records only from the web service. Or does the script below grab all 1,000 records and put it in the CFHTTP.FileContent and then the cfc grabs the 2 records that are output?
Code:- <cfhttp url="http://localhost:8500/TestingCF/phonebook.xml" method="GET" resolveurl="No" ></cfhttp>
- <cfset mydoc = XmlParse(CFHTTP.FileContent)>
- <cfset xmlObject = xmlParse(mydoc)/>
- <cfset size = "#arrayLen(xmlObject["phonebook"].xmlChildren)#">
- <cfset myquery = QueryNew("cat, firstName, lastName, phone,email")>
- <cfset temp = QueryAddRow(myquery, #size#)>
- <cfloop index="i" from = "1" to = "#size#">
- <cfset temp = QuerySetCell(myquery, "cat",
- #mydoc.phonebook.contact.XMLAttributes['category']#, #i#)>
- <cfset temp = QuerySetCell(myquery, "firstName",
- #mydoc.phonebook.contact.firstName.XmlText#, #i#)>
- <cfset temp = QuerySetCell(myquery, "lastName",
- #mydoc.phonebook.contact.lastName.XmlText#, #i#)>
- <cfset temp = QuerySetCell(myquery, "phone",
- #mydoc.phonebook.contact.phone.XmlText#, #i#)>
- <cfset temp = QuerySetCell(myquery, "email",
- #mydoc.phonebook.contact.email.XmlText#, #i#)>
- </cfloop>
- <cfinvoke component="pbook_meths" method="sortLName" returnVariable="Result">
- <cfinvokeargument name="q_obj" value="#myquery#">
- </cfinvoke>
- <table border=1 width=500 align=center>
- <th>category</th><th>fist name</th><th>last
- name</th><th>phone</th><th>email</th>
- <cfoutput query="Result">
- <tr>
- <td>#cat#</td><td>#firstName#</td>
- <td>#lastName#</td> <td>#phone#</td>
- <td>#email#</td>
- </tr>
- </cfoutput>
- </table>
Copy Code The cfc
Code:- <cffunction name="sortLName" access="remote" returnType="query">
- <cfargument name="q_obj" required="Yes" >
- <cftry>
- <cfquery name="pbTest" dbType="query">
- SELECT *
- FROM arguments.q_obj
- where lastname = 'Smith'
- </cfquery>
- <cfcatch type="Any">
- <P><cfoutput>#cfcatch.message#</cfoutput></P>
- </cfcatch>
- </cftry>
- <cfreturn pbTest>
- </cffunction>
Copy Code The output:
Code:- category fist name last name phone email
- friend John Smith 412-555-1212 johnsmith@email.com
- friend Jane Smith 412-555-1212 janesmith@email.com
Copy Code I hope Iam only grabbing 2 records each time the web service is called and not 1000 records?
<br><br>
</cfoutput>
My error message:
Element Person.XMLChildren is undefined in XMLFile
My XML looks like this:
Code:
<PersonData>
<Person>
<id>2</id>
<city>Oakland</city>
<state>California</state>
</Person>
</PersonData>
Please advise. |