Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

parsing xml with two elements named the same

Status
Not open for further replies.

PushCode

Programmer
Dec 17, 2003
573
0
0
US
I have some xml that I'm parsing. Within each structure there are two elements called <link> I need to reference only the second one.

Here's an example of the xml
Code:
<entry xmlns="[URL unfurl="true"]http://purl.org/atom/ns#">[/URL]
	<link href="[URL unfurl="true"]https://www.blogger.com/atom/13468992/113467358910280087"[/URL] rel="service.edit" title="Lily-Beignet Finds A Home" type="application/atom+xml"/>
	<author>
		<name>Blythe</name>
	</author>
	<issued>2005-12-15T10:23:00-08:00</issued>
	<modified>2005-12-15T19:08:07Z</modified>
	<created>2005-12-15T19:06:29Z</created>
	<link href="[URL unfurl="true"]http://shelterlife.blogspot.com/2005/12/lily-beignet-finds-home.html"[/URL] rel="alternate" title="Lily-Beignet Finds A Home" type="text/html"/>
	<id>tag:blogger.com,1999:blog-13468992.post-113467358910280087</id>
	<title mode="escaped" type="text/html">Lily-Beignet Finds A Home</title>
	<content type="application/xhtml+xml" xml:base="[URL unfurl="true"]http://shelterlife.blogspot.com"[/URL] xml:space="preserve">
		One of our hurricane dogs, Beignet (Lily to her foster) found a home yesterday. She was adopted by her foster family...
	</content>
	<draft xmlns="[URL unfurl="true"]http://purl.org/atom-blog/ns#">false</draft>[/URL]
</entry>

I need to reference the second <link> element...the one that links to
The way my code is set up right now, it is referencing the first link element. Here's how I'm looping throught the xml:
Code:
<cfloop index="x" from="1" to="11"><!--- #arrayLen(entries)# --->
	<cfset node = structNew() />
	<cfset node.author = entries[x].author.name.xmlText />
	<cfset node.link = entries[x].link.xmlAttributes.href />
	<cfoutput>
		
			<u>Most Recent Entry</u>:<br><br>
			Author: #node.author#<br>
			Link: #node.link#<br>
	</cfoutput>
</cfloop>

Can anyone tell me how to set node.link to the second <link> element instead of the first?

Thanks!
 
I figured it out:

<cfset node.link = entries[x].link[2].xmlAttributes.href />
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top