4 Replies Latest reply on Sep 22, 2006 12:03 PM by leotemp

    Retrieving and using nested xml

    leotemp Level 1
      If my xml is in the form of multiple nested "nodes?" then how can i go about serilizing them and retrieving them properly?

      Example, if my xml looked like this:
      <data>
      <value>value1</value>
      <value>value2</value>
      <value>value3</value>
      </data>

      then displaying the value would be easy to do in my Datagrid, i would just say use "myHTTPservice.lastResult.data.value" and it would display in the grid but if my data is more complex like this:
      <data>
      <heading>
      <name>name1</name>
      </heading>
      <heading>
      <name>name2</name>
      </heading>
      <heading>
      <name>name\3</name>
      </heading>
      </data>

      How would I in theory go about serializing the say "name" into an array my datagrid could use? if i say the dataprovider is "myHTTPservice.lastResult.heading.name then i dont get an array, how do say i want all the names found in the heading to be put in an array? do have to do this manually on result from my HTTPservice and if so any pointers would be good! thank you!
        • 1. Re: Retrieving and using nested xml
          peterent Level 2
          I believe you can do: lastResult..name to make an XMLList of the <name> nodes (note 2 dots).

          But if your dataProvider is an XMLList of <heading> items, then your DataGridColumn dataField="name" should work since to retrieve the name value from any item is: item.name.
          • 2. Re: Retrieving and using nested xml
            leotemp Level 1
            Ok that worked just like you said it would but would you mind explaining to me why it works? Im a little confused but that is easy to do. So when i tell it to retreive the result and its properly formed xml it just takes any repeating tab and builds them into an array of the same name automaticaly everytime?
            • 3. Re: Retrieving and using nested xml
              peterent Level 2
              I think you understand it pretty well. Just through the info on E4X and it will probably make a lot of sense to you now.

              Just keep in mind you aren't getting an "Array" or "ArrayCollection" but an XMLList which acts like an array where you can get its length, address the items using the [ ] operator, etc.

              When using an XMLList as a dataProvider, it would be better to convert it to an XMLListCollection so you can take advantage of data binding should you need to change the XML on the fly, such as editing nodes, adding nodes, or removing nodes. And you can use the Collection cursor views, filtering, and sorting.
              • 4. Re: Retrieving and using nested xml
                leotemp Level 1
                thank you.