开发者

doesn't parse xml when it's a single node

my script.php returns this XML

<all>
  <item>
     <field1>value1</field1>
     <field2>value2</field2>
  </item>

  <item>
     <field1>value1</field1>
     <field2>value2</field2>
  </item>
</all>

The HTTPService uses the default resultFormat="object" but I don't declare it since it's the default.

Then I bind it to a List

dataProvid开发者_运维问答er="{getDataHTTP.lastResult.all.item}"

I get no problems when the number of item returned is more than 1. But when it's only 1 item I get an error cannot convert XMLList to mx.collections.IList.

I tried different solutions including trying to cast it as XMLListCollection but it still gives an error for single items. Does anyone know of a way to possibly solve this?


Make resultFormat="xml" and set dataProvider="{getDataHTTP.lastResult.item}"


import mx.rpc.xml.SimpleXMLDecoder;
import mx.rpc.xml.SimpleXMLEncoder;

[Bindable]public var xmlDataObj:Object = new Object(); 

private function yourResultEvent(evt:ResultEvent):void{
var resultXml:XMLDocument = new XMLDocument(evt.result as String);
var decoder:SimpleXMLDecoder = new SimpleXMLDecoder(true);
xmlDataObj= decoder.decodeXML(resultXml).all.item;
}

This way you don't need to worry about changing your resultFormat to XML or e4x.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜