Archive

Posts Tagged ‘xml’

Parse XML with ColdFusion

February 19, 2009 ppshein Leave a comment

We’re now doing project with different language, VB6 and CFMX7. One part of our projects, we need to send our data each other without uploading database files. That’s why we need to consider about exporting and importing XML files. In CFMX7, reading XML isn’t kinda complicated. Here is coding…

<cffile action=”read” file=”c:\inetpub\wwwroot\myfile.xml” variable=”XMLFileText” charset=”UTF-8″>
<cfset MyXMLDoc = xmlParse(XMLFileText)>
<cfset MyXMLNodes = xmlSearch(MyXMLDoc,’/Values/Comment’)>
<cfloop from=”1″ to=”#arraylen(MyXMLNodes)#” index=”i”>
<cfset GetXMLNodes = xmlparse(MyXMLNodes[i])>
<cfset ID = GetXMLNodes.Comment.CommentID.xmlText>
<cfset type = GetXMLNodes.Comment.CommentType.xmlText>
<cfset message = GetXMLNodes.Comment.CommentMessage.xmlText>
</cfloop>

Categories: coldfusion Tags: , ,

Generate RSS Feed with ColdFusion MX

January 1, 2009 ppshein Leave a comment

Do you know how to generate RSS Feed with ColdFusion MX? If you don’t know well about CFMX, it might be complicated and fussy. But you little know about XML technology, it’s quite simple.

First of all, you need to put this, <cfsetting enablecfoutputonly=“yes”> at the top of the page. After that, output your query just like

<CFQUERY NAME=”RssQry” datasource=”MyDSN”>
SELECT *
FROM    RssTable
WHERE  Rss_status = <cfqueryparam cfsqltype=”CF_SQL_INTEGER” null=”no” value=”1″>
ORDER   BY Rss_id
</CFQUERY>

<cfsavecontent variable=”theXML”>
<cfoutput><?xml version=”1.0″ encoding=”ISO-8859-1″ ?>
<rss version=”2.0″>
<channel>
<title>RSS</title>
<link>http://www.rss.com</link>
<description>This is Description</description>
<language>en-us</language>
<copyright>Copyright — .</copyright>
<docs>http://—–.com/rss/</docs>
<lastBuildDate>#dateformat(now(), “ddd, dd mmm yyyy”)# #timeformat(now(), “HH:mm:ss”)# EST</lastBuildDate>
</cfoutput>

<cfloop from=”1″ to=”#RssQry.RecordCount#” index=”ctr”>
<cfscript>
title = replace(RssQry.Rss_title[ctr], “<”, “&lt;”, “ALL”);
description = replace(RssQry.Rss_description[ctr], “<”, “&lt;”, “ALL”);
description = replace(description, “&”, “&amp;”, “ALL”);
description = replace(description, ‘”‘, “‘”, “ALL”);
date = dateformat(RssQry.Rss_posted_date[ctr], “ddd, dd mmm yyyy”);
time = timeformat(RssQry.Rss_posted_date[ctr], “HH:mm:ss”) & ” EST”;
author = replace(RssQry.Rss_author[ctr], “<”, “&lt;”, “ALL”);
author_email = replace(RssQry.Rss_author_email[ctr], “at>”, “@”, “ALL”);
author_email = replace(author_email, “<”, “&lt;”, “ALL”);
</cfscript>

<cfoutput>
<item>
<title>#title#</title>
<description>#description#</description>
<link>http://tutorial#RssQry.Rss_id[ctr]#.easycfm.com</link>
<author>#author_email# (#author#)</author>
<pubDate>#date# #time#</pubDate>
</item>
</cfoutput>
</cfloop>
<cfoutput>
</channel>
</rss>
</cfoutput>
</cfsavecontent>

Categories: coldfusion Tags: ,