0

I have XML with a value like the following:

<products>
  <product id="1" name="All Products">
    <code>000</code>
    <shortname>ALL</shortname>
    <cost>0.0</cost>
    <product id="2" name="Product Group A">
      <code>001</code>
      <shortname>A</shortname>
      <cost>0.0</cost>
      <product id="4" name="Product A">
        <code>11</code>
        <shortname>ProductA</shortname>
        <cost>0.4</cost>
      </product>
    </product>
  </product>
</products>

I declare an XMLList by calling xml.children(), and bind it to a tree like so:

var products:XMLList = xml.children()

<mx:Tree id="treeProducts" dataProvider="{products}" labelField="@name" width="100%" />

However, my tree doesn't know which XML elements to create nodes for, so I get nodes for every element, ie:

-All Products
  - 000
  - ALL
  - 0.0
  - Product Group A
    - 001
    - A
    - 0

What I really want is just to show the @name value for each <product>:

  • All Products
    • Product Group A
      • Product A

Am I missing something totally obvious?

2
  • Just out of curiosity, shouldn't code, shortname etc be attributes as well? Commented Jan 23, 2009 at 23:38
  • I'm rendering with Grails, which has this type of format by default. But you're right, I could customize the format to make it readily bindable to the tree. Thanks! Commented Jan 24, 2009 at 0:41

1 Answer 1

2

If you were just collecting nodes from the tree, I would think E4X notation would be the best way to go:

xml..(@name != '')

(or some such, not checked for accuracy)

That wouldn't preserve the tree structure, though. Since you want a particular view of the tree data, I'd suggest applying an implementation of ITreeDataDescriptor which filters for named nodes in its methods:

Sign up to request clarification or add additional context in comments.

1 Comment

Yep, that worked. I created a new ITreeDataDescriptor and customized the getChildren method- not too bad. I might wind up just simplifying the XML to just return the <product> hierarchy with only the name attribute, and use it to build the tree. Then, get the other details when needed...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.