2012-02-25 47 views
0

我有一个flex 4.6应用程序调用访问MS SQl服务器的Web服务。 我正在使用(或尝试使用)我创建的Web服务。该Web服务似乎正在工作的XML返回看起来不错,但我得到以下错误。XML解析器失败:元素格式不正确。 null

"XML parser failure: element is malformed. null" 

我谷歌这个错误,做了一些研究,我收集,这是由XML格式来自Web服务的原因。

我在C#编写的Web服务,我测试了,服务是重新调整以下XML结构:

<root> 
<pub> 
<PublicationId>BIA-B0112</PublicationId> 
<TargetPPODate>2012-02-28</TargetPPODate> 
<TargetPPIDate>2012-03-13</TargetPPIDate> 
<TargetRIPDate>2012-03-16</TargetRIPDate> 
</pub> 
</root> 

格式不看我错了,返回这一点,我在这里的C#代码。

// Connect to the database and run the query 
SqlConnection conn = new SqlConnection(bldr.ToString()); 
SqlCommand cmd = new SqlCommand("AWFE.dbo.Connect_PubInfo"); 
cmd.CommandType = System.Data.CommandType.StoredProcedure; 
cmd.Parameters.Clear(); 
cmd.Parameters.Add(new SqlParameter("@Pubid", BookName)); 
conn.Open(); 
cmd.Connection = conn; 

SqlDataAdapter da = new SqlDataAdapter(); 
DataSet ds = new DataSet(); 
ds.DataSetName = "root"; 
da.SelectCommand = cmd; 
da.Fill(ds, "pub"); 

// Return the data as XML 
XmlDocument xmlDoc = new XmlDocument(); 
xmlDoc.LoadXml(ds.GetXml()); 
return xmlDoc; 

,这里是我使用的动作脚本:

<?xml version="1.0" encoding="utf-8"?> 
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
         xmlns:s="library://ns.adobe.com/flex/spark" 
         xmlns:mx="library://ns.adobe.com/flex/mx" 
         xmlns:service1="services.service1.*" 
         width="529" height="322"> 

    <fx:Script> 
     <![CDATA[ 
      import com.adobe.serializers.utility.TypeUtility; 

      import mx.controls.Alert; 
      import mx.events.FlexEvent; 


      protected function dataGrid_creationCompleteHandler(event:FlexEvent):void 
      { 
       PubInfoResult.token = service1.PubInfo("FRP-Q0112"); 
      } 

     ]]> 
    </fx:Script> 

    <fx:Declarations> 
     <s:CallResponder id="PubInfoResult"/> 
     <service1:Service1 id="service1" 
          fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)" 
          showBusyCursor="true"/> 
     <!-- Place non-visual elements (e.g., services, value objects) here --> 


    </fx:Declarations> 
    <s:TextInput id="BookCode" x="9" y="22"/> 
    <s:DataGrid id="dataGrid" x="75" y="95" 
       creationComplete="dataGrid_creationCompleteHandler(event)" requestedRowCount="4"> 
     <s:columns> 
      <s:ArrayList> 
      </s:ArrayList> 
     </s:columns> 
     <s:typicalItem> 
      <fx:Object></fx:Object> 
     </s:typicalItem> 
     <s:AsyncListView list="{TypeUtility.convertToCollection(PubInfoResult.lastResult)}"/> 
    </s:DataGrid> 


</s:WindowedApplication> 

我是新Flex和web服务,所以我有一些这方面的麻烦,任何帮助将是巨大的。

+0

你的xml是正确的,'XmlDocument'()可以加载你的xml。你的bug在别的地方。尝试打印'ds.GetXml()' – 2012-02-25 20:49:03

回答

0

我没有做的是在数据服务中设置服务的返回类型是flash builder,一旦我确定错误已被修复。现在我遇到了另一个我必须研究的问题。它现在只重新调整返回XML文件的根元素,我需要元素中的数据..

感谢大家的帮助。

+0

尝试将PubInfoResult.lastResult更改为PubInfoResult.lastResult.pub。 – 2012-02-27 00:30:31