Skip navigation
Sign in
0
Search forums only
Search forums only
Cancel
Adobe
Support Home
Forums Home
News
People
Product
Menu begins
Adobe Creative Cloud
Downloading, Installing, Setting Up
Adobe Experience Cloud
Adobe Flash Player
Acrobat Reader
Adobe Acrobat
Adobe Photoshop
Adobe Photoshop Lightroom
Adobe Photoshop Elements
Adobe Dreamweaver
Adobe Muse
Adobe Animate CC
Adobe Premiere Pro
Adobe After Effects
Adobe Illustrator
Adobe InDesign
View all communities
Explore
Menu begins
Meet the experts
Learn our products
Get inspired in the lounge
Read the blog
Error: You don't have JavaScript enabled. This tool uses JavaScript and much of it will not work correctly without it enabled. Please turn JavaScript back on and reload this page.
Please enter a title.
You can not post a blank message. Please type your message and try again.
More discussions
in
Advanced Techniques
All Communities
ColdFusion
Advanced Techniques
3 Replies
Latest reply
on Apr 12, 2007 10:05 AM by Anthony Spears
Looping through xml
Anthony Spears
Apr 11, 2007 2:21 PM
This is the situation. I am parsing xml and putting it into a cfquery.
This is the basic structure of the xml
<year count=1 value=90>
<tag1>300</tag1>
<tag2>400</tag2>
</year>
<year value=91>
<tag1>100</tag1>
<tag2>200</tag2>
</year>
<year value=92>
<tag1>500</tag1>
</year>
Tag1 will always exist and Tag2 only sometimes
I am looping through the xml and putting it into a query which looks pretty much like this.
Year Tag1 Tag2
How do I detect to see if tag2 exists under each year tag and then insert the value into the query or put zero into the query when it doesn't exist?
Thanks in advance.
This content has been marked as final.
Show 3 replies
1.
Re: Looping through xml
cf_dev2
Apr 11, 2007 7:49 PM
(
in response to Anthony Spears
)
Have you tried StructKeyExists(). It seems to work with 7.0.2
...
<cfset xml = XMLParse(xmlString)>
<cfif structKeyExists(xml.yourRootNode.year[3], "tag2")>
Exists
<cfelse>
Not Exists
</cfif>
2.
Re: Looping through xml
BKBK
Apr 11, 2007 10:09 PM
(
in response to Anthony Spears
)
XML is pedantic. Use quotes around the attribute values.
3.
Re: Looping through xml
Anthony Spears
Apr 12, 2007 10:05 AM
(
in response to Anthony Spears
)
Thank you cf_dev2 and BKBK. the StructKeyExists is what I was looking for.
BKBK - I know XML is pedantic. I just threw that example together for the purpose of asking the question.
Again, thank you both.
Actions
More Like This
Retrieving data ...
Legend
Correct Answers
- 10 points