Last active
December 15, 2015 16:39
-
-
Save youcoldfusion/5290435 to your computer and use it in GitHub Desktop.
xml parsing in coldfusion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<employee> | |
<!-- A list of employees --> | |
<name EmpType="Regular"> | |
<first>Animesh </first> | |
<last>Dutta</last> | |
</name> | |
<name EmpType="Contract"> | |
<first>Hiranmayee</first> | |
<last>Dutta</last> | |
</name> | |
</employee> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cffile action="read" file="C:\Development\Users\Animesh\cf\intermediate\OSSS\testxml.xml.cfm" variable="xmltext" > | |
<cfset xmltexttoxmldocumentobject=xmlparse(xmltext)> | |
<cfset xmlelementinarray=xmltexttoxmldocumentobject.employee.XmlChildren> | |
<cfset size=ArrayLen(xmlelementinarray)> | |
<cfset queryobj=QueryNew("first , last" ,"VarChar ,VarChar" )> | |
<cfset temp=queryAddRow(queryobj,#size#)> | |
<cfloop index="i" from="1" to=#size# > | |
<cfset temp=QuerySetCell(queryobj,"first",#xmltexttoxmldocumentobject.employee.name[i].first.XmlText#,#i#)> | |
<cfset temp=QuerySetCell(queryobj,"last",#xmltexttoxmldocumentobject.employee.name[i].last.XmlText#,#i#)> | |
</cfloop> | |
<cfdump var="#queryobj#"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cffile action="read" file="testxml.xml.cfm" variable="xmltext" > | |
<cfdump var="#IsXML(xmltext)#"> | |
<cfdump var="#xmlparse(xmltext)#"> | |
<cfdump var="#xmlparse(xmltext).employee.name[1].first.XmlText#"> | |
<cfdump var="#xmlparse(xmltext).employee.name[1].last.XmlText#"> | |
<cfdump var="#xmlparse(xmltext).employee.name[1].first.XmlText#"> | |
<cfdump var="#xmlparse(xmltext).employee.name[1].last.XmlText#"> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment