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

Xml Serialization

Scheduled Pinned Locked Moved C#
tutorialquestiongraphicsdata-structuresxml
4 Posts 2 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.
  • L Offline
    L Offline
    Lea Hayes
    wrote on last edited by
    #1

    Hi, What is the easiest way to serialize an array of objects like the one in the following code example?

    public void Test()
    {
    List arObject = new List();
    arObject.Add(Color.Red);
    arObject.Add(Color.Green);
    arObject.Add(new string("Hello World!"));
    arObject.Add(new MyObject());

    // How to serialize to and from file here?
    }

    In my program the object array represents an array of property values which could be of any time. Custom objects implement the IXmlSerializable interface, and simple types like strings appear to work fine. So far I have found problems with the low-level types like System.Drawing.Color and the like. Is there a generic way of serializing objects which do not implement the IXmlSerializable interface? At the moment I am not using the XmlSerializer class because I need extra control over how objects are serialized. So instead I am just using the XmlWriter class. Any help would be greatly appreciated! Lea Hayes

    M 1 Reply Last reply
    0
    • L Lea Hayes

      Hi, What is the easiest way to serialize an array of objects like the one in the following code example?

      public void Test()
      {
      List arObject = new List();
      arObject.Add(Color.Red);
      arObject.Add(Color.Green);
      arObject.Add(new string("Hello World!"));
      arObject.Add(new MyObject());

      // How to serialize to and from file here?
      }

      In my program the object array represents an array of property values which could be of any time. Custom objects implement the IXmlSerializable interface, and simple types like strings appear to work fine. So far I have found problems with the low-level types like System.Drawing.Color and the like. Is there a generic way of serializing objects which do not implement the IXmlSerializable interface? At the moment I am not using the XmlSerializer class because I need extra control over how objects are serialized. So instead I am just using the XmlWriter class. Any help would be greatly appreciated! Lea Hayes

      M Offline
      M Offline
      mav northwind
      wrote on last edited by
      #2

      Hi! Does it have to be XML? Otherwise the BinaryFormatter is a very easily to use alternative. Or use the SoapFormatter (although I think it has a problem with generics IIRC).

      Regards, mav -- Black holes are the places where God divided by 0...

      L 1 Reply Last reply
      0
      • M mav northwind

        Hi! Does it have to be XML? Otherwise the BinaryFormatter is a very easily to use alternative. Or use the SoapFormatter (although I think it has a problem with generics IIRC).

        Regards, mav -- Black holes are the places where God divided by 0...

        L Offline
        L Offline
        Lea Hayes
        wrote on last edited by
        #3

        Hi, Unfortunately the BinaryFormatter will not do the trick because it is not easily edited by the user. I keep seeing SoapFormatter pop up here and there, I've not actually use this before so I think it is time to dig into some MSDN documentation and the brilliant selection of articles on CodeProject! Thanks for your advice! Lea Hayes

        M 1 Reply Last reply
        0
        • L Lea Hayes

          Hi, Unfortunately the BinaryFormatter will not do the trick because it is not easily edited by the user. I keep seeing SoapFormatter pop up here and there, I've not actually use this before so I think it is time to dig into some MSDN documentation and the brilliant selection of articles on CodeProject! Thanks for your advice! Lea Hayes

          M Offline
          M Offline
          mav northwind
          wrote on last edited by
          #4

          Hi! Yes, the binary files created by BinaryFormatter cannot be edited easily by the user, but it's also a way to protect the integrity of your serialized data. When users can play around, they will and then you'll have to deal with invalid XML files... :sigh: So depending on what you want the user to edit, creating a separate function to modify the serialized data could be a safer option.

          Regards, mav -- Black holes are the places where God divided by 0...

          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