簡體   English   中英

XML解析器失敗:元素格式錯誤。 空值

[英]XML parser failure: element is malformed. null

我有一個Flex 4.6應用程序,該應用程序調用訪問MS SQl服務器的Web服務。 我正在使用(或嘗試使用)我創建的Web服務。 Web服務似乎正在工作,返回的XML看起來還可以,但是出現以下錯誤。

"XML parser failure: element is malformed. null"

我對這個錯誤進行了Google搜索,並做了一些研究和收集,這是由於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 Builder,一旦我確定該錯誤已解決。 現在我遇到了另一個必須研究的問題。 現在只調整返回XML文件的根元素,我需要元素中的數據。

感謝大家的幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM