Jump to content
Larry Ullman's Book Forums

Xmllist Dataprovider To Tree: Nodes Duplicated


Recommended Posts

Firstly, apologies because I've e-mailed this question to Larry as well...

Based on pp. 248-249 of Effortless Flex 4: trying to get XML data to display correctly in Tree component, but nodes are duplicated: parent duplicates itself as a child which in turn duplicates itself again as another child.

When I run my xmlData.php script in browser, the hierarchical layout is correct:

<?xml version="1.0" encoding="utf-8" ?>

- <kettles>

- <kettle>

<child>Auto kettle</child>

<child>Salton SSSAK22</child>

</kettle>

- <kettle>

<child>Eon Kettle</child>

<child>Kenwood SJ900</child>

</kettle>

- ...etc.etc...

</kettles>

I'm using HTTPService, XMLList and bind XMLList to my tree component:

<s:HTTPService id="XMLService" url="http://localhost/EE/services/xmlData.php" method="GET" resultFormat="e4x" result="getXMLDataResult(event)"/>

[bindable]

private var XMLDataList:XMLList;

private function getXMLDataResult(event:ResultEvent):void{

XMLDataList=event.result.kettle;

}

<mx:Tree id="applTree" creationComplete="XMLService.send()"

dragEnabled="true" labelField="child" dataProvider="{XMLDataList}" dragStart="tree_dragStartHandler(event)"/>

 

I URGENTLY need to get rid of the duplication. Please help!! Thanks.

Link to comment
Share on other sites

That's okay. It's when people post in the forum and then email that's annoying. As for your issue, kudos for validating the XML output. I believe the solution is to change this:

XMLDataList=event.result.kettle;

to

XMLDataList=event.result.kettles.kettle;

And/or set the showRoot property on the Tree to false. I don't have the time at this moment to test these myself, but I'm fairly sure it's one of those changes that will do the trick.

Link to comment
Share on other sites

Hi, thanks very much for your reply. Unfortunately no joy :(

When I use: XMLDataList=event.result.kettles.kettle; nothing displays - just a blank.

I also set the showRoot property on the Tree to false but still no difference.

Will appreciate any further suggestions.

Regards

Link to comment
Share on other sites

  • 2 months later...

Okay, the easy solution is to change the XML, if that's an option. If not, I think you're either going to have create a custom data renderer or convert the raw XML to a more usable format.

 

I think my problem is with the php script that generates the XML data for my tree component. I think I need a package (from PEAR) called Query2XML to generate XML from a sql query.

However, when I try and install the package on my wampserver 2.0 via the commandline:

c:\wamp\bin\php\php5.3.0>pear install XML_Query2XML-1.7.1,

 

I get the following error 'failed to mkdir C:\php5\pear\docs\XML_Query2XML\cases\case01

 

And as a test: if I try and run in my browser the following php script:

 

<?php

require_once 'XML/Query2XML.php';

require_once ('PEAR/Exception.php');

require_once 'DB.php';

$db = DB::connect('mysql://root@localhost/Query2XML_Tests');

$query2xml = XML_Query2XML::factory($db);

?>

:(

I get this error:

Warning: require_once(XML/Query2XML.php) [function.require-once]: failed to open stream: No such file or directory in C:\wamp\www\try.php on line 2

 

Fatal error: require_once() [function.require]: Failed opening required 'XML/Query2XML.php' (include_path='.;C:\php5\pear') in C:\wamp\www\try.php on line 2

 

 

I really need to get the xml data via sql and php into a tree component and I reckon I need to use the sql to xml query. What am I doing wrong???

 

Can you please help? Thanks a lot. :(

Link to comment
Share on other sites

Well, your PEAR installation failed, so any use of that PEAR class will also fail. This is likely a permissions issue and perhaps caused by the fact that you're trying to install PEAR into C:\php5 when PHP and everything is within C:\wamp.

Link to comment
Share on other sites

 Share

×
×
  • Create New...