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. C#
  4. XML Serialization of derived classes

XML Serialization of derived classes

Scheduled Pinned Locked Moved C#
questionphpdatabasecomxml
3 Posts 3 Posters 0 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.
  • R Offline
    R Offline
    Roland Bar
    wrote on last edited by
    #1

    Hi I wanted to ask if it is possible to do something like this and how to do it: I would like to have a xml structure like this:

    <root>
    <collection>
    <element />
    <element attribute="value" />
    <element />
    </collection>
    <something />
    <somethingother />
    </root>

    The elements in the collection should be of the type ElementBase if the attribute is not set or of the type ElementDerived if the attribute is set to a value (the second element). So the Deserialized collection should be something like: List<ElementBase> collection = new List<ElementBase>() { new ElementBase(), new ElementDerived(), new ElementBase() }; ElementDerived would be derived from ElementBase:

    class ElementDerived : ElementBase {}

    I hope my question is described clearly. Thanks for your help :rose: Roland


    Hi! I'm a signature virus. Copy me into your sig file and help me spread!

    Follow your Euro notes in their tracks

    L S 2 Replies Last reply
    0
    • R Roland Bar

      Hi I wanted to ask if it is possible to do something like this and how to do it: I would like to have a xml structure like this:

      <root>
      <collection>
      <element />
      <element attribute="value" />
      <element />
      </collection>
      <something />
      <somethingother />
      </root>

      The elements in the collection should be of the type ElementBase if the attribute is not set or of the type ElementDerived if the attribute is set to a value (the second element). So the Deserialized collection should be something like: List<ElementBase> collection = new List<ElementBase>() { new ElementBase(), new ElementDerived(), new ElementBase() }; ElementDerived would be derived from ElementBase:

      class ElementDerived : ElementBase {}

      I hope my question is described clearly. Thanks for your help :rose: Roland


      Hi! I'm a signature virus. Copy me into your sig file and help me spread!

      Follow your Euro notes in their tracks

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      I find following link useful.. http://social.msdn.microsoft.com/Forums/en-US/netfxremoting/thread/41e462ab-f833-40a0-937b-3faaeba711e3/[^]

      Jinal Desai - LIVE Experience is mother of sage....

      1 Reply Last reply
      0
      • R Roland Bar

        Hi I wanted to ask if it is possible to do something like this and how to do it: I would like to have a xml structure like this:

        <root>
        <collection>
        <element />
        <element attribute="value" />
        <element />
        </collection>
        <something />
        <somethingother />
        </root>

        The elements in the collection should be of the type ElementBase if the attribute is not set or of the type ElementDerived if the attribute is set to a value (the second element). So the Deserialized collection should be something like: List<ElementBase> collection = new List<ElementBase>() { new ElementBase(), new ElementDerived(), new ElementBase() }; ElementDerived would be derived from ElementBase:

        class ElementDerived : ElementBase {}

        I hope my question is described clearly. Thanks for your help :rose: Roland


        Hi! I'm a signature virus. Copy me into your sig file and help me spread!

        Follow your Euro notes in their tracks

        S Offline
        S Offline
        Stanciu Vlad
        wrote on last edited by
        #3

        This is possible if you write your own custom xml deserializer. Based on your xml rules build the deserialization rules and then, at the parsing of element nodes, check if there is an atribute defined, and based on the result instantiate your element class. But I don't understand why you want to use something like this (inheritance), why not just put a flag in the base class (a bool flag, or an enum flag) to diferentiate between the two element types?

        I have no smart signature yet...

        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