Hi Everyone,
I'm trying to parse my XML File with ColdFusion and I've already made an
Object like:
<cffile action="read" file="C:\myxmldoc.xml" variable="XMLFileText">
<cfset myXMLDocument=XmlParse(XMLFileText)>
<cfoutput>#toString(myXMLDocument)#</cfoutput>
my Problem is: I only want to output some childs not the whole XML-File.
I could tranform it with XSLT, but my <xsl:template>...</xslt:template> as xls
String doesn't work.
Thx 4 help,
Sonix
RoBsTaMaCk - 31 May 2005 21:34 GMT
I'm going to use the latest virus alerts feed from .link.XmlText# (where x is
the item number you want)
From here, you can create a simple loop that changes the value of X and
outputs all the items. Even if you're only retrieving one node of data (and
not a series), hopefully the steps described above should help you determine
how to locate and reference the nodes you need.
<!--- // Retrieve XML file for latest virus alerts // --->
<cfhttp url="http://www.sophos.com/virusinfo/infofeed/tenalerts.xml"
method="GET"
timeout="15">
</cfhttp>
<!--- // Trim whitespace and parse XML // --->
<cfscript>
XMLContent = trim(cfhttp.filecontent);
XMLContent = XMLParse(XMLContent);
</cfscript>
<!--- // Output ONLY THE FIRST 5 alerts // --->
<cfoutput>
<cfloop from ="1" to="5" index="i">
<a href="#XMLContent.RDF.item[i].link.XmlText#"
target="_blank">#XMLContent.RDF.item[i].title.XmlText#</a><br>
</cfloop>
</cfoutput>