views:

55

answers:

3

How do I parse this structure? I need to turn this into single variables. E.g. from the attributes struct:

name

type

value

I'm not familiar with structures, and I need to enter this type of data into a database.

I've played around with cfloop, but nothing.

cfdump

+1  A: 

If you want to simply dump this structure, use a simple XML and store it in a CLOB or BLOB field. But if you want to perform operations such as search, frequent changes to the data, then its better you consider tree structures.

If you are using Oracle, take a look at CONNECT BY PRIOR, this makes you store values in the database directly as rows and later query them and load into a tree structure.

The gist here is you should both be able to store and retrieve data as if you are dealing with a simple TREE data structure.

Bragboy
well is there a way to get each field as a variable??? im using a function that parses a input as you see, now i just need the results so i can work with them. this function is located http://www.bennadel.com/blog/779-Parsing-HTML-Tag-Data-Into-A-ColdFusion-Structure.htm
loo
+5  A: 

Assuming your variable name is "foo", you can access the name like this

foo.attributes.name

Structures are simply accessed via dot notation.

Ben Doom
A: 

Along the same lines as what Ben said, I'm not sure why you'd want to pull this nice little struct apart. Use it in its current form by accessing the values inside it rather than disassembling it.

<cfloop collection="#foo.attributes#" item="myKey">
    <cfoutput>Value of #myKey# is #structFind(foo.attributes, myKey)#</cfoutput>
</cfloop>

Refer to the LiveDocs' structure looping page for more details.

Adam Bellas