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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

determining if xml node exists

Status
Not open for further replies.

johne417

Programmer
Sep 18, 2001
23
US
I'm having a problem determining if an XML node exists or not. Under the node of 'Flight', there's a few children. The first child is 'Time'. The second node is 'Date'. The possible third, fourth, and fifth nodes are one of 3 possible things (if they exist): 'Scheduled', 'Actual', or 'Estimated'. Any of these last three nodes may or may not exist, and in any order.

root
Flight
Date
Time
Scheduled
Estimated
Actual
[or]
root
Flight
Date
Time
Actual

and so on

Is there a way to determine if the node Flight.Scheduled exists?

This code:
<cfset xmlnode = flightXML.xmlroot>
<cfif isDefined(xmlnode.flight.scheduled)>
produces an error on the second when the node doesn't exist.

Looks like there's probably a really ugly brute force way to do this, but it seems like there should be some sort of nodeExists() method or something. Is there? Thanks in advance for any help.

 
I believe you'd have to use
Code:
XMLSearch()
with a dynamic xpath to try to find the specific nodes. If they don't exist, XMLSearch would return the returned array would be empty.

Either that or you need to create a structure from your XML doc (I'm pretty sure there are custom tags available on Macromedia's developer exchange that can do it for you... or it's not too hard to write it yourself), then use IsDefined() or StructKeyExists() on the structure.


-Carl
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top