Deserialize multiple XML documents

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jonker
    New Member
    • Jul 2008
    • 2

    Deserialize multiple XML documents

    Hi All,

    I have a TCP Client which reads the data from the socket. Now I have to deserialize the received data. The data can contain multiple XML documents like :

    <customer field="value">
    <address>road 11<address/>
    <customer/>
    <supplier>
    <goods>printers <goods/>
    <supplier/>

    In this case I want to deserialize customer and secondly the supplier. I know how I deserialize each individual document as long as I know which document should be deserialized. Ofcourse, I can check the name of the root tag and fire the applicable deserialization function. But I hope there is a more generic way to do this.

    Thanks for your help in advance
  • TTCEric
    New Member
    • Jul 2008
    • 26

    #2
    is that the data as recieved from the socket?
    i think all you need to do is get an XML reader and use that as long as its relatively well-formed.
    but you mention deserialize. thats taking objects passed between domains and using them as objects in your code. in this case you seem to have the data deserialized already.
    all you need now is an xml object to get to the element you need.

    Comment

    • jonker
      New Member
      • Jul 2008
      • 2

      #3
      The data is directly received from the socket. The problem is that each message has a different structure and its own root node.

      OK, I can't deserialize multiple root nodes, but I can detect a full message and parse the single message.

      At the moment of deserialization you have to specify the type of the target object.
      XmlSerializer xs = new XmlSerializer(t ypeof(customer) );

      Since this can be multiple objects (customer of supplier) I can't use this method. How can I solve this issue? As said by multiple functions or is there a generic way ?

      The input format is specified by a 3th party, so I can't modify the structure :-(

      Comment

      Working...