Question
Cant parse xml
I am trying to parse XML using Cold Fusion 8 and it doesnt
work.
My attempt:
<cfscript>
xmlfile = xmlparse(cfhttp.filecontent);
xmlsize = arraylen(xmlfile.PersonData.xmlchildren);
xmlqry = QueryNew("id, city, state");
QueryAddRow(xmlqry,xmlsize);
for(a=1;a LTE xmlsize;a=a+1) {
QuerySetCell(xmlqry,"city",xmlfile.PersonData.Person.City.xmlText,a);
QuerySetCell(xmlqry,"state",xmlfile.PersonData.Person.State.xmlText,a);
QuerySetCell(xmlqry,"id",xmlfile.PersonData.Person.xmlAttributes.id,a);
}
</cfscript>
<cfquery name="Person" dbtype="query">
SELECT *
FROM xmlqry
</cfquery>
<cfoutput query="Person">
Id = #id#<br>
City = #city#<br>
State = #state#
<br><br>
</cfoutput>
The XML that doesnt work:
<?xml version = "1.0" ?
<SOAP-ENV:Envelope ....>
<SOAP-ENV:Body ....>
<PeopleAction>
<PersonData>
<Person>
<id>1</id>
<city>San Jose</city>
<state>California</state>
</Person>
</PersonData>
</PeopleAction>
</SOAP-ENV:Envelope ....>
</SOAP-ENV:Body ....>
If I manually change the XML it works with the below:
<?xml version = "1.0" ?
<SOAP-ENV:Envelope ....>
<SOAP-ENV:Body ....>
<PersonData>
<Person category="friend">
<id>1</id>
<city>San Jose</city>
<state>California</state>
</Person>
</PersonData>
</SOAP-ENV:Envelope ....>
</SOAP-ENV:Body ....>
Please advise how I can change the CFScript to make it work with my original XML?
My attempt:
<cfscript>
xmlfile = xmlparse(cfhttp.filecontent);
xmlsize = arraylen(xmlfile.PersonData.xmlchildren);
xmlqry = QueryNew("id, city, state");
QueryAddRow(xmlqry,xmlsize);
for(a=1;a LTE xmlsize;a=a+1) {
QuerySetCell(xmlqry,"city",xmlfile.PersonData.Person.City.xmlText,a);
QuerySetCell(xmlqry,"state",xmlfile.PersonData.Person.State.xmlText,a);
QuerySetCell(xmlqry,"id",xmlfile.PersonData.Person.xmlAttributes.id,a);
}
</cfscript>
<cfquery name="Person" dbtype="query">
SELECT *
FROM xmlqry
</cfquery>
<cfoutput query="Person">
Id = #id#<br>
City = #city#<br>
State = #state#
<br><br>
</cfoutput>
The XML that doesnt work:
<?xml version = "1.0" ?
<SOAP-ENV:Envelope ....>
<SOAP-ENV:Body ....>
<PeopleAction>
<PersonData>
<Person>
<id>1</id>
<city>San Jose</city>
<state>California</state>
</Person>
</PersonData>
</PeopleAction>
</SOAP-ENV:Envelope ....>
</SOAP-ENV:Body ....>
If I manually change the XML it works with the below:
<?xml version = "1.0" ?
<SOAP-ENV:Envelope ....>
<SOAP-ENV:Body ....>
<PersonData>
<Person category="friend">
<id>1</id>
<city>San Jose</city>
<state>California</state>
</Person>
</PersonData>
</SOAP-ENV:Envelope ....>
</SOAP-ENV:Body ....>
Please advise how I can change the CFScript to make it work with my original XML?
