<cfxml variable="myXML">
<root>
 <colors>
   <color>
     <cname>24K</cname>
     <type>flek</type>
     <value>0xfbe680</value>
     <price>0</price>
     <cid>1</cid>
   </color>
   <color>
     <cname>Black Mist</cname>
     <type>flek</type>
     <value>0x222222</value>
     <price>0</price>
     <cid>1</cid>
   </color>
 </colors>
</root>
</cfxml>

<!--- Search String --->
<cfset sSearch = "Black Mist">

<!--- Location of the color found  --->
<cfset indexLocation = 0>

<!--- Root --->
<cfset nRoot = myXML.XMLRoot>

<!--- Colors Root --->
<cfset nColors = nRoot.XMLChildren[1]>

<cfloop from="1" to="#ArrayLen(nColors.XMLChildren)#" index="i">

    <!--- Color node currently looping through --->
    <cfset nColor = nColors.XMlChildren[i]>

    <cfset nCname = nColor["cname"]>

    <cfif Trim(nCname.xmlText) eq sSearch>
        <cfset indexLocation = i>
    </cfif>

</cfloop>

<cfoutput>#indexLocation#</cfoutput>


On 1/5/07, Phill B <[EMAIL PROTECTED]> wrote:
>
> I have this XML
> <root>
> <colors>
>    <color>
>      <cname>24K</cname>
>      <type>flek</type>
>      <value>0xfbe680</value>
>      <price>0</price>
>      <cid>1</cid>
>    </color>
>    <color>
>      <cname>Black Mist</cname>
>      <type>flek</type>
>      <value>0x222222</value>
>      <price>0cid>
>    </color>
> </colors>
> </root>
>
> I need to query the <cname> for the value "Black Mist". Then I need to
> get the index of its parent <color>. How the heck do I go about this?
> I found that I can search for the cname value using this
> XMLSearch(colorXML, "/root/colors/color/cname[. ='Black Mist']") Now
> how do I get the parent position so that I can display all the nodes
> in <color> ?
>
> --
> Phil
>
> 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Create robust enterprise, web RIAs.
Upgrade & integrate Adobe Coldfusion MX7 with Flex 2
http://ad.doubleclick.net/clk;56760587;14748456;a?http://www.adobe.com/products/coldfusion/flex2/?sdid=LVNU

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:265810
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4

Reply via email to