deserialization of xml with unknown object type?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • KenK

    #1

    deserialization of xml with unknown object type?

    Hi all,

    Been reading all day about object serialization techniques in C# and my
    problem is that everything I read is requiring a "known" object class. Is
    there a way to create an object from the xml code itself without casting it
    through an object?

    If not, what is the best way to allow the end user to create their own
    object classes?

    Thanks,
    Ken


  • Robert Johnson

    #2
    Re: deserialization of xml with unknown object type?


    "KenK" <techsupp@helpc onsulting.net> wrote in message
    news:26265$43c2 fb79$438cec90$1 5304@ALLTEL.NET ...[color=blue]
    > Hi all,
    >
    > Been reading all day about object serialization techniques in C# and my
    > problem is that everything I read is requiring a "known" object class. Is
    > there a way to create an object from the xml code itself without casting[/color]
    it[color=blue]
    > through an object?
    >
    > If not, what is the best way to allow the end user to create their own
    > object classes?
    >
    > Thanks,
    > Ken
    >
    >[/color]

    If you want to serialize data using XML then you have to have the requisite
    information about the 'types' represented in XML.
    Visual Studio can/does this for you. The 'types' I refer to will be likely a
    reflection of an underlying datalayer that provides relational information
    to the calling class about the tables in that data layer. Table names and
    table column names lend themselves well to XML structured documents.

    Not sure what you mean about 'allow the end user to create their own object
    classes?'

    LW


    Comment

    • Nicholas Paldino [.NET/C# MVP]

      #3
      Re: deserialization of xml with unknown object type?

      Ken,

      You can use true serialization (using an implementation of IFormatter)
      and you can have fields of type object which are serialized/deserialized
      correctly. However, with XML serialization, you need to know the types of
      the objects being exposed, because of the way that it works (using public
      properties on the exposed type).

      Hope this helps.


      --
      - Nicholas Paldino [.NET/C# MVP]
      - mvp@spam.guard. caspershouse.co m

      "KenK" <techsupp@helpc onsulting.net> wrote in message
      news:26265$43c2 fb79$438cec90$1 5304@ALLTEL.NET ...[color=blue]
      > Hi all,
      >
      > Been reading all day about object serialization techniques in C# and my
      > problem is that everything I read is requiring a "known" object class. Is
      > there a way to create an object from the xml code itself without casting
      > it through an object?
      >
      > If not, what is the best way to allow the end user to create their own
      > object classes?
      >
      > Thanks,
      > Ken
      >
      >[/color]


      Comment

      • KenK

        #4
        Re: deserialization of xml with unknown object type?

        thanks,

        The idea is that the end user opens an xml file and the content of that xml
        file would be displayed in a propertygrid with the xml field names
        representing names in the propertygrid and the values would be in the right
        (values) column.

        Thanks again,
        Ken

        "Robert Johnson" <robert10021@ya hoo.com> wrote in message
        news:TCDwf.5726 7$Ou3.29367@duk eread09...[color=blue]
        >
        > "KenK" <techsupp@helpc onsulting.net> wrote in message
        > news:26265$43c2 fb79$438cec90$1 5304@ALLTEL.NET ...[color=green]
        >> Hi all,
        >>
        >> Been reading all day about object serialization techniques in C# and my
        >> problem is that everything I read is requiring a "known" object class.
        >> Is
        >> there a way to create an object from the xml code itself without casting[/color]
        > it[color=green]
        >> through an object?
        >>
        >> If not, what is the best way to allow the end user to create their own
        >> object classes?
        >>
        >> Thanks,
        >> Ken
        >>
        >>[/color]
        >
        > If you want to serialize data using XML then you have to have the
        > requisite
        > information about the 'types' represented in XML.
        > Visual Studio can/does this for you. The 'types' I refer to will be likely
        > a
        > reflection of an underlying datalayer that provides relational information
        > to the calling class about the tables in that data layer. Table names and
        > table column names lend themselves well to XML structured documents.
        >
        > Not sure what you mean about 'allow the end user to create their own
        > object
        > classes?'
        >
        > LW
        >
        >[/color]


        Comment

        • Nicholas Paldino [.NET/C# MVP]

          #5
          Re: deserialization of xml with unknown object type?

          Ken,

          In this case, you don't necessarily need to use serialization for this.

          You can create a class that implements ICustomTypeDesc riptor and exposes
          the properties to show in the property grid.

          You just have your class load the XML file, and then have the
          GetProperties method return the properties that correspond to the data in
          the file.

          Hope this helps.


          --
          - Nicholas Paldino [.NET/C# MVP]
          - mvp@spam.guard. caspershouse.co m

          "KenK" <techsupp@helpc onsulting.net> wrote in message
          news:61824$43c3 0aa5$438cec90$2 1680@ALLTEL.NET ...[color=blue]
          > thanks,
          >
          > The idea is that the end user opens an xml file and the content of that
          > xml file would be displayed in a propertygrid with the xml field names
          > representing names in the propertygrid and the values would be in the
          > right (values) column.
          >
          > Thanks again,
          > Ken
          >
          > "Robert Johnson" <robert10021@ya hoo.com> wrote in message
          > news:TCDwf.5726 7$Ou3.29367@duk eread09...[color=green]
          >>
          >> "KenK" <techsupp@helpc onsulting.net> wrote in message
          >> news:26265$43c2 fb79$438cec90$1 5304@ALLTEL.NET ...[color=darkred]
          >>> Hi all,
          >>>
          >>> Been reading all day about object serialization techniques in C# and my
          >>> problem is that everything I read is requiring a "known" object class.
          >>> Is
          >>> there a way to create an object from the xml code itself without casting[/color]
          >> it[color=darkred]
          >>> through an object?
          >>>
          >>> If not, what is the best way to allow the end user to create their own
          >>> object classes?
          >>>
          >>> Thanks,
          >>> Ken
          >>>
          >>>[/color]
          >>
          >> If you want to serialize data using XML then you have to have the
          >> requisite
          >> information about the 'types' represented in XML.
          >> Visual Studio can/does this for you. The 'types' I refer to will be
          >> likely a
          >> reflection of an underlying datalayer that provides relational
          >> information
          >> to the calling class about the tables in that data layer. Table names and
          >> table column names lend themselves well to XML structured documents.
          >>
          >> Not sure what you mean about 'allow the end user to create their own
          >> object
          >> classes?'
          >>
          >> LW
          >>
          >>[/color]
          >
          >[/color]


          Comment

          • KenK

            #6
            Re: deserialization of xml with unknown object type?

            thank you much. I will investigate this.

            ken

            "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c om> wrote in
            message news:%23$IiXUYF GHA.140@TK2MSFT NGP12.phx.gbl.. .[color=blue]
            > Ken,
            >
            > In this case, you don't necessarily need to use serialization for this.
            >
            > You can create a class that implements ICustomTypeDesc riptor and
            > exposes the properties to show in the property grid.
            >
            > You just have your class load the XML file, and then have the
            > GetProperties method return the properties that correspond to the data in
            > the file.
            >
            > Hope this helps.
            >
            >
            > --
            > - Nicholas Paldino [.NET/C# MVP]
            > - mvp@spam.guard. caspershouse.co m
            >
            > "KenK" <techsupp@helpc onsulting.net> wrote in message
            > news:61824$43c3 0aa5$438cec90$2 1680@ALLTEL.NET ...[color=green]
            >> thanks,
            >>
            >> The idea is that the end user opens an xml file and the content of that
            >> xml file would be displayed in a propertygrid with the xml field names
            >> representing names in the propertygrid and the values would be in the
            >> right (values) column.
            >>
            >> Thanks again,
            >> Ken
            >>
            >> "Robert Johnson" <robert10021@ya hoo.com> wrote in message
            >> news:TCDwf.5726 7$Ou3.29367@duk eread09...[color=darkred]
            >>>
            >>> "KenK" <techsupp@helpc onsulting.net> wrote in message
            >>> news:26265$43c2 fb79$438cec90$1 5304@ALLTEL.NET ...
            >>>> Hi all,
            >>>>
            >>>> Been reading all day about object serialization techniques in C# and my
            >>>> problem is that everything I read is requiring a "known" object class.
            >>>> Is
            >>>> there a way to create an object from the xml code itself without
            >>>> casting
            >>> it
            >>>> through an object?
            >>>>
            >>>> If not, what is the best way to allow the end user to create their own
            >>>> object classes?
            >>>>
            >>>> Thanks,
            >>>> Ken
            >>>>
            >>>>
            >>>
            >>> If you want to serialize data using XML then you have to have the
            >>> requisite
            >>> information about the 'types' represented in XML.
            >>> Visual Studio can/does this for you. The 'types' I refer to will be
            >>> likely a
            >>> reflection of an underlying datalayer that provides relational
            >>> information
            >>> to the calling class about the tables in that data layer. Table names
            >>> and
            >>> table column names lend themselves well to XML structured documents.
            >>>
            >>> Not sure what you mean about 'allow the end user to create their own
            >>> object
            >>> classes?'
            >>>
            >>> LW
            >>>
            >>>[/color]
            >>
            >>[/color]
            >
            >[/color]


            Comment

            Working...