15 Replies Latest reply on Aug 4, 2009 11:41 AM by Flex harUI

    E4X parsing  corrupt the xml .. any help is appreciated

    rushbond Level 1

       

      <contactlist>

       

       

      <contact>

       

      <contactid>1111</contactid>

      <imageurl>url</imageurl>

      <starred>Y</starred>

      <contactType>VZW</contactType>

      <mobileSync>Y</mobileSync>

      <item type="heading"> firstname or last name </item>

      <item type="subHeading"> company ,title</item>

      <item index="1" type="mobilePhone">mobilephone</item>

      <item index="2" type="workPhone">mobilephone</item>

      <item index="3" type="homePhone">mobilephone</item>

      <item index="4" type="otherPhone">mobilephone</item>

      <item index="5" type="lineSeparator" />

      <item index="6" type="personalEmail">emailaddress</item>

      <item index="7" type="businessEmail">emailaddress</item>

      <item index="8" type="im">john123(Yahoo)</item>

      <item index="9" type="webUrl">weburl</item>

      <item index="10" type="address">address</item>

      <item index="11" type="lineSeparator" />

      <item index="12" type="webGroup">wireless handset</item>

      <item index="13" type="mobileGroup">Family</item>

      <item index="14" type="lastLineSeparator" />

      <endPoints>Google,Yahoo</endPoints>

      <lastUpdated>Updated May11,1:43PM</lastUpdated>

      <connectStatus>1</connectStatus>

      <webGroup>1,3,4</webGroup>

      <mobileGroup>2,5</mobileGroup>

      <extraParam name="sessionid" >23424</extraParam>

      <extraParam name="sessionid" >23424</extraParam>

           </contact>

           <contact>

      <contactid>2222</contactid>

      <imageurl>url</imageurl>

       

      <starred>Y</starred>

      <contactType>VZW</contactType>

      <mobileSync>Y</mobileSync>

       

      <item type="heading"> firstname or last name </item>

      <item type="subHeading"> company ,title</item>

       

      <item index="1" type="mobilePhone">mobilephone</item>

      <item index="2" type="workPhone">mobilephone</item>

      <item index="3" type="homePhone">mobilephone</item>

      <item index="4" type="otherPhone">mobilephone</item>

       

      <item index="5" type="lineSeparator" />

       

      <item index="6" type="personalEmail">emailaddress</item>

      <item index="7" type="businessEmail">emailaddress</item>

      <item index="8" type="im">john123(Yahoo)</item>

      <item index="9" type="webUrl">weburl</item>

      <item index="10" type="address">address</item>

       

      <item index="11" type="lineSeparator" />

       

      <item index="12" type="webGroup">wireless handset</item>

      <item index="13" type="mobileGroup">Family</item>

       

      <item index="14" type="lastLineSeparator" />

       

      <endPoints>Google,Yahoo</endPoints>

      <lastUpdated>Updated May11,1:43PM</lastUpdated>

       

      <connectStatus>1</connectStatus>

      <webGroup>1,3,4</webGroup>

      <mobileGroup>2,5</mobileGroup>

       

      <extraParam name="sessionid" >23424</extraParam>

      <extraParam name="sessionid" >23424</extraParam>

      </contact>

      </contacts>

        • 1. Re: E4X parsing  corrupt the xml .. any help is appreciated
          rushbond Level 1

          Return garbage result when use below statement

           

           

          var xml:XML = new XML();

          // load the attached file

          //and try to execute the below statement give garbage result ..

           

               data.item.(@item=

          'heading');

           

          Any help is appreciated !

          • 2. Re: E4X parsing  corrupt the xml .. any help is appreciated
            Gregory Lafrance Level 6

            The XML sample you posted is not complete, but I'll assume that was a copy/paste error.

             

            You e4x synax is wrong. I thin it should be this:

             

            data.item.item.(@type='heading');

             

            If this does not solve the issue, can you post a small yet complete sample of how you are using the data in a control with e4x?

             

            If this post answers your question or helps, please mark it as such.

            • 3. Re: E4X parsing  corrupt the xml .. any help is appreciated
              rushbond Level 1

              Complete example

               

               

               

               

               

               

               

               

              <?xml version="1.0" ?>

              <mx:Application

               

              xmlns:mx="http://www.adobe.com/2006/mxml" width="400"

              >

               

               

               

              <mx:Script>

              <![CDATA[

               

               

              var

              myXML:XML =

              <contactlist>

              <contact>

              <contactid>1111</contactid>

              <imageurl>url</imageurl>

              <starred>Y</starred>

              <contactType>VZW</contactType>

              <mobileSync>Y</mobileSync>

              <item type="heading"> firstname or last name </item>

              <item type="subHeading"> company ,title</item>

              <item index="1" type="mobilePhone">mobilephone</item>

              <item index="2" type="workPhone">mobilephone</item>

              <item index="3" type="homePhone">mobilephone</item>

              <item index="4" type="otherPhone">mobilephone</item>

              <item index="5" type="lineSeparator" />

              <item index="6" type="personalEmail">emailaddress</item>

              <item index="7" type="businessEmail">emailaddress</item>

              <item index="8" type="im">john123(Yahoo)</item>

              <item index="9" type="webUrl">weburl</item>

              <item index="10" type="address">address</item>

              <item index="11" type="lineSeparator" />

              <item index="12" type="webGroup">wireless handset</item>

              <item index="13" type="mobileGroup">Family</item>

              <item index="14" type="lastLineSeparator" />

              <endPoints>Google,Yahoo</endPoints>

              <lastUpdated>Updated May11,1:43PM</lastUpdated>

              <connectStatus>1</connectStatus>

              <webGroup>1,3,4</webGroup>

              <mobileGroup>2,5</mobileGroup>

              <extraParam name="sessionid" >23424</extraParam>

              <extraParam name="sessionid" >23424</extraParam>

              </contact>

              <contact>

              <contactid>2222</contactid>

              <imageurl>url</imageurl>

              <starred>Y</starred>

              <contactType>VZW</contactType>

              <mobileSync>Y</mobileSync>

              <item type="heading"> firstname or last name </item>

              <item type="subHeading"> company ,title</item>

              <item index="1" type="mobilePhone">mobilephone</item>

              <item index="2" type="workPhone">mobilephone</item>

              <item index="3" type="homePhone">mobilephone</item>

              <item index="4" type="otherPhone">mobilephone</item>

              <item index="5" type="lineSeparator" />

              <item index="6" type="personalEmail">emailaddress</item>

              <item index="7" type="businessEmail">emailaddress</item>

              <item index="8" type="im">john123(Yahoo)</item>

              <item index="9" type="webUrl">weburl</item>

              <item index="10" type="address">address</item>

              <item index="11" type="lineSeparator" />

              <item index="12" type="webGroup">wireless handset</item>

              <item index="13" type="mobileGroup">Family</item>

              <item index="14" type="lastLineSeparator" />

              <endPoints>Google,Yahoo</endPoints>

              <lastUpdated>Updated May11,1:43PM</lastUpdated>

              <connectStatus>1</connectStatus>

              <webGroup>1,3,4</webGroup>

              <mobileGroup>2,5</mobileGroup>

              <extraParam name="sessionid" >23424</extraParam>

              <extraParam name="sessionid" >23424</extraParam>

              </contact>

              </contactlist>

               

               

               

              public function

              execute(){

              result.text=myXML.contact[0].item.(@type=

               

              'heading'

              );

              }

               

              ]]>

               

               

              </mx:Script>

               

               

              <mx:Button label="Button" id='btn' click="execute()"

              />

               

               

              <mx:Text text="Text" height="247" width="354" id='result'

              />

              </mx:Application>

               

              Try to run this and see the result

              • 4. Re: E4X parsing  corrupt the xml .. any help is appreciated
                rushbond Level 1

                Are you able to see the corrupt result ?

                • 5. Re: E4X parsing  corrupt the xml .. any help is appreciated
                  Gregory Lafrance Level 6

                  The result seems fine, since it returned results that have type="heading":

                   

                  What were you hoping to see?

                   

                  If this post answers your question or helps, please mark it as such.

                   

                  <item type="heading">firstname or last name</item>
                  <item type="heading">company ,title</item>
                  <item index="1" type="heading">mobilephone</item>
                  <item index="2" type="heading">mobilephone</item>
                  <item index="3" type="heading">mobilephone</item>
                  <item index="4" type="heading">mobilephone</item>
                  <item index="5" type="heading"/>
                  <item index="6" type="heading">emailaddress</item>
                  <item index="7" type="heading">emailaddress</item>
                  <item index="8" type="heading">john123(Yahoo)</item>
                  <item index="9" type="heading">weburl</item>
                  <item index="10" type="heading">address</item>
                  <item index="11" type="heading"/>
                  <item index="12" type="heading">wireless handset</item>
                  <item index="13" type="heading">Family</item>
                  <item index="14" type="heading"/>

                  • 6. Re: E4X parsing  corrupt the xml .. any help is appreciated
                    rushbond Level 1

                    my expected result is  "firstname or last name"

                     

                    current result

                    <item type="heading">firstname or last name</item>
                    <item type="heading">company ,title</item>
                    <item index="1" type="heading">mobilephone</item>
                    <item index="2" type="heading">mobilephone</item>
                    <item index="3" type="heading">mobilephone</item>
                    <item index="4" type="heading">mobilephone</item>
                    <item index="5" type="heading"/>
                    <item index="6" type="heading">emailaddress</item>
                    <item index="7" type="heading">emailaddress</item>
                    <item index="8" type="heading">john123(Yahoo)</item>
                    <item index="9" type="heading">weburl</item>
                    <item index="10" type="heading">address</item>
                    <item index="11" type="heading"/>
                    <item index="12" type="heading">wireless handset</item>
                    <item index="13" type="heading">Family</item>
                    <item index="14" type="heading"/>

                     

                    Whre are this tag coming from ... as there is no tag like

                     

                    <item index="1" type="heading">mobilephone</item> in input xml

                    • 7. Re: E4X parsing  corrupt the xml .. any help is appreciated
                      Gregory Lafrance Level 6

                      In that case the problem is in your XML data. It is not strcutured for the type of filtering you desire. There is no way to identify that node/attributes.

                       

                      You will need to add an atrribute to that XML tag or otherwise restructure your data.

                       

                      If this post answers your question or helps, please mark it as such.

                      • 8. Re: E4X parsing  corrupt the xml .. any help is appreciated
                        rushbond Level 1

                        What is the problem with XML ..

                        It is well formed XML ...

                        How can you justify that output coming is correct !

                        • 9. Re: E4X parsing  corrupt the xml .. any help is appreciated
                          rushbond Level 1

                          Can some one give me E4X syntax how to fetch "firstname or last name" from the above XML

                          • 10. Re: E4X parsing  corrupt the xml .. any help is appreciated
                            Gregory Lafrance Level 6

                            The XML is well formed, but does not adhere to rules necessary for E4X filtering to work.

                            • 11. Re: E4X parsing  corrupt the xml .. any help is appreciated
                              Flex harUI Adobe Employee

                              @Greg:  I'm not sure what you mean by that, but I doubt that statement is true.

                               

                              @Rushbond:  result.text=myXML.contact[0].item.(@type=='heading'); // 2 equals signs

                               

                              Alex Harui

                              Flex SDK Developer

                              Adobe Systems Inc.

                              Blog: http://blogs.adobe.com/aharui

                              • 12. Re: E4X parsing  corrupt the xml .. any help is appreciated
                                Gregory Lafrance Level 6

                                But there are multiple node with type="heading", so e4x will return them all correct? How will == as opposed to = help the e4x syntax know which of the multiple nodes with type="heading" is the one the user is trying to find? It doesn't seem possible unless the desired node has something like an attribute myAttribute="firstlast".

                                • 13. Re: E4X parsing  corrupt the xml .. any help is appreciated
                                  rushbond Level 1

                                  Thanks for the answer

                                  Actually i was using '=' instead of '=='

                                  so e4x was assigning instead of querying ....

                                   

                                  Thanks

                                  Rushit Patel

                                  • 14. Re: E4X parsing  corrupt the xml .. any help is appreciated
                                    Flex harUI Adobe Employee

                                    There are multiple nodes with type heading but only one per contact node.  If there was more than one per contact node, he'd get them all, but he was getting all item nodes, even ones without type heading and those nodes were getting their type changed to heading because the test wasn't a test, it was an assignment by accident.

                                     

                                     

                                    Alex Harui

                                    Flex SDK Developer

                                    Adobe Systems Inc.

                                    Blog: http://blogs.adobe.com/aharui

                                    • 15. Re: E4X parsing  corrupt the xml .. any help is appreciated
                                      Gregory Lafrance Level 6

                                      Aha. Thanks for the clarification.