Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. XML Serialisation - is it possible to generate multiple views from an object? [modified]

XML Serialisation - is it possible to generate multiple views from an object? [modified]

Scheduled Pinned Locked Moved .NET (Core and Framework)
questioncsharpbusinessxml
3 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kalyan_A
    wrote on last edited by
    #1

    Hi All, I hope i am posting in the right forum as i am looking for a .Net related solution rather than a pure XML solution. I have the following class which i serialise using default XML serialisation. Class UserA UserID UserName Description Comments End Class Later, my requirements changed and i had to generate 2 views of the same data. In my 1st view, i would generate XML for the whole object (all 4 properties) My 2nd view - include only UserID and UserName. i modified the code as below Interface iUser UserID UserName End Class Class UserA Implements iUser UserID implements iUser.UserID UserName implements implements iUser.UserName Description Comments End Class I intended to serialise appropriate objects (iUser or UserA) based on my view requirements. Unfortunately, i realised that XML serailisation does not work on interfaces - end to my dreams of getting it easy :( My question is - if i have an Object instance, can i use any feature with serialisation to generate multiple views of an object? I have ventured towards creating seperate classes, ISerializable, etc. looking for suggestions on whats the best way to take this forward. Thanks in advance.

    modified on Thursday, August 13, 2009 4:23 AM

    T 1 Reply Last reply
    0
    • K Kalyan_A

      Hi All, I hope i am posting in the right forum as i am looking for a .Net related solution rather than a pure XML solution. I have the following class which i serialise using default XML serialisation. Class UserA UserID UserName Description Comments End Class Later, my requirements changed and i had to generate 2 views of the same data. In my 1st view, i would generate XML for the whole object (all 4 properties) My 2nd view - include only UserID and UserName. i modified the code as below Interface iUser UserID UserName End Class Class UserA Implements iUser UserID implements iUser.UserID UserName implements implements iUser.UserName Description Comments End Class I intended to serialise appropriate objects (iUser or UserA) based on my view requirements. Unfortunately, i realised that XML serailisation does not work on interfaces - end to my dreams of getting it easy :( My question is - if i have an Object instance, can i use any feature with serialisation to generate multiple views of an object? I have ventured towards creating seperate classes, ISerializable, etc. looking for suggestions on whats the best way to take this forward. Thanks in advance.

      modified on Thursday, August 13, 2009 4:23 AM

      T Offline
      T Offline
      Tristan Rhodes
      wrote on last edited by
      #2

      It might be worth bearing in mind that you can implement IXmlSerializable in an object and just dump that into the object hierachy you use the automated serializer for (XmlSerializer). The serializer will call the IXmlSerializable instead of using reflection, which means you could do your branching in there. However, it could be a maintainance time bomb. ^^

      ------------------------------- Carrier Bags - 21st Century Tumbleweed.

      K 1 Reply Last reply
      0
      • T Tristan Rhodes

        It might be worth bearing in mind that you can implement IXmlSerializable in an object and just dump that into the object hierachy you use the automated serializer for (XmlSerializer). The serializer will call the IXmlSerializable instead of using reflection, which means you could do your branching in there. However, it could be a maintainance time bomb. ^^

        ------------------------------- Carrier Bags - 21st Century Tumbleweed.

        K Offline
        K Offline
        Kalyan_A
        wrote on last edited by
        #3

        Its the maintenance i was worried about. But there appears to be no better way. Many thanks for posting your suggestion. :)

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups