10 Replies Latest reply on Apr 23, 2008 6:23 PM by dwwangrui

    Why can't got element from XML

    dwwangrui
      I try to load an XML element from an XML file using HTTPService Object . But The loaded object always null .

      Here is my XML Content
      <?xml version="1.0" standalone="no"?>
      <manifest identifier="imsmanifest.xml" version="1.3" xmlns=" http://www.imsglobal.org/xsd/imscp_v1p1" xmlns:adlcp=" http://www.adlnet.org/xsd/adlcp_v1p3" xmlns:adlseq=" http://www.adlnet.org/xsd/adlseq_v1p3" xmlns:imsss=" http://www.imsglobal.org/xsd/imsss" xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.imsglobal.org/xsd/imscp_v1p1 imscp_v1p1.xsd http://www.adlnet.org/xsd/adlcp_v1p3 adlcp_v1p3.xsd http://www.adlnet.org/xsd/adlseq_v1p3 adlseq_v1p3.xsd http://www.imsglobal.org/xsd/imsss imsss_v1p0.xsd">
      <metadata>
      <schema>ADL SCORM</schema>
      <schemaversion>CAM 1.3</schemaversion>
      </metadata>
      <organizations default="default_org">
      <organization identifier="default_org">
      <title>example_1</title>
      <item identifier="lesson1" identifierref="lesson1_ref">
      <title>Lesson_1_Interface</title>
      <imsss:sequencing xmlns:imsss=" http://www.imsglobal.org/xsd/imsss" xmlns:adlseq=" http://www.adlnet.org/xsd/adlseq_vlp3">
      <imsss:controlMode choiceExit="true" />
      </imsss:sequencing>
      </item>
      <item identifier="lesson2" identifierref="lesson2_ref">
      <title>Lesson_2_Toolbox</title>
      <imsss:sequencing xmlns:imsss=" http://www.imsglobal.org/xsd/imsss" xmlns:adlseq=" http://www.adlnet.org/xsd/adlseq_vlp3">
      <imsss:controlMode choiceExit="false" />
      </imsss:sequencing>
      </item>
      <item identifier="lesson3" identifierref="lesson3_ref">
      <title>Lesson_3_Palettes</title>
      <imsss:sequencing xmlns:imsss=" http://www.imsglobal.org/xsd/imsss" xmlns:adlseq=" http://www.adlnet.org/xsd/adlseq_vlp3">
      <imsss:controlMode choiceExit="true" />
      </imsss:sequencing>
      </item>
      <item identifier="lesson4" identifierref="lesson4_ref">
      <title>Lesson_4_Layers</title>
      <imsss:sequencing xmlns:imsss=" http://www.imsglobal.org/xsd/imsss" xmlns:adlseq=" http://www.adlnet.org/xsd/adlseq_vlp3">
      <imsss:controlMode choiceExit="true" />
      </imsss:sequencing>
      </item>
      <imsss:sequencing xmlns:imsss=" http://www.imsglobal.org/xsd/imsss" xmlns:adlseq=" http://www.adlnet.org/xsd/adlseq_vlp3">
      <imsss:controlMode flow="false" forwardOnly="true" choice="true" />
      </imsss:sequencing>
      </organization>
      </organizations>
      <resources>
      <resource identifier="lesson1_ref" adlcp:scormType="asset" type="webcontent" href="no title/Lesson 1 -- Interface/Lesson1.htm">
      <file href="no title/Lesson 1 -- Interface/Lesson1.htm" />
      <file href="no title/Lesson 1 -- Interface/images/headertop.gif" />
      <file href="no title/Lesson 1 -- Interface/images/headerside.gif" />
      <file href="no title/Lesson 1 -- Interface/images/pssidebar.gif" />
      <file href="no title/Lesson 1 -- Interface/images/LessonTitle1.gif" />
      <file href="no title/Lesson 1 -- Interface/images/interfacesmall.jpg" />
      <file href="no title/Lesson 1 -- Interface/images/EndOfLesson.gif" />
      </resource>
      <resource identifier="lesson2_ref" adlcp:scormType="asset" type="webcontent" href="no title/Lesson 2 -- Toolbox/Lesson2.htm">
      <file href="no title/Lesson 2 -- Toolbox/Lesson2.htm" />
      <file href="no title/Lesson 2 -- Toolbox/images/headertop.gif" />
      <file href="no title/Lesson 2 -- Toolbox/images/headerside.gif" />
      <file href="no title/Lesson 2 -- Toolbox/images/pssidebar.gif" />
      <file href="no title/Lesson 2 -- Toolbox/images/LessonTitle2.gif" />
      <file href="no title/Lesson 2 -- Toolbox/images/toolbox.gif" />
      <file href="no title/Lesson 2 -- Toolbox/images/selectiontools.gif" />
      <file href="no title/Lesson 2 -- Toolbox/images/enhancementtools.gif" />
      <file href="no title/Lesson 2 -- Toolbox/images/navagationtools.gif" />
      <file href="no title/Lesson 2 -- Toolbox/images/ZoomToolIcon.gif" />
      <file href="no title/Lesson 2 -- Toolbox/images/HandTool.gif" />
      <file href="no title/Lesson 2 -- Toolbox/images/colorselect.gif" />
      <file href="no title/Lesson 2 -- Toolbox/images/eyedroppertool.gif" />
      <file href="no title/Lesson 2 -- Toolbox/images/eyedroppertool.gif" />
      <file href="no title/Lesson 2 -- Toolbox/images/EndOfLesson.gif" />
      </resource>
      <resource identifier="lesson3_ref" adlcp:scormType="asset" type="webcontent" href="no title/Lesson 3 -- Palettes/Lesson3.htm">
      <file href="no title/Lesson 3 -- Palettes/Lesson3.htm" />
      <file href="no title/Lesson 3 -- Palettes/images/headertop.gif" />
      <file href="no title/Lesson 3 -- Palettes/images/headerside.gif" />
      <file href="no title/Lesson 3 -- Palettes/images/pssidebar.gif" />
      <file href="no title/Lesson 3 -- Palettes/images/LessonTitle3.gif" />
      <file href="no title/Lesson 3 -- Palettes/images/defaultpalettes.gif" />
      <file href="no title/Lesson 3 -- Palettes/images/EndOfLesson.gif" />
      </resource>
      <resource identifier="lesson4_ref" adlcp:scormType="asset" type="webcontent" href="no title/Lesson 4 -- Layers/Lesson4.htm">
      <file href="no title/Lesson 4 -- Layers/Lesson4.htm" />
      <file href="no title/Lesson 4 -- Layers/images/headertop.gif" />
      <file href="no title/Lesson 4 -- Layers/images/headerside.gif" />
      <file href="no title/Lesson 4 -- Layers/images/pssidebar.gif" />
      <file href="no title/Lesson 4 -- Layers/images/LessonTitle4.gif" />
      <file href="no title/Lesson 4 -- Layers/images/flatlayers.gif" />
      <file href="no title/Lesson 4 -- Layers/images/37.gif" />
      <file href="no title/Lesson 4 -- Layers/images/layers.gif" />
      <file href="no title/Lesson 4 -- Layers/images/layerarrows.gif" />
      <file href="no title/Lesson 4 -- Layers/images/eyeicon.gif" />
      <file href="no title/Lesson 4 -- Layers/images/paintbrush.gif" />
      <file href="no title/Lesson 4 -- Layers/images/linkicon.gif" />
      <file href="no title/Lesson 4 -- Layers/images/newlayericon.gif" />
      <file href="no title/Lesson 4 -- Layers/images/EndOfLesson.gif" />
      </resource>
      </resources>
      </manifest>
      quote:

      Text



      For example , i want to get metadata element .
      var nodes:XML = XML(myManifestSrv.lastResult.metadata);
      trace(nodes)
      quote:

      Text
        • 1. Re: Why can't got element from XML
          levancho Level 3
          how are you executing myManifestSrv ?
          and when are you calling var nodes:XML = XML(myManifestSrv.lastResult.metadata);?
          • 2. Re: Why can't got element from XML
            dwwangrui Level 1
            in initialize step of application
            and in the initialize method , i just simple call myManifestSrv.send(), then
            after execute statement var nodes:XML = XML(myManifestSrv.lastResult.metadata), nodes's value is null.
            so strange.
            • 3. Re: Why can't got element from XML
              levancho Level 3
              quote:

              Originally posted by: dwwangrui
              in initialize step of application
              and in the initialize method , i just simple call myManifestSrv.send(), then
              after execute statement var nodes:XML = XML(myManifestSrv.lastResult.metadata), nodes's value is null.
              so strange.


              the reason you are getting null is because httpService call is asynchronous that means it does not return right away,
              so what you need to do is to register listener with your service :

              myManifestSrv.addEventListener(ResultEvent.RESULT,yourResultListener);
              and in yourResultListener function:

              var nodes:XML = XML(myManifestSrv.lastResult.metadata)
              or simply var nodes:XML = XML(myManifestSrv.result) etc ...

              P.S lastResult will be null untill at least one successful call is made with that service so it can get populated.
              • 4. Re: Why can't got element from XML
                dwwangrui Level 1
                Follow your suggestion , i use AS style to load the XML.
                below is my full code , it's an AIR application .

                <?xml version="1.0" encoding="utf-8"?>
                <mx:WindowedApplication xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" initialize="init()">
                <mx:Script>
                <![CDATA[
                import mx.rpc.events.ResultEvent;
                import mx.rpc.http.HTTPService;

                public var myManifestSrv:HTTPService;

                private function init():void{
                myManifestSrv = new HTTPService();
                myManifestSrv.url = "datas/example1/imsmanifest.xml";
                myManifestSrv.resultFormat = "e4x";
                myManifestSrv.addEventListener(ResultEvent.RESULT , manifestLoaded);
                myManifestSrv.send();
                }

                private function manifestLoaded(event:Event):void{
                var nodes:XML = XML(myManifestSrv.lastResult.metadata);
                trace(nodes);
                }
                ]]>
                </mx:Script>
                </mx:WindowedApplication>

                you can try my code , trace(myManifestSrv.lastResult.metadata) is still null.

                I am not quite sure whether the resaon of fault is from XML problem .When i use a simple XML , such as :
                <?xml version="1.0" encoding="UTF-8"?>
                <galleries>
                <gallery id="flextravel">
                <description>Trip photos from various Flex team members</description>
                <photo>
                <name>Acropolis: Matt Chotin</name>
                <description>Acropolis on Calton Hill in Edinburgh</description>
                <source>flextravel/Acropolis on Calton Hill.jpg</source>
                </photo>
                <photo>
                <name>Edinburgh Castle: Matt Chotin</name>
                <description>The Edinburgh Castle as seen from fountain in the Princess Gardens</description>
                <source>flextravel/Fountain and Edinburgh Castle.jpg</source>
                </photo>
                </gallery>
                </galleries>

                It is OK.
                • 5. Re: Why can't got element from XML
                  levancho Level 3
                  instead of duing

                  private function manifestLoaded(event:Event):void{
                  var nodes:XML = XML(myManifestSrv.lastResult.metadata);
                  trace(nodes);
                  }

                  do :
                  private function manifestLoaded(event:ResultEvent):void{
                  var nodes:XML = XML(event.result);
                  trace(nodes);
                  }
                  • 6. Re: Why can't got element from XML
                    dwwangrui Level 1
                    Thanks for you replay .
                    I have tried your suggestion .
                    var nodes:XML = XML(event.result);
                    trace(nodes);
                    is Ok, But i need event.result.metadata. and it is still null.
                    • 7. Re: Why can't got element from XML
                      dwwangrui Level 1
                      Any suggestion ?
                      • 8. Re: Why can't got element from XML
                        dwwangrui Level 1
                        yeah , the file encoding is UTF-8 ,and the format of xml declaration is UTF-8 too.

                        Your can try my XML, when i change to a simply one, it works ...
                        • 9. Re: Why can't got element from XML
                          dwwangrui Level 1
                          yeah , the file encoding is UTF-8 ,and the format of xml declaration is UTF-8 too.

                          You can try my XML, when i change to a simply one, it works ...
                          • 10. Re: Why can't got element from XML
                            dwwangrui Level 1
                            yeah , the file encoding is UTF-8 ,and the format of xml declaration is UTF-8 too.

                            You can try my XML, when i change to a simply one, it works ...