Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

having parsing xml like below into a struct.

Enthusiast ,
Nov 10, 2010 Nov 10, 2010

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

760
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Nov 10, 2010 Nov 10, 2010

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).

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Nov 10, 2010 Nov 10, 2010

still gives me the same xml string, no arrays

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 10, 2010 Nov 10, 2010

Just a quick question: why are you trying to convert your XML into a struct?

--

Adam

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Nov 10, 2010 Nov 10, 2010

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Nov 11, 2010 Nov 11, 2010

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Nov 11, 2010 Nov 11, 2010

ah, very cool

xml document [short version]
XmlComment
XmlRoot
xml element
XmlNametaskConditions
XmlNsPrefix
XmlNsURI
XmlText
XmlComment
XmlAttributes
struct [empty]
XmlChildren
xml element
XmlNameCondition
XmlNsPrefix
XmlNsURI
XmlText
XmlComment
XmlAttributes
struct
conditionEnabled1
nameMONDAY
XmlChildren
xml element
XmlNameCondition
XmlNsPrefix
XmlNsURI
XmlText
XmlComment
XmlAttributes
struct
conditionEnabled1
nameTUESDAY
XmlChildren
taskConditions
XmlText
Condition
XmlText
XmlAttributes
struct
conditionEnabled1
nameMONDAY
Condition
XmlText
XmlAttributes
struct
conditionEnabled1
nameTUESDAY

xml document [short version]
XmlComment
XmlRoot
xml element
XmlNametaskConditions
XmlNsPrefix
XmlNsURI
XmlText
XmlComment
XmlAttributes
struct [empty]
XmlChildren
xml element
XmlNameCondition
XmlNsPrefix
XmlNsURI
XmlText
XmlComment
XmlAttributes
struct
conditionEnabled1
nameTUESDAY
XmlChildren
xml element
XmlNameCondition
XmlNsPrefix
XmlNsURI
XmlText
XmlComment
XmlAttributes
struct
conditionEnabled1
nameTHURSDAY
XmlChildren
taskConditions
XmlText
Condition
XmlText
XmlAttributes
struct
conditionEnabled1
nameTUESDAY
Condition
XmlText
XmlAttributes
struct
conditionEnabled1
nameTHURSDAY

xml document [short version]
XmlComment
XmlRoot
xml element
XmlNametaskConditions
XmlNsPrefix
XmlNsURI
XmlText
XmlComment
XmlAttributes
struct [empty]
XmlChildren
xml element
XmlNameCondition
XmlNsPrefix
XmlNsURI
XmlText
XmlComment
XmlAttributes
struct
conditionEnabled1
nameWEDNESDAY
XmlChildren
taskConditions
XmlText
Condition
XmlText
XmlAttributes
struct
conditionEnabled1
nameWEDNESDAY

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;
                    }
                }

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Nov 11, 2010 Nov 11, 2010

think its something like this:

    test = xmlParse(data.conditionsXML);   
                           
                            test2 =test.taskConditions.XmlChildren;
                           
                            for (y = 1; y <= ArrayLen(test.taskConditions.XmlChildren); y=y+1) {

                           
                            }

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Nov 11, 2010 Nov 11, 2010

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.XmlAttributes.name;
                               st.item2 = item2;

                            }

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 12, 2010 Nov 12, 2010

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Nov 12, 2010 Nov 12, 2010

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;
                    }
                }

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Nov 17, 2010 Nov 17, 2010
LATEST

figured it, I needed to use this to create the dictionary

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources