Copy link to clipboard
Copied
I'm having parsing xml like below into a struct. I tried this function but that just gives me the 1st <Condition's attribute in a resultant struct
<taskConditions>
<Condition name="TUESDAY" conditionEnabled="1" />
<Condition name="THURSDAY" conditionEnabled="1" />
</taskConditions>
ASTR
Condition [, ]
[1]
[2]
Condition_attributes
conditionEnabled 1
name TUESDAY
What happend tp the thursday attributes ?
thanks
Copy link to clipboard
Copied
Did you try xmlParse()? It is not a CF structure per se., but very similar (you can walk the arrays but you can't StructCopy or StructAppend).
Copy link to clipboard
Copied
still gives me the same xml string, no arrays
Copy link to clipboard
Copied
Just a quick question: why are you trying to convert your XML into a struct?
--
Adam
Copy link to clipboard
Copied
Did you try doing a CFDUMP of the xmlParse result? Thursday is contained in the name attribute within the xmlAttributes element of each "condition" element. CFDUMP is your friend.
Copy link to clipboard
Copied
Just a quick question: why are you trying to convert your XML into a struct?
because I will be looping through each row and be performing some code
Copy link to clipboard
Copied
ah, very cool
xml document [short version] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
XmlComment | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
XmlRoot |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
taskConditions |
|
xml document [short version] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
XmlComment | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
XmlRoot |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
taskConditions |
|
xml document [short version] | |||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
XmlComment | |||||||||||||||||||||||||||||||||||||||||
XmlRoot |
| ||||||||||||||||||||||||||||||||||||||||
taskConditions |
|
I'm trying to mimic a flex filter function and I'm not sure how to implement it in a cfscript. I basicallly need to put each condidtion name ie, Tuesday into a dictionary and then in the code test for each condition ie in flex I done this:
the code I'm trying to do in cf is
var conditionsD:Dictionary=new Dictionary
for each(var o:Object in conditions)
{
conditionsD[o.name]=true;
}
From this code in flex
var conditions:ArrayCollection=convertXmlToArrayCollection(new XMLDocument(item.conditionsXML));
//create a dictionary asour conditions are strings
var conditionsD:Dictionary=new Dictionary
for each(var o:Object in conditions)
{
conditionsD[o.name]=true;
}
//now we finally validate,
if (conditionsD['SUNDAY'])
{
if (today.day == 0)
{
return true;
}
}
if (conditionsD['MONDAY'])
{
if (today.day == 1)
{
return true;
}
}
if (conditionsD['TUESDAY'])
{
if (today.day == 2)
{
return true;
}
}
Copy link to clipboard
Copied
think its something like this:
test = xmlParse(data.conditionsXML
test2 =test.taskConditions.XmlChildren;
for (y = 1; y <= ArrayLen(test.taskConditions.XmlChildren); y=y+1) {
}
Copy link to clipboard
Copied
this does what I need, but I really need a dictionary datatype wich cf doesnt seem to have
test = xmlParse(data.conditionsXML
test2 =test.taskConditions.XmlChildren;
len = ArrayLen(test2);
st = structNew();
for (y = 1; y <= len; y=y+1) {
item = test2
item2 = test2
st.item2 = item2;
}
Copy link to clipboard
Copied
Are you under the impression you cannot loop through XML node sets? Or is it something else? Because needing to loop over the data and "performing some code" is not a good reason to be potentially wasting time converting the XML to a struct to do so.
What is it about the data (or it's structure) that necessitates you converting it from XML to a struct before you can do what you want to it?
--
Adam
Copy link to clipboard
Copied
I need to cach the xml into a dictionary because of the kind of test that I will perform, I don't want
to perform the tests below each time for each xml row
//now we finally validate,
if (conditionsD['SUNDAY'])
{
if (today.day == 0)
{
return true;
}
}
if (conditionsD['MONDAY'])
{
if (today.day == 1)
{
return true;
}
}
if (conditionsD['TUESDAY'])
{
if (today.day == 2)
{
return true;
}
}
Copy link to clipboard
Copied
figured it, I needed to use this to create the dictionary