Sorry about the late reply, thanks Stephen, worked like a charm.
Peter, you requested the correct code when it was found . it's below :o).
One more question regarding xml /cfmx, is I may..
I have the following loop..
<cfscript>
for (i=1; i lte arraylen(count_dropdowns_t); i=i+1) {
//count_dropdowns_t is the parent's xmlchildren array
thisElement2 = StructNew();
thisElement2 = count_dropdowns_t[i];
//
if (thisElement2.xmlattributes["name"] is "#ivan#"){
//
trythis = XmlElemNew(mydrop,"drop_item");
structinsert(trythis,"xmltext","new model");
arrayappend(thiselement2,trythis);
}
}
</cfscript>
I'm trying to add an element where the attributes.name is #ivan#
Following the references I've seen, (docs, nate's xml/xslt pdf, this looks
right.. But it keeps comming back as "trythis" is undefined.. is there a
syntax error I'm missing or something? (the error line is on the
structinsert()line, ) My looking at the example in the pdf, mine is
essentially the same abiet it's not in cfset tags....
Shed any light?
Robby
trythis= XmlElemNew(mydrop,"drop_item");
structinsert(trythis,"xmltext","new model");
arrayappend(thiselement2,trythis);*/
}
}
</cfscript>
Subject: xml woes
From: "Stephen Moretti" Date: Mon, 17 Feb 2003 11:55:10 -0000
Robby,
I suspect this is probably a typo, but the closing tag of your xml packet
isn't a closing tag.
>Both of which bail.. the first one bails without an actual error,
>. just the araydeleteat() being the line it error'd at.
>But when I looked in to the logs,
>It says java.lang.IndexOutOfBoundsException and searching google only gave
>two results,
>. both of which have no bearing on the situation at hand.
>
Basically, this means that CF is trying to access a element in an array,
past the end of the array. eg. there are 2 elements in the array and you
are trying to access the third element.
Looking at your code. The reason for this is that you are using the "yes"
variable to store an array in both your outer "i" loop and your inner "j"
loop. You need to use different variables for each loop, otherwise you'll
be overwriting your outer array everytime you go around your inner array.
Also, I suspect that you are trying to delete the wrong bit of your array.
You need to be
Try this : (I warn you there maybe errors. I typed this from your code and
off the top of my head without testing it)
<cfscript>
// Loop over the children of c_dropx eg. <drop name="abba"> and <drop
name="1221">
for (i=1; i lte arraylen(c_dropx); i=i+1) {
// bung the structure for the current element into a new variable for ease
thisElement = StructNew();
thisElement = c_dropx[i];
// Check the attributes of thisElement to see it is abba.
if (thisElement.xmlattributes["name"] is "abba")
// Loop over the children for thisElement, which would be the same as
looping over the <drop_item> elements
for (j=1;j lte arraylen(thisElement.xmlChildren); j=j+1) {
// Store the current child structure in a variable thisChild for
ease
thisChild = StructNew();
thisChild = thisElement.xmlchildren[j];
if (thisChild.xmltext is "a") {
WriteOutput(j&" - "&thisChild.xmltext&"<BR>");
arraydeleteat(thisElement.xmlchildren, j);
}
}
}
</cfscript>
>The element at position 5 of dimension 1, of array variable "TT," cannot
be
>found is the one on the second try, and with it, the array itself is
cfdumped, and
>there is 5 elements in the array, I've read the docs
>I've double checked what I know how. What the hell am I doing wrong?
To be honest, I'm not sure what's up with your second bit of code. I
really need to play with xml in CFMX some more, but here's the cfscript
version of your code. I suspect, that you have the same problem here as you
do above, where you are trying to delete the array from the wrong place in
the data structure.
<cfscript>
for (i=1;i lte arraylen(tt); i=i+1) {
if (tt[i].xmltext is "a") {
arraydeleteat(tt, i);
}
}
</cfscript>
Hope some of this helps some how.
Regards
Stephen
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4
Subscription:
http://www.houseoffusion.com/cf_lists/index.cfm?method=subscribe&forumid=4
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Get the mailserver that powers this list at http://www.coolfusion.com
Unsubscribe:
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4