3 Replies Latest reply on Sep 1, 2009 2:23 PM by babo_ya

    How to convert XML to Custom Type Object!!!!

    Phoenix_Guru Level 1

      How do we convert an XML to a custom type Value Object?

       

      I tried using SimpleXMLDecoder but it returns ObjectProxy not the custom type Value Object.

       

       

      Please help!!

       

      Thanks,

      Guruji..

        • 1. Re: How to convert XML to Custom Type Object!!!!
          babo_ya Level 3

          Let's say you have an XML as below..

           

          <Employee>

               <fName>John</fName>

               <lName>Barker</lName> .... my boss's last name

          </Employee>

           

           

          then here is how u create a VO.

           

          create a class called Employee that has two public variable fname, lname..

           

          var xml:XML = .. point to the above XML..

           

          var employee:Employee = new Employee();

          employee.fname = xml.fName;

          employee.lname = xml.lName;

           

          there is your VO.

           

          hope this helps,

           

          BaBo,

          • 2. Re: How to convert XML to Custom Type Object!!!!
            Phoenix_Guru Level 1

            Thanks for the reply..

             

            Your solution sounds only feasible for a small XML. In my case I have the XML as a result of the Webservice. which is very very huge and complex and i can't afford to manually assign individual variable values.

             

            Any other ideas??

            • 3. Re: How to convert XML to Custom Type Object!!!!
              babo_ya Level 3

              Yes,

              just assign the xml to the VO and don't parse it before you need it.

               

              for example,

               

              public class Employee
              {

               

                   private var xml:XML;

               

                   public function Employee()

                   {

               

                   }

               

                   public function parse(xml:XML):void

                   {

                        this.xml = xml;

                   }    

                   public function get fname():String

                   {

                        return xml.FName;

                   }

              }

               

              hope this helps,

               

              BaBo,