delphi programming forums mysql charset mget recursive synonimos
free ventrilo servers hosting cs javascript delay python find in list
Back Forum New
abstract:

<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.


I am trying to parse XML that I got from a web service.
My attempt in Cold Fusion 8 is not working:
Code:
  1. <cfscript>
  2. xmlfile = xmlparse(cfhttp.filecontent);
  3. xmlsize = arraylen(xmlfile.Person.xmlchildren);
  4. xmlqry = QueryNew("id, city, state");
  5. QueryAddRow(xmlqry,xmlsize);
  6. for(a=1;a LTE xmlsize;a=a+1) {
  7. QuerySetCell(xmlqry,"city",xmlfile.Person.PersonID[a].City.xmlText,a);
  8. QuerySetCell(xmlqry,"state",xmlfile.Person.PersonID[a].State.xmlText,a);
  9. QuerySetCell(xmlqry,"id",xmlfile.Person.PersonID[a].xmlAttributes.id,a);
  10. }
  11. </cfscript>
  12. <cfquery name="Person" dbtype="query">
  13. SELECT *
  14. FROM xmlqry
  15. </cfquery>
  16. <cfoutput query="Person">
  17. Id = #id#<br>
  18. City = #city#<br>
  19. State = #state#
  20. <br><br>
  21. </cfoutput>
Copy Code
My error message:
Element Person.XMLChildren is undefined in XMLFile
My XML looks like this:
Code:
  1. <PersonData>
  2.     <Person>
  3.          <id>2</id>
  4.          <city>Oakland</city>
  5.          <state>California</state>
  6.     </Person>
  7. </PersonData>
Copy Code
Please advise.

TOP


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:
  1. <cfhttp url="http://localhost:8500/TestingCF/phonebook.xml" method="GET" resolveurl="No" ></cfhttp>
  2. <cfset mydoc = XmlParse(CFHTTP.FileContent)>
  3. <cfset xmlObject = xmlParse(mydoc)/>
  4. <cfset size = "#arrayLen(xmlObject["phonebook"].xmlChildren)#">
  5. <cfset myquery = QueryNew("cat, firstName, lastName, phone,email")>
  6. <cfset temp = QueryAddRow(myquery, #size#)>
  7. <cfloop index="i" from = "1" to = "#size#">
  8. <cfset temp = QuerySetCell(myquery, "cat",
  9. #mydoc.phonebook.contact.XMLAttributes['category']#, #i#)>
  10. <cfset temp = QuerySetCell(myquery, "firstName",
  11. #mydoc.phonebook.contact.firstName.XmlText#, #i#)>
  12. <cfset temp = QuerySetCell(myquery, "lastName",
  13. #mydoc.phonebook.contact.lastName.XmlText#, #i#)>
  14. <cfset temp = QuerySetCell(myquery, "phone",
  15. #mydoc.phonebook.contact.phone.XmlText#, #i#)>
  16. <cfset temp = QuerySetCell(myquery, "email",
  17. #mydoc.phonebook.contact.email.XmlText#, #i#)>
  18. </cfloop>
  19. <cfinvoke component="pbook_meths" method="sortLName" returnVariable="Result">
  20. <cfinvokeargument name="q_obj" value="#myquery#">
  21. </cfinvoke>
  22. <table border=1 width=500 align=center>
  23. <th>category</th><th>fist name</th><th>last
  24. name</th><th>phone</th><th>email</th>
  25. <cfoutput query="Result">
  26. <tr>
  27. <td>#cat#</td><td>#firstName#</td>
  28. <td>#lastName#</td> <td>#phone#</td>
  29. <td>#email#</td>
  30. </tr>
  31. </cfoutput>
  32. </table>
Copy Code
The cfc
Code:
  1. <cffunction name="sortLName" access="remote" returnType="query">
  2. <cfargument name="q_obj" required="Yes" >
  3. <cftry>
  4. <cfquery name="pbTest" dbType="query">
  5. SELECT *
  6. FROM arguments.q_obj
  7. where lastname = 'Smith'
  8. </cfquery>
  9. <cfcatch type="Any">
  10. <P><cfoutput>#cfcatch.message#</cfoutput></P>
  11. </cfcatch>
  12. </cftry>
  13. <cfreturn pbTest>
  14. </cffunction>
Copy Code
The output:
Code:
  1. category   fist name      last name    phone         email
  2. friend       John             Smith         412-555-1212 johnsmith@email.com
  3. 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.

TOP

Back Forum