> On Feb 3, 2004, at 12:54 PM, Justin Balog wrote:
> > Would an XPathQueryString look like to find the attributes of an XML
> > tag?
>
> No. XmlSearch() returns "An array of XML object nodes that match the
> search criteria". An attribute is not an "XML object node" so you have
> to get the nodes back and then drill into them:

For the DOM specs, an attribute is a node (actually an ATTRIBUTE_NODE, but
still a node, fully implementing the node interface).

The only (indeed annoying) limitation in XmlSearch() is that it throws an
exception if the XPath expression doesn't return a NodeList (I am using DOM
nomenclature here) but, instead, it return a string, a boolean or a number.
So, in this specific case, we could get the attribute node directely using
XPath, because we extract a NodeList. In order to get the value of the
attribute ("100lbs" as a string) an additional step is required. Something
like:

<cfsavecontent variable="xmlStr">
<parent>
<child name="jo">
<weight value="100lbs"/>
</child>
</parent>
</cfsavecontent>
<cfset xmlDoc=XmlParse(xmlStr)>
<cfset nodeList=XmlSearch(xmlDoc,"/parent/child/weight/@value")>
<cfdump var="#nodeList[1].getNodeValue()#">

If you want to have fun and see <cfdump> getting confused, try this.
<cfdump> is getting something like an attribute node but it's unable to
recognize it:

<cfdump var="#nodeList[1]#">


In general I like the way XML was implemented in CF MX. In a typical
"fusionesque" way, it's simple, yet powerful.

Unfortunately, I think the docs are at least misleading, mixing the very
specific way XML works in CFML with W3C's DOM specs. Mixing terms that have
a very specific meaning inside the DOM specs with other that have not. The
docs even say that "ColdFusion conforms to the DOM Level 2 Core
specification". In my opinion this is both wrong and misleading...

It's clear CFML use Java's DOM under the hood, but a "XML document objects"
in CFML (please note there isn't any equivalent inside the DOM specs, this
is a CFML specific term) doesn't provide a full DOM implementation. Most of
the time is easier/faster than a "real" DOM, it may also somewhat behave
like a DOM, but it's not a DOM :-)))

----------------------------
Massimo Foti
http://www.massimocorner.com

Co-Author of Dreamweaver MX 2004 Magic:
http://www.dwmagic.com/









> > <parent>
> > <child name="jo">
> > <weight value="100lbs"/>
> > </child>
> > </parent>
>
> I think the following will work:
>
> <cfset jo_weights = XmlSearch(xmlDoc,"parent/[EMAIL PROTECTED]'jo']/weight")
> />
> <cfset jo_weight = jo_weights[1].XmlAttributes["value"] />
>
> Regards,
> Sean
>
> ----------------------------------------------------------
> You are subscribed to cfcdev. To unsubscribe, send an email
> to [EMAIL PROTECTED] with the words 'unsubscribe cfcdev'
> in the message of the email.
>
> CFCDev is run by CFCZone (www.cfczone.org) and supported
> by Mindtool, Corporation (www.mindtool.com).
>
> An archive of the CFCDev list is available at
www.mail-archive.com/[EMAIL PROTECTED]
>
>


----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email
to [EMAIL PROTECTED] with the words 'unsubscribe cfcdev' 
in the message of the email.

CFCDev is run by CFCZone (www.cfczone.org) and supported
by Mindtool, Corporation (www.mindtool.com).

An archive of the CFCDev list is available at www.mail-archive.com/[EMAIL PROTECTED]

Reply via email to