1 Reply Latest reply on Apr 18, 2009 5:47 AM by wvxvw

    e4x Problem: How to Split XML Strings?

    alice_data Level 1

      Hi,

       

      I have the XML snippet here as one of the entries:

      <book name="My Sister's Closet">              
                       <appt type="commission" date="09/29/2008"/>
                       <appt type="review" date="10/05/2008"/>
                       <appt type="publish" date="10/19/2008"/>
                       <appt type="sales mark" date="11/20/2008"/>                              
                       <appt type="sales mark" date="12/21/2008"/>         
                      <appt type="sales mark" date="12/24/2008"/>   
      </book>

       

      There are many more entries before and after this with the similar format. What I wanted to do is to say, a person selects 09/29/2008, and he also selected the book name as My Sister's Closet, the result in the Actioinscript should bring back all the other book.@name(s) as the result.

      I tried fiddling around with it and I don't have any luck on getting accurate results, here is the code:

       

                  var date:String=DateChooser(event.currentTarget).selectedDate.getDate().toString();
                  var month:String= DateChooser(event.currentTarget).selectedDate.getMonth().toString();
                  var year:String= DateChooser(event.currentTarget).selectedDate.getFullYear().toString();                        
                  wholeDate= new Date(year,month,date);       
                  xlc = new XMLListCollection(searchResult..book.(@name == selectedName));
                  xlc2 = new XMLListCollection(searchResult..book.(@name == selectedName).appt.@date);     
                  input = [];
                
                 for each (xml2 in xlc2) {
                      var real_date:Date = new Date(xml2.toString());
                   var schedule_name:String = xml2.parent().@type.toString();
                   var real_date2:String; 
                  if (wholeDate.toDateString() == real_date.toDateString()){
                        trace(wholeDate.toDateString());
                        trace(real_date.toDateString());
                    for each (xml in xlc)
                    {
                            var dates:XMLList = xml..@date;
                            trace(dates.length());
                            trace(dates.toXMLString()); 
                            for (var i:int=0;i<dates.length;i++) {
                                trace(dates[i].toString());
                            }      
                          
                            var date3:Date = new Date(dates.toXMLString());         
                            trace(date3.toDateString());  //I get invalid date with this one
                            trace(real_date.toDateString());

       

                         //This does not work as a result of what I ahve from above
                            if (date3.toDateString() == real_date.toDateString()) {
                                trace("New Date " + date3.toDateString());
                            }

                        }
                    }
               }

       

      Right now, I can get the correct node count in the book element.

      However, it appears to me that dates.toXMLString is a long string and I am not sure why I cannot use a for each to parse it.

      I hope this makes sense. Have I selected the wrong node of what I am doing here? Anything is appreciated.

       

      Alice

        • 1. Re: e4x Problem: How to Split XML Strings?
          wvxvw

          Well, it seems like I keep answering it all ower agian

           

          But, I was just thinking that another way of doing it would be like this:

           

          say, you have this XMLList:

           

          var xml:XML =

          <book name="My Sister's Closet">              
                           <appt type="commission" date="09/29/2008"/>
                           <appt type="review" date="10/05/2008"/>
                           <appt type="publish" date="10/19/2008"/>
                           <appt type="sales mark" date="11/20/2008"/>                              
                           <appt type="sales mark" date="12/21/2008"/>         
                          <appt type="sales mark" date="12/24/2008"/>   
          </book>;

           

          var list:XMLList = xml..*.@date;

          var dates:Array = [];

          list.(dates.push(valueOf()));

           

          trace(dates.join("\r"));