开发者

FLEX: can't retrieve XML from event.result

I'm trying to feed data from SQL database to FLEX, using php script in the middle. I see the data in body of message in the Network Monitor and in "Variable" window during debug, but I can't retrieve them to XML.

Below (event.message.toString())

(mx.messaging.messages::AcknowledgeMessage)#0
  body = "<?xml version="1.0" encoding="UTF-8"?>
<articles>
<no开发者_如何学编程de><id>2</id>
<articleid>2</articleid>
<nrporzadkowy>2</nrporzadkowy>
<tresc>moja tresc</tresc>
<rodzaj>textFlow</rodzaj>
</node>
</articles>"
  clientId = "DirectHTTPChannel0"
  correlationId = "C8993E66-DF60-FE63-73D3-6700CA497221"
  destination = ""
  headers = (Object)#1
    DSStatusCode = 200
  messageId = "475F2475-A915-29AB-4364-6700D08BD7D2"
  timestamp = 0
  timeToLive = 0

I'm trying

protected function pobieranieElementow_resultHandler(event:ResultEvent):void
{
    var myXML2:XML = new XML();
    myXML2 =XML(event.result);
}

but then in myXML2 I'm getting only "[object Object]" , when I'm changing casting method to:

protected function pobieranieElementow_resultHandler(event:ResultEvent):void
    {
        var myXML2:XML = new XML();
        myXML2 =event.result as XML;
    }

I'm receiving null in myXML2. I have no idea whats going on ? I'll post also php script just in case something is wrong there (maybe wrong '\n' signs)

<?php
  header('Content-type: text/xml; charset=utf-8');
  echo '<?xml version="1.0" encoding="utf-8"?>';
  echo "\r\n";
  $link = mysql_connect("HOST", "XXXXX", "XXXXDS");
  mysql_select_db("DATABASEXXXX");
  if (!$link) {
  printf("Connect failed: %s\n", mysql_connect_error());
  exit();
}
  $sql = sprintf("SELECT id,articleid,nrporzadkowy,tresc,rodzaj from elements where articleid = '%s'",$_POST["id"]);
  $result = mysql_query($sql);
  $beg = '<articles>';
  $end = '</articles>';
  echo "$beg\r\n";
  while($row = mysql_fetch_assoc($result))
  {
   echo '<node>';
   echo '<id>';
   echo $row["id"];
   echo '</id>';
   echo "\r\n";
   echo '<articleid>';
   echo $row["articleid"];
   echo '</articleid>';
   echo "\r\n";
   echo '<nrporzadkowy>';
   echo $row["nrporzadkowy"];
   echo '</nrporzadkowy>';
   echo "\r\n";
   echo '<tresc>';
   echo $row["tresc"];
   echo '</tresc>';
   echo "\r\n";
   echo '<rodzaj>';
   echo $row["rodzaj"];
   echo '</rodzaj>';
   echo "\r\n";  
   echo '</node>';
   echo "\r\n";
  }
  echo $end;
  mysql_free_result($result);
  mysql_close($link);
?>

PS Well I'm able to change nodes to arrayCollection via:

var array:ArrayCollection = event.result.articles.node;

but I can't feed the dataGrid this way.


OK, ERROR was stupid. I didnt specify the resultFormat in httpService i left it default, and to read xml i should set it to "e4x"

<mx:HTTPService id="pobieranieElementow" 
                        url="URL" 
                        useProxy="false" 
                        method="POST"
                        result="pobieranieElementow_resultHandler(event)"
                        fault="pobieranie_faultHandler(event)"
                        {this was not set->}**resultFormat="e4x"**>

And now XML(event.result) is working properly.


<mx:HTTPService id="getDataUser" 
                url="http://localhost/test/db.php" 
                resultFormat="e4x" useProxy="false"
                result="onResultData(event)" 
                fault="onFaultData(event)">     
</mx:HTTPService>

get fault:

(mx.messaging.messages::AcknowledgeMessage)#0  
  body = "<user>abc</user>"
  clientId = "DirectHTTPChannel0"
  correlationId = "147F8A12-7055-5FD4-0584-0B8A07850826"  
  destination = ""
  headers = (Object)#1
    DSStatusCode = 200  
  messageId = "82772E32-1D8A-4A73-C5C8-0B8A07C30EE0"
  timestamp = 0
  timeToLive = 0


I would try (and catch) passing event.result into the constructor rather than casting with "as". That way, you're creating a new XML object out of a string instead of creating a blank document, then casting it to XML. Hope that works.


I don't think you need the

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

line.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜