XML分析器失败:元素格式不正确.无效的



我有一个flex 4.6应用程序,它调用访问MS SQl服务器的web服务。我正在使用(或试图使用)我创建的web服务。web服务似乎正在工作,返回的XML看起来还可以,但我收到了以下错误。

"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服务的新手,所以我在这方面遇到了一些麻烦,任何帮助都会很棒。

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

感谢大家的帮助。

相关内容

最新更新