代码改变世界

初学Flex,在使用Webservice时遇到Xml数据绑定的一个问题,试了N个方案,均没解决。

2007-12-07 10:51  Brush  阅读(1407)  评论(2编辑  收藏  举报

  如题,近期在研究Flex,遇到一个问题。
  问题是:
  用Flex中的datagride绑定Xml数据。
  Xml数据格式为:
 

<?xml version="1.0" encoding="utf-8" ?>
<XMLa>
        
<item>
            
<name>Mobile Phone</name>
            
<price>$199</price>
        
</item>
        
<item>
            
<name>Car Charger</name>
            
<price>$34</price>
        
</item>
        
<item>
            
<name>Car Charger1</name>
            
<price>$341</price>
        
</item>
        
<item>
            
<name>Car Charger2</name>
            
<price>$342</price>
        
</item>
        
<item>
            
<name>Car Charger3</name>
            
<price>$343</price>
        
</item>
</XMLa>


  第一次,我使用httpservice,可以绑定。
  代码如下:

<mx:HTTPService id="https" showBusyCursor="true"
     url
="http://10.10.10.9:8080/WebService/demo.xml" />
     
<mx:DataGrid id="productGrid" width="400"
         dataProvider
="{https.lastResult.XMLa.item}"  x="0" y="0">
        
<mx:columns>
            
<mx:DataGridColumn headerText="Name" dataField="name" />
            
<mx:DataGridColumn headerText="Price" dataField="price" />
        
</mx:columns>
    
</mx:DataGrid>
    
<mx:Button click="https.send()" label="Send"  x="408" y="-1"/>

然后,我使用Webservice,其代码为:
    [WebMethod]
    
public XmlDataDocument GetXml() 
    
{
        XmlDataDocument xdd 
= new XmlDataDocument();
        xdd.Load(Server.MapPath(
"demo.xml"));
        
return xdd;
    }
以上webservice已经发布,能使用。
Flex代码为:
<mx:WebService id="Service" wsdl="http://10.10.10.9:8080/WebService/Service.asmx?wsdl"
    showBusyCursor
="true" fault="fault(event.fault.faultString)" >
    
<mx:operation name="GetXml" resultFormat="xml">
    
</mx:operation>
</mx:WebService>

<mx:Label id="lblInf" text="Error Inf"  visible="false"  x="407" y="29" height="104" width="60"/>
    
<mx:DataGrid id="productGrid" width="400"
         dataProvider
="{Service.GetXml.lastResult.XMLa.item}"  x="0" y="0">
        
<mx:columns>
            
<mx:DataGridColumn headerText="Name" dataField="name" />
            
<mx:DataGridColumn headerText="Price" dataField="price" />
        
</mx:columns>
    
</mx:DataGrid>
    
<mx:TextArea text="{Service.GetXml.lastResult}"  x="0" y="150" width="467" height="183" wordWrap="false"/>
    
<mx:Button click="Service.GetXml.send()" label="Send"  x="408" y="-1"/>

结果,就不能绑定了。
关键是在那句"Dataprovider='...'",我试了不同的方法,包括把GetXml的方法中的resultFormat去掉,均不能绑定。


在这里请教各位高手,帮我找下原因。