Serialize

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

    #1

    Serialize

    Is it possible to "Serialize" a class to xml into a string or XmlDocument
    without having to create a disk file?

    Thanks in advance.





  • KJ

    #2
    Re: Serialize

    Sure:
    public string XmlSerialize()
    {
    XmlSerializer mySerializer = new XmlSerializer(t his.GetType());
    MemoryStream ms = new MemoryStream();
    mySerializer.Se rialize(ms, this);
    ms.Position = 0;
    StreamReader sr = new StreamReader(ms );
    return sr.ReadToEnd();
    }

    And this is nice and generic.

    Comment

    • Peter Rilling

      #3
      Re: Serialize

      XmlSerializer.S erialize() has overloads that take streams and such. Is that
      what you are talking about?

      "David" <Contributor@Ad sorptionProcess Modeling.com> wrote in message
      news:LfGpf.5715 1$WH.53556@duke read01...[color=blue]
      > Is it possible to "Serialize" a class to xml into a string or XmlDocument
      > without having to create a disk file?
      >
      > Thanks in advance.
      >
      >
      >
      >
      >[/color]


      Comment

      Working...