Read OPML File

Whipped out this little script to read an OPML file from Google Reader. Thought it may be handy.

<cfset GoogleOPMLFile = "C:/google-reader-subscriptions.xml" />
 
<cffile action="READ" variable="xml" file="#GoogleOPMLFile#" /> 
 
<cfset xmlDoc = XMLParse(xml) /> 
 
<cfset StartingDataNode = 2 />
 
<cfset Categories = ArrayLen( xmlDoc.opml.xmlChildren[2].XmlChildren ) />
 
<cfoutput>
 
<cfloop index="i" from="2" to="#Categories#">
 
  <strong>#xmlDoc.opml.xmlChildren[StartingDataNode].XmlChildren[i].XmlAttributes.Title#</strong>
  <ul>
  <cfloop index="j" from="1" to="#ArrayLen( xmlDoc.opml.xmlChildren[StartingDataNode].XmlChildren[i].XmlChildren )#">      	    
    <li>
      <a href="#xmlDoc.opml.xmlChildren[StartingDataNode].XmlChildren[i].XmlChildren[j].XmlAttributes.htmlURL#">
      #xmlDoc.opml.xmlChildren[StartingDataNode].XmlChildren[i].XmlChildren[j].XmlAttributes.title#</a>
    </li>      
  </cfloop>
  </ul>
 
</cfloop>
 
</cfoutput>

The code will display as follows:

Leave a Reply