2 Replies Latest reply on Feb 21, 2011 4:53 PM by Benoitcn

    xml e4x grammer error

    Benoitcn Level 1
      When I run the app I get this error, " TypeError: Error #1010: A term is undefined and has no properties. "
      But if I bebug the line which error occured, there is no error any more!!
      I think the speed of xml creating element is slower than the application executed speed .
      This is my code :
      When I run the app I get this error, " TypeError: Error #1010: A term is undefined and has no properties. "
      But if I bebug the line which error occured, there is no error any more!!
      I think the speed of xml creating element is slower than the application executed speed .
      This is my code :
      public function exportToXML():XML{
         var diaXML:XML = new XML("<nodes></nodes>");   
         var index:int = 0;
         while(  index < allNodes.length ){
          var element:BaseNode = allNodes[index] as BaseNode;
          diaXML[index].node.@["class"] = getQualifiedClassName(element); // the error line !!!
          diaXML[index].node.@nodeName = (element).nodeName;
          diaXML[index].node.@editable = (element).editable;
          diaXML[index].node.@textMargin = (element).textMargin;
         
          var leavingLinks:IList = element.getAllLeavingLinks();
          var lnkIndex:int = 0;
          while( lnkIndex < leavingLinks.length ){
           diaXML[index].node.links.link[lnkIndex] = getQualifiedClassName(leavingLinks[lnkIndex].toNode);
           ++lnkIndex;
          }
         
          ++index;
         }
         trace(diaXML.toXMLString());
         return diaXML;
        }
        • 1. Re: xml e4x grammer error
          injpix Level 3

          Last week I had an issue of parsing an XML file using E4X in a while-loop.  I fixed the issue, by converting the while-loop to a for-each-loop and I also created local varibles for the nodes.  But I am not sure how you can edit a node by reference other then the way you are currently doing it.  That is, if you create a local variable, it "copies" the XML value to it.  If you edit it, the orginial XML will not reflect this change.

           

          Try changing the loop to a for-each.  I believe the while-loop executes the fastest of all loops.  So perhaps your statement about the speed of execution is correct.

          1 person found this helpful
          • 2. Re: xml e4x grammer error
            Benoitcn Level 1

            Thanks injpix ! Your reply is helpful to me. I found the reason this is my mistake in understanding the e4x grammer.

            I change my code in the while-loops section. Actually I just want the two loops to create a xml

            even though the xml doesn't has "node" and "link" section.

             

            public function exportToXML():XML{
               var diaXML:XML = new XML("<nodes></nodes>");
              
               var index:int = 0;
               while(  index < allNodes.length ){
                var element:BaseNode = allNodes[index] as BaseNode;
                diaXML.appendChild(<node></node>);
                diaXML.node[index].@["class"] = getQualifiedClassName(element);
                diaXML.node[index].@nodeName = (element).nodeName;
                diaXML.node[index].@editable = (element).editable;
                diaXML.node[index].@textMargin = (element).textMargin;
               
                var leavingLinks:IList = element.getAllLeavingLinks();
                var lnkIndex:int = 0;
                while( lnkIndex < leavingLinks.length ){
                 diaXML.node[index].links.link[lnkIndex] = getQualifiedClassName(leavingLinks[lnkIndex].toNode);
                 ++lnkIndex;
                }
               
                ++index;
               }

               return diaXML;
              }