2011-07-18 10 views
0
私は、次のXML文字列を受信して​​い

問題は、デシリアライズXML文字列

<?xml version="1.0" encoding="UTF-8"?> 
- <changeNotificationDto xmlns="http://www.Company.com/item" changeEventTypeCode="RemoveDeliveryPoint" messageId="10" sentDateTime="1970-01-01T00:00:00.000Z"> 
- <entry action="Remove" type="DeliveryPoint"> 
- <removeEntityNotification> 
    <type>DeliveryPoint</type> 
    <compassKey>1139</compassKey> 
    </removeEntityNotification> 
- <changeDelta> 
    <changeDeltaType>ObjectRemove</changeDeltaType> 
    <recordId>1139</recordId> 
    <recordType>DeliveryPoint</recordType> 
    <subRecordId>2324</subRecordId> 
    <subRecordType>ExternalReference</subRecordType> 
    </changeDelta> 
- <changeDelta> 
    <changeDeltaType>ObjectRemove</changeDeltaType> 
    <recordId>1139</recordId> 
    <recordType>DeliveryPoint</recordType> 
    </changeDelta> 
    </entry> 
    </changeNotificationDto> 

私は「changeNotificationDto」へのWeb参照を持っている(私は、実際の名前空間名を削除した)、これは(プロキシクラスを生成しました私のアプリケーション内でこのタイプのオブジェクトを作成/使用することは問題ありません)[実際のタイプの内容は変わりますが、私は受け取るすべてのオブジェクトのWeb参照からプロキシクラスを持っています。 私はstreamReaderを使ってファイルからxmlを抽出していますが、ファイルはソケット経由で元のメッセージから書き込まれました]

私は以下のような小さなテストハーネスを持っています: - (VB .NEt/VS2010/FrmWrk 4)

 Dim objStreamReader As New StreamReader("C:\Testing\101 VB.NET Samples\SerializeandDeserializeXML\rdp.xml") 
     Dim p2 As ChangeEventManagerService.ChangeNotificationDto 
     Dim output As StringBuilder = New StringBuilder() 

     Using xmlrdr As XmlReader = XmlReader.Create(New StringReader(objStreamReader.ReadToEnd())) 
      Dim ws As XmlWriterSettings = New XmlWriterSettings() 
      ws.Indent = True 
      Using writer As XmlWriter = XmlWriter.Create(output, ws) 

       ' Parse the file and display each of the nodes. 
       While xmlrdr.Read() 
        Select Case xmlrdr.NodeType 
         Case XmlNodeType.Element 
          writer.WriteStartElement(xmlrdr.Name) 
         Case XmlNodeType.Text 
          writer.WriteString(xmlrdr.Value) 
         Case XmlNodeType.XmlDeclaration 
         Case XmlNodeType.ProcessingInstruction 
          writer.WriteProcessingInstruction(xmlrdr.Name, xmlrdr.Value) 
         Case XmlNodeType.Comment 
          writer.WriteComment(xmlrdr.Value) 
         Case XmlNodeType.EndElement 
          writer.WriteFullEndElement() 
        End Select 
       End While 
      End Using 

      Console.Write(output.ToString()) '# up to this point all is good 

      If x.CanDeserialize(xmlrdr) Then '# this fails 
       p2 = CType(x.Deserialize(objStreamReader), ChangeEventManagerService.ChangeNotificationDto) '# forcing it to here throws an error as expected! 
       objStreamReader.Close() 
      End If 

     End Using '# reader 


     ''Display property values of the new product object. 
     Console.WriteLine(p2.changeEventTypeCode) 
     Console.WriteLine(p2.messageId) 


    Catch ex As Exception 
     Console.WriteLine(ex.InnerException.ToString()) 
     Console.WriteLine(ex.ToString()) 
    End Try 

    Console.ReadLine() 

「ルート要素がありません」というエラーがスローされました。

誰でも私にこれを手伝ってもらえますか、私は少し迷っています。

私は、ルート要素が要素か、または 要素であると推定していました。とにかく

は、私が作った願って、すべてをクリア...

TIA

ジャブ

答えて

0

それは余分な文字を持っている ' - ' ファイルの先頭に

<?xml version="1.0" encoding="UTF-8"?> 
<changeNotificationDto xmlns="http://www.Company.com/item" changeEventTypeCode="RemoveDeliveryPoint" messageId="10" sentDateTime="1970-01-01T00:00:00.000Z"> 
<entry action="Remove" type="DeliveryPoint"> 
<removeEntityNotification> 
<type>DeliveryPoint</type> 
<compassKey>1139</compassKey> 
</removeEntityNotification> 
<changeDelta> 
<changeDeltaType>ObjectRemove</changeDeltaType> 
<recordId>1139</recordId> 
<recordType>DeliveryPoint</recordType> 
<subRecordId>2324</subRecordId> 
<subRecordType>ExternalReference</subRecordType> 
</changeDelta> 
<changeDelta> 
<changeDeltaType>ObjectRemove</changeDeltaType> 
<recordId>1139</recordId> 
<recordType>DeliveryPoint</recordType> 
</changeDelta> 
</entry> 
</changeNotificationDto> 

上記のxml。 IEでxmlを開いてメモ帳に貼り付けると起こります。それは余分な ' - '文字を運びます。

+0

こんにちは、 あなたの返信をありがとう.... xmlファイルには、私が見る/見つけて/明らかにすることができる隠された文字や "余分な"文字がありません。 このトピックを作成したときに、上記のxmlの " - "が追加されました。実際のテキスト文字列には改行やキャリッジリターンはありません。 削除するタグの間に空白があります。 私は行方不明の他の種類の文字がありますか? – justabloke

+0

xとは何か分かりますか? – ysrb

関連する問題