2 Replies Latest reply on Sep 23, 2010 9:28 AM by Extreme911

    XML->VoObj and VoObj -> XML

    Extreme911

      I have a problem with creating proper VO object for the following xml:

       

      example:

       

      <Journey>
                 <Origin LocationCode="SYD" CodeContext="CRS"/>
                 <Destination LocationCode="GOS" CodeContext="CRS"/>
                 <DateTime>
                      <OutBound>
                              <DepartureDateTime WindowAfter="P1970Y1M1DT7H">2010-02-18T06:43:00</DepartureDateTime>
                      </OutBound>
                 </DateTime>
      </Journey>

       

       

      The problem is with the RED part of the xml... How do i create a VOobject for this so i can TypeCast my ObjXml to VoObj ?

       

      Also How my VO class should look if i want to get exact same XML if i will encode it from my VOt?

       

       

      Thanks.

        • 2. Re: XML->VoObj and VoObj -> XML
          Extreme911 Level 1

          Thanks for a quick reply...

          I wish it was that simple... however... here is a source.

          Im basicaly loading XML to the obj, and then converitng it back to xml..

           

          ////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////

           

           

          <?xml version="1.0" encoding="utf-8"?>

          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"   xmlns:reservation="services.reservation.*" creationComplete="application_creationCompleteHandler(event)">

          <mx:Script>

          <![CDATA[

          import mx.controls.Alert;

          import mx.events.FlexEvent;

          import mx.rpc.events.FaultEvent;

          import mx.rpc.events.ResultEvent;

          import mx.rpc.events.SchemaLoadEvent;

          import mx.rpc.events.XMLLoadEvent;

          import mx.rpc.xml.Schema;

          import mx.rpc.xml.SchemaLoader;

          import mx.rpc.xml.SchemaManager;

          import mx.rpc.xml.SchemaTypeRegistry;

          import mx.rpc.xml.SimpleXMLDecoder;

          import mx.rpc.xml.SimpleXMLEncoder;

          import mx.rpc.xml.XMLDecoder;

          import mx.rpc.xml.XMLEncoder;

          import mx.utils.ObjectUtil;

           

           

           

           

           

          protected function application_creationCompleteHandler(event:FlexEvent):void

          {

           

          /* Convert XMLNode to XMLDocument. */

          var xmlStr:String = <Journey>

          <Origin LocationCode="SYD" CodeContext="CRS"/>

          <Destination LocationCode="GOS" CodeContext="CRS"/>

          <DateTime>

          <OutBound>

          <DepartureDateTime WindowAfter="P1970Y1M1DT7H">2010-02-18T06:43:00</DepartureDateTime>

          </OutBound>

          </DateTime>

          </Journey>;

           

          var xmlDoc:XMLDocument = new XMLDocument(xmlStr);

          var decoder:SimpleXMLDecoder = new SimpleXMLDecoder(true);

          var resultObj:Object = decoder.decodeXML(xmlDoc);

          var xml:XML = objectToXML(resultObj);

           

          }

           

           

          private function objectToXML(obj:Object):XML {

          var qName:QName = new QName("root");

          var xmlDocument:XMLDocument = new XMLDocument();

          var simpleXMLEncoder:SimpleXMLEncoder = new SimpleXMLEncoder(xmlDocument);

          var xmlNode:XMLNode = simpleXMLEncoder.encodeValue(obj, qName, xmlDocument);

          var xml:XML = new XML(xmlDocument.toString());

          trace(xml.toXMLString());

          return xml;

          }

           

          ]]>

          </mx:Script>

          <mx:CallResponder id="RailDist_ScheduleAvailabilityResult"/>

          <reservation:Reservation id="reservation" fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)" showBusyCursor="true"/>

          <mx:CallResponder id="RailDist_ScheduleAvailabilityResult2"/>

           

           

           

           

          </mx:Application>

           

           

          ////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////// /

           


           

          And its not the same as

          <DepartureDateTime WindowAfter="P1970Y1M1DT7H">2010-02-18T06:43:00</DepartureDateTime>

           

          i need to recreate exact copy of this TAG and not <value>2010-02-18T06:43:00</value>

           

          RETURN WOULD BE:

           

           

            <Journey>

              <DateTime>

                <OutBound>

                  <DepartureDateTime>

                    <value>2010-02-18T06:43:00</value>     // This part is not good. has to be as before

                    <WindowAfter>P1970Y1M1DT7H</WindowAfter>

                  </DepartureDateTime>

                </OutBound>

              </DateTime>

              <Destination>

                <CodeContext>CRS</CodeContext>

                <LocationCode>GOS</LocationCode>

              </Destination>

              <Origin>

                <CodeContext>CRS</CodeContext>

                <LocationCode>SYD</LocationCode>

              </Origin>

            </Journey>

           

          Message was edited by: Extreme911