Dynamically Loading xml in tree  control

Hi I am new to flex i need to load the following xml into tree
<?xml  version="1.0" encoding="utf-8" ?>
- <catalog>
- <product>
<name>laptop3</name>
<price>"1256"</price>
<qty>"45"</qty>
</product>
- <product>
<name>"CAR"</name>
<price>"45000"</price>
<qty>"7"</qty>
</product>
- <product>
<name>"Laptop2"</name>
<price>"450011"</price>
<qty>"7022888"</qty>
</product>
- <product>
<name>"Laptop"</name>
<price>"45000"</price>
<qty>"70"</qty>
</product>
- <product>
<name>"Laptop2"</name>
<price>"45000"</price>
<qty>"7022"</qty>
</product>
- <product>
<name>"Laptop2"</name>
<price>"45000"</price>
<qty>"7022888"</qty>
</product>
</catalog>
I am unable to load the exact xml structure ...
Please help me
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
    <mx:HTTPService id="srv" url="http://localhost:8080/SampleWebApp/test.jsp"/>
    <mx:DataGrid dataProvider="{srv.lastResult.catalog.product}" width="100%" height="100%"/>
    <mx:Tree labelField="@val" width="201" height="100%" showRoot="true"
    showInAutomationHierarchy="true" id="machineTree" dataProvider="{srv.lastResult.catalog.product}"></mx:Tree> 
    <mx:Button label="Get Data" click="srv.send()"/>
</mx:Application>
I am able to load into data grid , but not in tree help me

The same as you have but with embeded XML.
<mx:XML id="tstData">
<catalog>
<product>
<name>laptop3</name>
<price>"1256"</price>
<qty>"45"</qty>
</product>
<product>
<name>"CAR"</name>
<price>"45000"</price>
<qty>"7"</qty>
</product>
<product>
<name>"Laptop2"</name>
<price>"450011"</price>
<qty>"7022888"</qty>
</product>
<product>
<name>"Laptop"</name>
<price>"45000"</price>
<qty>"70"</qty>
</product>
<product>
<name>"Laptop2"</name>
<price>"45000"</price>
<qty>"7022"</qty>
</product>
<product>
<name>"Laptop2"</name>
<price>"45000"</price>
<qty>"7022888"</qty>
</product>
</catalog>
</mx:XML>
<mx:Tree labelFunction="treeLabel" width="201" height="100%" showRoot="true"
    showInAutomationHierarchy="true" id="machineTree" dataProvider="{tstData.product}">
But it doesn't matter.
try to debug. Add this
               [Bindable]
            private var treeData:XMLListCollection;
            public function onResult(event:ResultEvent):void
            treeData = new XMLListCollection(XML(event.result).product); // debug here to see what you get and what is a type for this data
          <mx:HTTPService id="srv"  url="http://localhost:8080/SampleWebApp/test.jsp" result="onResult(event)"/>
And treeData as a dataSource for Tree.

Similar Messages

  • Complex xml in tree control

    every example you see online is trivial and utterly useless
    for practical programming purposes...typically you'll see something
    like this:
    <mx:XML format="e4x" id="myMenuModel">
    <root label="Menu">
    <menuitem label="MenuItem A">
    <menuitem label="SubMenuItem 1-A"/>
    <menuitem label="SubMenuItem 2-A" />
    </menuitem>
    <menuitem label="MenuItem B"/>
    <menuitem label="MenuItem C" type="check"/>
    <menuitem type="separator"/>
    <menuitem label="MenuItem D">
    <menuitem label="SubMenuItem 1-D" type="radio"
    groupName="one"/>
    <menuitem label="SubMenuItem 2-D" type="radio"
    groupName="one"/>
    <menuitem label="SubMenuItem 3-D" type="radio"
    groupName="one"/>
    </menuitem>
    </root>
    </mx:XML>
    ...just hard coded simplistic xml which is fine and dandy if
    you have a simple xml schema and all the leaves of your tree can be
    keyed off the same "label" attribute. But what if you have a
    complex, deeply nested XML file that doesn't follow this nice
    pattern? What if I want to pull different attributes from different
    levels in the tree to display, is that even possible? Or what if I
    dont want to use the attribute at all for my display label in the
    tree, what if I want to use an element node name? Like for example,
    say I had:
    <department label="marketing">
    <employee name="Eric Cartman" Age="8">
    <interest>
    <type>food</type>
    <name>cheesiepoofs</name>
    </interest>
    <interest>
    <type>pets</type>
    <name>mr. kitty</name>
    </interest>
    </employee>
    Is there a way I can build my tree to use the department
    'label' attribute for the top level, the employee 'name' attribute
    for the second level and the <type> element nested under
    <interest> for the third level?
    I confess I'm a Flex newbie but any other language I've
    worked provides a mechanism to tailor this sort of thing to
    individual business cases. Any insight would be greatly
    appreciated.
    thank you.
    S

    Another approach is parse your complex xml into objects and
    then create your own
    tree datadescriptor. This is described in the help. Search on
    "custom tree datadescriptor"
    We use this approach because the xml we want to display in a
    tree does not fit nicely. So we wrote a parser that converts the
    xml into "TreeObjects" (our class) and created the custom tree
    datadescriptor to handle it. When we create the tree object we can
    control the data used for the label so it displays correctly.

  • Dynamically loading xml content

    I’m creating a menu bar in which the links have to be
    dynamically created based on the values in the xml, and the number
    of links(buttons) may even exceed 100.
    The menu bar will be displayed in the horizontal manner. I
    have the following questions, can any one help me ?
    1. How to create the buttons dynamically based on the number
    of entries in the xml..?
    2. How to have a on (release) action common to all even
    though they have to perform different action.(such as loading a
    movie based on the button clicked)
    3. When the number of links becomes more how to have a
    horizontal scrolling effect for this.
    4. I even want to change the colors of some dynamic buttons
    to be changed based on some values in the xml. Can this be done?

    Hi
    Most of what you want is here -
    www.gotoandlearn.com
    Check out the 3 Carousel Tutorials, although its not a
    horizontal navbar is does everything else you want
    Hope it helps

  • Dynamically load xml into TextArea

    How can I include text from an xml file (loaded using URLLoader) into a TextArea. Flex is stripping the brackets <, >, and mangling the text output.
    thx

    Try the toXMLString() method.

  • Tree Control Image Loading

    Hi all
    Can i load Images inside
    Tree Control menu instead off juss text. I can do the same
    in Accordion but not in
    Tree Control . if its possible Please let me know how?
    Thanks
    Sany

    There is an example posted on www.cflex.net. Search for Tree
    itemrenderer.
    It draws lines between sibling nodes, but will show you how
    to do a TIR.
    Tracy

  • Transfer tree control to subprogram as XML

    I've been pretty happy with the labview tree control except that there doensn't seem to be a method for transferring a complete tree from one vi to another. I finally wrote some functions for converting a tree to/from an xml string. To convert to xml, pass the tree refnum to the subvi and out comes xml. To convert back to a new tree, pass a refnum for a new tree and the xml string. I haven't done any optimization for speed or flexibility, (no documentation yet either) but it works pretty well. The attached code has everything you need - I hope someone else will find this useful. I'd love feedback if anyone tries it.
    thanks,
    George
    Attachments:
    tree-xml.zip ‏86 KB

    Hi, George,
    thank you for your answer. I use LabView tree and work with LabView 2013, maybe the tree itself is not uptodate, but after casting it works, I suppose, that it is just the XML string which you expect to get. I made an XML -display VI using LabView tools from the corresponding library - they are going from node to node getting names and attributes. As a result a tree with 2 columns is displayed. I can send you this VI to have a look at it.
    I found and loaded TestConfiguration.xml, it can be also displayed with my VI, though it uses XSD - my original file doesn't have any XSD, that#s why it may be differen in your solution and in what I have to do.
    I took my tree, "casted" it to your ref and than used "LoadXML" from the XML palett of LabView. I got the parsing error "Line 2, Column 2,  Message: Expected an element name", maybe that means, that some header info is not correct.
    As I see from you VI you convert the tree to an XML- string, and then you can save this string in a file, right? I thought of creating an XML -structure with nodes and attributes just from the tree, but obviously it is a very complicated way, isn't it? My problem is to save changes, which a user has done editing the Tree - it seems to be the simplest way to write donw the TREE  completely in an XML file, because the tree has all the info.  But maybe this way can#t be gone at all :-(.
    Please find attached the VI to display an XML file in a tree with 2 columns. I used this display form as an XML Notepad 2007 does it.
    Thanks
    Attachments:
    DisplayXMLFileAsTreeExample.vi ‏49 KB
    DisplayXML.lvproj ‏3 KB

  • How to binding incoming xml node list to the tree control as dataProvider

    Recently, I faced into one issue: I want to binding incoming xml node (it's not avaliable at start) list to the tree control as a dataProvider.
    Since the incoming xml node list is not avaliable at beginning but I needs to bind it to the tree, so I create one virtual one in the xml, and prepare to remove it before the tree is shown. (ready for the actual node adding). But It did not work.
    Please see the presudo-code here:
    1.  Model layer(CsModel.as)
    public class CsModel
            [Bindable]
            public var treeXML:XML=<nodes><car label="virtualOne" id="1">
                                   </car></nodes>;
            (Here, I want to build binding relationship on the <car/> node,
             one 'virtual/stub' node is set here with lable="virtualOne".
             But this node will be deleted after IdTree
             control is created completely.)      
            [Bindable]
            public var treeData:XMLList =new XMLListCollection(treeXML.car);
    2. view layer(treePage.mxml)
            private var _model:CsModel = new CsModel();
            private function addNode():void
                    var newNode:XML=<car/>;
                    newNode.@label="newOne";
                    newNode.@id=1;
                    _model.treeXML.appendChild(newNode);
                             private function cleanData():void
                                     delete _model.treeXML.car;
            <mx:VBox height="100%" width="100%">
            <mx:Button label="AddNode" click="addNode()" />
            <mx:Tree id="IdTree"  labelField="@label"
              creationComplete="cleanData()"
              dataProvider="{_model}"/>
        </mx:VBox>
    3. Top view layer (App.Mxml)
    <mx:application>
        <treePage />
    </mx:application>
    For method: cleanData(),It's expected that when the treePage is shown, we first delete the virutalOne to provide one 'clear' tree since we don't want show virtualOne to the user. The virutalOne node just for building the relationship between treeData and treeXML at beginning. But the side effect of this method, I found, is that the relationship between treeXML and treeData was cut off. And this leads to that when I added new node (by click the 'addNode' button) to the xmlXML, the xmlData was not affected at all !
    So Is there any other way to solve this issue or bind the incoming xml node list to the xmlListCollection which will be used as Tree control's dataProvider ?

    If u want to display the name : value then u can do like this
    <xsl:eval>this.selectSingleNode("name").nodeName</xsl:eval> : <xsl:value-of select="name" />

  • Loading XML file with missing elements dynamically through ODI

    Hi Guys ,
    I have the below xml file with two nodes Employee and Address. On a daily basis , sometimes the address element might not come in from the source xml file , but my interface has columns mapped to address elements, and hence it can fail due to the source element not being found in the file or data might not get loaded due to the 'and' condition in the sql query generated between the employee and address elements.  Is there a way where i can load the data dynamically where i can search in the file only for the elements (Employee) present and load data only for those elements dynamically?
    XML File:
    <?xml version="1.0" encoding="UTF-8" ?>
    <EMP>
    <Empsch>
    <Employee>
    <EmployeeID>12345</EmployeeID>
    <Initials>t</Initials>
    <LastName>john</LastName>
    <FirstName>doe</FirstName>
    </Employee>
    <Address>
    <WorkPhone>12345</WorkPhone>
    <WorkAddress>Test 234</WorkAddress>
    </Address>
    </Empsch>
    </EMP>
    Thanks ,
    Revanth Tambisetty

    I was able to resolve it by using left outer joins and referring the table structure from the XSD

  • Flex tree control expanditem dynamically..?

    Hi All.,
               I have using tree control using to display. when i pass the data with folder id dynamically  to expanding particular child node of tree.
        How to extarct tree with dynamic...?
    Below sample coding.....
    <mx:tree id="folderTree" />
    folderid=2618;
         callLater(expandTree, [folderid]);
         private function expandTree(folderid: Object) : void
                    folderTree.expandChildrenOf(folderTree.getChildAt(0), true);
                    folderTree.selectedItem = folderid;
    but not extracting tree.
    anyone help this problem
    With Regards.,
    Lings

    Thanks buddy for the answer.
    Unfortunately the answer came after quite long time of posting the message. Anyway I was able to open a tree on demand using HttpService and due to my new requirement I changed it to RemoteObject.
    I my latest change I am able to populate tree nodes on demand and also the same solution if getting update from server via JMS using Consumer object.
    I kind a like this solution because it took me good amount of effort to find the right solution.
    If any one is intersted the he/she can reply to the post and I can provide code here or may at some location so that it can be easily downloaded.
    The solution is Flex-Grails combination.
    Thanks everybody.

  • How to dynamically load data from DB in an HTML control present in jsp

    Hi Friends,
    Can anyone help me with this problem:
    I am working on a portal application. My requirement is to dynamically load data in an HTML control present in my JSPs. The controls are combo-boxes, text-fields, list-boxes etc. . Also, the events to load the data are like On Form load, On selecting a value from the combo-box, on clicking on a text-field etc.
    If any one can help me with a code snippet, than that would be highly appreciable. If not then the approach to achieve this will also be helpful.
    Thanks and Regards,
    Gaive.

    Refer
    http://www.developer.com/db/article.php/3384201
    http://www.developer.com/db/article.php/10920_3399331_1

  • Dynamic loading tree and data grid

    Hi All,
    I new to java as well as JSF. I am very impressed with the jsf and Sun Java Creator IDE. I made a sample project.
    Now I want to load tree and data grid with dynamic values how can I achieve this.
    Please help to find out some examples.
    Also I need to know who I can use SOAP call using JSF.
    Thanks
    CSCS

    To dynamically load a Basic Table (ui:table) from a database, see http://developers.sun.com/prodtech/javatools/jscreator/learning/tutorials/2/databoundcomponents.html
    To dynamically load a Basic Table from other sources of data that are loaded into an array or such, see http://blogs.sun.com/roller/page/divas?entry=table_component_sample_project
    To dynamically CREATE a Basic Table, see http://developers.sun.com/prodtech/javatools/jscreator/reference/tips/2/createTableDynamically.html and http://developers.sun.com/prodtech/javatools/jscreator/reference/tips/2/add_component_to_table.html
    To dynamically create an HTML table on the fly, see section 7.5 in Chapter 7 of the Field Guide at http://developers.sun.com/prodtech/javatools/jscreator/learning/bookshelf/index.html
    To dynamically create a tree, see Dynamic Tree example at http://developers.sun.com/prodtech/javatools/jscreator/reference/index.jsp.
    A tutorial for dynamically creating a tree from a database is work in progress.
    Hope this helps,
    Chris

  • Tree control and XML dataprovider

    Hi,
    I am trying to get this xml ( http://mitjafelicijan.net/test.xml ) working with my tree control in my Flex app and cannot figure it out how exactly to do this.
    my Flex code is this
    <mx:Tree left="0" top="0" bottom="0" showRoot="true" id="trvTreeview" right="0"></mx:Tree>
    and my AS code is this
    var tmp:XML = XML(event.target.data);
    trvTreeview.dataProvider = tmp.node;
    I get such output
    http://mitjafelicijan.net/tree.png

    The default data descriptor will see any child node as a child and claim that node is a folder.  If the xml node used attributes like this:
    Then there aren't any child nodes.  However, if you can't change the XML structure you can create a custom TreeDataDescriptor that is smarter about hasChildren()
    Alex Harui
    Flex SDK Developer
    Adobe Systems Inc.
    Blog: http://blogs.adobe.com/aharui

  • Tree control and XML

    Hi,
    I have an XML file. I want to display the nodes from the XML
    using a tree control.
    The structure of the XML is
    <grandparent>
    <parent>
    <child1> 1 </child1>
    <child2> 2 </child2>
    <child3> 3 </child3>
    </parent>
    <parent>
    <child1> 4 </child1>
    <child2> 5 </child2>
    <child3> 6 </child3>
    </parent>
    <parent>
    <child1> 7 </child1>
    <child2> 8 </child2>
    <child3> 9 </child3>
    </parent>
    </grandparent>
    Can I display the tree like
    grandparent
    parent
    1
    4
    7
    skipping some children.

    Two choices:
    1. pre-process the xml into a form the tree can render
    directly.
    2. Create a custom Tree Data Descriptor
    Tracy

  • XML for a Tree Control

    I am trying to create a Tree control for my application that lists account reps as branches with their clients as leaves below them.
    I created the xml below from a CGI script, but when the tree renders it the account reps are leaves and the clients don't show up at all. There is evidently something basic I am missing. Can anyone tell me what xml to do what I am shooting for should look like?
    <Result>
    <node>
      <label>Bill Smith</label>
      <data>AM|01</data>
        <node>
          <label>125 Company</label>
          <data>COMPID|2177</data>
        </node>
        <node>
          <label>ABC Manufacturing</label>
          <data>COMPID|2167</data>
        </node>
        <node>
          <label>Test Company</label>
          <data>COMPID|2172</data>
        </node>
    </node>
    <node>
      <label>Jane Jones</label>
      <data>AM|01</data>
        <node>
          <label>126 Company</label>
          <data>COMPID|2100</data>
        </node>
        <node>
          <label>XYZ Service Company</label>
          <data>COMPID|2101</data>
        </node>
        <node>
          <label>Test Company 2</label>
          <data>COMPID|2102</data>
        </node>
    </node>
    </Result>

    At this point it is just a test application so the code is pretty small. For retrieving the data, I pretty much copied code from one of the examples. I created an HTTP request since I plan to return results from a CGI interface rather than a web service. My data provider is derived from the lastResult property of the HTTPService "userRequest".
    <?xml version="1.0"?>
    <!-- containers\layouts\HDivBoxSimple.mxml -->
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*" creationComplete="send_data()">
        <mx:Script>
            <![CDATA[
                private function send_data():void {
                    userRequest.send();
            ]]>
        </mx:Script>
        <mx:TitleWindow width="100%" height="100%" layout="absolute" title="Task Management" fontFamily="Verdana" fontSize="12" backgroundColor="#F0F0F0">
            <mx:HDividedBox x="0" y="30" width="100%" height="95%" >
                <mx:Tree width="15%" height="100%" id="treeCompList" dataProvider="{userRequest.lastResult.Result.node}" enabled="true"></mx:Tree>
                <mx:TileList width="60%" height="100%"></mx:TileList>
                <mx:DateChooser width="180"/>
            </mx:HDividedBox>
            <mx:Canvas x="0" y="-10" width="390" height="35">
                <mx:Button x="4" y="10" label="Reports"   cornerRadius="0"/>
                <mx:Button x="80" y="10" label="Due Today"   cornerRadius="0"/>
                <mx:Button x="174" y="10" label="Past Due"   cornerRadius="0"/>
                <mx:Button x="258" y="10" label="Events"   cornerRadius="0"/>
            </mx:Canvas>
        </mx:TitleWindow>
        <mx:HTTPService id="userRequest" url="http://192.168.1.20/cgiGroupFlex.exe" useProxy="false" method="POST">
            <mx:request xmlns="">
                <FUNCTION>GetAMCompList</FUNCTION>
                <FORMAT>TREE</FORMAT>
            </mx:request>
        </mx:HTTPService>
    </mx:Application>

  • Problems handling xml data for tree control.

    Hi,
    I have tried using tree control for displaying my xml data
    but I had a problem that i did not have labels in my xml data. A
    sample xml data is attached. So it displays the whole data at each
    level in the tree. The root label will be the entire the xml data
    and then one level down the remaining xml data and so on...
    How do i solve this issue i,e get the tags names itself as
    labels..
    Thanks in advance....

    An update after some efforts..
    Could get the folders perfectly i.e until the level of
    CPUTime perfectly but could not get the leaf: 32 since i used the
    following to set the label.
    I would like to know if there is a way to find out if a node
    is a leaf or folder and according set the label

Maybe you are looking for

  • ORA-06502 error after SSO login

    Hi all. In our intranet i'm trying to use the AS 10g SSO as authentication with my HTML DB application. HTML DB is into a 9.2.0.4 database in a Alpha open VMS server. AS 10g infrastructure and AS 10g mid-tier on two difference Linux RedHat AS 2.1 ser

  • Lightroom 5: start button in the presentation module doesn't work properly

    Hi. I purchased LR 5 last week but the start button in the presentation mudule doesn't work properly. I get a black screen and nothing happens. I have to press the esc button several times to return to LR.Can you help me please Regards Eugene

  • What is a good gps app for ipad2 ?

    What is a good gps app for ipad2?

  • Doubt in String

    Hi Members, Is there any method to check whether a string contains any special characters or not. Venkat

  • [solved] [Qemu+libvirt] Can't emulate e1000 NIC cards

    Hi, I want to emulate 2 e1000 NIC cards. I'm using a virsh template file. I've tried several variantes of the following : <interface type='bridge'> <source bridge='br0'/> <target dev='veth0'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x03