• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Parsing XML

Engaged ,
Sep 22, 2006 Sep 22, 2006

Copy link to clipboard

Copied

I've used CFMX7 to parse several XML documents, but I'm having trouble with the XML syntax of my latest assignment when there is a colon ( : ) in the XML tag. Help is appreciated:

XML Sample Snippet:

<rdf:RDF xmlns=" http://purl.org/rss/1.0/">
<channel rdf:about=" http://somewebsite/somedirectory/">
</channel>
<item rdf:about=" http://somewebsite/somedirectory/somestory.html">
</item>
</rdf:RDF>

My code:

<cfset ParsedRSSData = XMLParse(XmlObj)>

#ArrayLen(XMLSearch(ParsedRSSData,"rdf:RDF/"))# ----> results in 1.

However, #ArrayLen(XMLSearch(ParsedRSSData,"rdf:RDF/channel/"))# ----> Results in 0. Why?

Also trying to display data, #ParsedRSSData.rdf:RDF.XmlAttributes.xmlns# ----> Results in a CF error:

Invalid CFML construct

ColdFusion was looking at the following text:

:

How do I structure the CF code to handle the colons ( : ) in the XML?

Thanks!
TOPICS
Advanced techniques

Views

404

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 22, 2006 Sep 22, 2006

Copy link to clipboard

Copied

LATEST
This is how I handled this issue. I used XSLT and xmlTransform()
functions instead of the xmlSearch() function. HTH.

<cfhttp url=" http://www.houseoffusion.com/groups/Flex/RSS.cfm"
method="get" />
<cfset HOF = XMLParse(cfhttp.filecontent)>

<cfhttp
url=" http://weblogs.macromedia.com/product_feeds/archives/flex/index.rdf"
method="get" />
<cfset Adobe = XMLParse(cfhttp.filecontent)>

<cffile action="read" file="G:\playground\rss_feeds\rss_1.xsl"
variable="RSS_1">

<cffile action="read" file="G:\playground\rss_feeds\rss_2.xsl"
variable="RSS_2">

<cfoutput>#xmlTransform(HOF,RSS_2)#</cfoutput>
<hr />
<cfoutput>#xmlTransform(Adobe,RSS_1)#</cfoutput>

And the XSLT files:

RSS_1.xsl
---------
<?xml version="1.0" encoding="iso-8859-1"?><!--
DWXMLSource=" http://www.adobe.com/cfusion/webforums/forum/rss.cfm?forumid=60&catid=585"
-->
<!DOCTYPE xsl:stylesheet [
<!ENTITY nbsp "&#160;">
<!ENTITY copy "&#169;">
<!ENTITY reg "&#174;">
<!ENTITY trade "&#8482;">
<!ENTITY mdash "&#8212;">
<!ENTITY ldquo "&#8220;">
<!ENTITY rdquo "&#8221;">
<!ENTITY pound "&#163;">
<!ENTITY yen "&#165;">
<!ENTITY euro "&#8364;">
]>
<xsl:stylesheet
version="1.0"
xmlns:xsl=" http://www.w3.org/1999/XSL/Transform"
xmlns:rss=" http://purl.org/rss/1.0/"
xmlns:rdf=" http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:dc=" http://purl.org/dc/elements/1.1/">

<xsl:output method="html" encoding="iso-8859-1"/>

<xsl:template match="/">
<h2><xsl:value-of select="rdf:RDF/rss:channel/rss:title"/></h2>
<p><xsl:value-of select="rdf:RDF/rss:channel/rss:description"/></p>
<ul>
<xsl:for-each select="rdf:RDF/rss:item">
<li>
<xsl:element name="a">
<xsl:attribute name="href">viewLink.cfm?url=<xsl:value-of
select="rss:link"/></xsl:attribute>
<xsl:value-of select="rss:title"/>
</xsl:element>
</li>
</xsl:for-each>
</ul>
</xsl:template>
</xsl:stylesheet>

rss_2.xsl
---------
<?xml version="1.0" encoding="iso-8859-1"?><!--
DWXMLSource=" http://www.houseoffusion.com/groups/CF-Talk/RSS.cfm" -->
<!DOCTYPE xsl:stylesheet [
<!ENTITY nbsp "&#160;">
<!ENTITY copy "&#169;">
<!ENTITY reg "&#174;">
<!ENTITY trade "&#8482;">
<!ENTITY mdash "&#8212;">
<!ENTITY ldquo "&#8220;">
<!ENTITY rdquo "&#8221;">
<!ENTITY pound "&#163;">
<!ENTITY yen "&#165;">
<!ENTITY euro "&#8364;">
]>
<xsl:stylesheet version="1.0"
xmlns:xsl=" http://www.w3.org/1999/XSL/Transform"
xmlns:sy=" http://purl.org/rss/1.0/modules/syndication/"
xmlns:dc=" http://purl.org/dc/elements/1.1/">

<xsl:output method="html" encoding="iso-8859-1"/>

<xsl:template match="/">
<h2><xsl:value-of select="rss/channel/title"/></h2>
<p><xsl:value-of select="rss/channel/description" /></p>
<ul>
<xsl:for-each select="rss/channel/item">
<li>
<xsl:element name="a">
<xsl:attribute name="href">viewLink.cfm?url=<xsl:value-of
select="guid"/></xsl:attribute>
<xsl:value-of select="title" />
</xsl:element>
</li>
</xsl:for-each>
</ul>
</xsl:template>
</xsl:stylesheet>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation