Import XML depuis un controller PHP
Bonjour
Je voudrais prendre le XML généré par ce controller PHP et le placer dans un tree.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
<?php
function build(&$xml, $parent)
{
$sql = 'SELECT idpanel AS id, belongTo AS parent, mname AS name, `group` AS `type` '
. 'FROM atactionpanel '
. 'WHERE belongTo ' . $parent ;
$rs = mysql_query($sql) ;
while ( $tuple = mysql_fetch_assoc($rs) ) {
if ( $tuple['type'] == 't' ) {
$groupe = $xml->addChild('groupe') ;
$groupe->addAttribute('id', $tuple['id']) ;
$groupe->addAttribute('name', $tuple['name']) ;
build($groupe, '= ' . $tuple['id']) ;
} elseif ( $tuple['type'] == 'f' ) {
$pannel = $xml->addChild('pannel') ;
$pannel->addAttribute('id', $tuple['id']) ;
$pannel->addAttribute('name', $tuple['name']) ;
} else {
// Elément indéterminé !!
}
}
}
mysql_connect('localhost', 'root', 'root') ;
mysql_select_db('APIM') ;
$root = new SimpleXMLElement('<list/>') ;
build($root, 'IS NULL') ;
header('Content-Type: text/xml') ;
echo $root->asXML( ) ;
?> |
Qui me génère ce XML :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
<list>
−
<groupe id="0" name="APIM">
<pannel id="1" name="Email"/>
<pannel id="2" name="Print"/>
<pannel id="3" name="File"/>
<pannel id="4" name="Http/s"/>
<pannel id="5" name="FTP"/>
</groupe>
<pannel id="6" name="Scripting"/>
<pannel id="8" name="User Def"/>
−
<groupe id="9" name="RDBMS">
<pannel id="10" name="ETL"/>
</groupe>
−
<groupe id="12" name="Middleware">
<pannel id="13" name="Corba"/>
<pannel id="14" name="JMS"/>
</groupe>
−
<groupe id="15" name="Directories">
<pannel id="16" name="LDAP"/>
</groupe>
−
<groupe id="17" name="Operating System">
<pannel id="18" name="Ms Windows"/>
−
<groupe id="19" name="Unix">
<pannel id="20" name="SUN Solaris 9"/>
<pannel id="21" name="IBM AIX 5"/>
<pannel id="22" name="Redhat Linux 9"/>
<pannel id="23" name="Mandrake Linux 9.1"/>
</groupe>
</groupe>
−
<groupe id="24" name="EDM">
<pannel id="25" name="Documentum 4"/>
</groupe>
−
<groupe id="26" name="Workgroup">
<pannel id="27" name="Lotus Domino 6"/>
<pannel id="28" name="Microsoft Outlook"/>
</groupe>
−
<groupe id="53" name="Legacy">
−
<groupe id="54" name="SAGE">
<pannel id="55" name="SAGE 50"/>
</groupe>
</groupe>
<pannel id="56" name=" EDI"/>
<pannel id="57" name=" ANSI X12"/>
<pannel id="58" name=" xCBL 4"/>
<pannel id="59" name=" Oracle Financials"/>
</list> |
Pour le moment j'ai entré le XML en dur directement dans le FLEX. Mais je voudrais que à chaque démarrage de mon application, sa appel le controller pour mettre a jour mon XML.
Voici mon code MXML :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
|
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" viewSourceURL="src/index.html">
<mx:Script>
<![CDATA[
private var dragSmallBox:Canvas;
private var dragArea:Rectangle;
private var draggableCanvas:Canvas = new Canvas();
private function rollOutHandler(event:MouseEvent):void {
// start dragging the canvas, limit the drag inside the stage
draggableCanvas.startDrag(false, dragArea);
// relatedObject is the object where the mouse went after the rollOut event
event.relatedObject.addEventListener(
MouseEvent.MOUSE_UP,
function():void {
draggableCanvas.stopDrag();
// we need to remove the rollOut event handler to avoid calling it
// when trying to roll out when mouseUp was already handled
dragSmallBox.removeEventListener(MouseEvent.ROLL_OUT, rollOutHandler);
}
);
};
private function mouseDownHandler(event:MouseEvent, da:Canvas = null):void {
if(da == null)
{
dragArea = new Rectangle(0, 0,
stage.width-draggableCanvas.width,stage.height-draggableCanvas.height)
}
else
{
dragArea = getCanvasRect(da);
dragArea.width = dragArea.width - draggableCanvas.width;
dragArea.height = dragArea.height - draggableCanvas.height;
}
dragSmallBox = new Canvas();
dragSmallBox.width = 15;
dragSmallBox.height = 15;
// comment out the following to hide the canvas
// smallBox.setStyle("backgroundColor", 0xff0000);
dragSmallBox.addEventListener(
MouseEvent.MOUSE_UP,
function():void {
draggableCanvas.stopDrag();
dragSmallBox.removeEventListener(MouseEvent.ROLL_OUT, rollOutHandler);
}
);
draggableCanvas = Canvas(event.currentTarget);
draggableCanvas.addChild(dragSmallBox);
// move the smallBox to location where the current mouse pointer is its center
dragSmallBox.move(
event.currentTarget.mouseX - (dragSmallBox.width / 2),
event.currentTarget.mouseY - (dragSmallBox.height / 2)
);
dragSmallBox.addEventListener(MouseEvent.ROLL_OUT, rollOutHandler);
}
private function getCanvasRect(c:Canvas):Rectangle{
return new Rectangle(0, 0, c.width, c.height);
}
]]>
</mx:Script>
<mx:Script>
<![CDATA[
import mx.collections.XMLListCollection;
[Bindable]
private var company:XML =
<list>
<groupe name="APIM" id="0">
<pannel name="Email" id="1"/>
<pannel name="Print" id="2"/>
<pannel name="File" id="3"/>
<pannel name="Http/s" id="4"/>
<pannel name="FTP" id="5"/>
</groupe>
<pannel name="Scripting" id="6"/>
<pannel name="User Def" id="7"/>
</list>;
[Bindable]
private var companyData:XMLListCollection = new XMLListCollection(company.groupe);
private function treeLabel(item:Object):String
{
var node:XML = XML(item);
if( node.localName() == "groupe" )
return node.@name;
else
return node.@name;
}
]]>
</mx:Script>
<mx:Canvas mouseDown="mouseDownHandler(event)" x="10" y="10" height="450" width="200" backgroundColor="red">
<mx:Tree id="tree" dataProvider="{companyData}"
labelFunction="treeLabel"
height="450" width="200"
/>
</mx:Canvas>
</mx:Application> |