I haven't used XML before and I was given a file that looks
like this:
<DataSet>
<productSum>
<productTotal>2</productTotal>
<productNew>0</productNew>
</productSum>
<product>
<productId>122</productId>
<productName>Demo Kit</productName>
<productRelease>1.2.5</productRelease>
<productQty>32</productQty>
</product>
<product>
<productId>174</productId>
<productName>Sample Kit</productName>
<productRelease>2.0</productRelease>
<productQty>3</productQty>
</product>
</DataSet>
I read through
http://www.adobe.com/devnet/coldfusion/articles/xmlxslt.pdf
and tried to convert some sample code to read this XML file. I'm
having no luck though.
I want to be able to output to a csv file so it looks like
this:
productID,productName,productRelease,productQty
122,Demo Kit,1.2.5,32
174,Sample Kit,2.0,3
How can I modify this code so I can produce the CSV? I need
to get a listing of the items in the <product> tag.
Thanks in advance!
<CFSET MyXmlFile = ExpandPath("test.xml")>
<CFFILE
ACTION="READ"
FILE="#MyXmlFile#"
VARIABLE="MyXmlCode">
<CFSET MyXml = XmlParse(MyXmlCode)>
<CFSET xnDataSet = MyXML.XmlRoot>
<CFSET nNumProducts = ArrayLen(xnDataSet.XmlChildren)>
<CFOUTPUT>
<p>The company has a total of: <b>#nNumProducts#
products</b></p>
<CFLOOP FROM="1" TO="#nNumProducts#" INDEX="i">
<CFSET xnThisProduct = xnDataSet.XmlChildren
>
<CFSET arProducts =
xnThisProduct["product"].XmlChildren>
<CFSET nNumProducts = ArrayLen(arProducts)>
<p>Product #i# (product):<br>
<CFLOOP FROM="1" TO="#nNumProducts#" INDEX="j">
#arProducts.XmlText#<br>
</CFLOOP></p>
</CFLOOP>
</CFOUTPUT>