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. XML / XSL
  4. Serializing StringDictonary to XML

Serializing StringDictonary to XML

Scheduled Pinned Locked Moved XML / XSL
csharpxmlquestion
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.
  • W Offline
    W Offline
    WiseHacker
    wrote on last edited by
    #1

    Does anyone know how I can serialize a StringDictonary to XML? Failing that, is there another structure that I can use that is serializable? I'm trying to use WSRF.Net but my code gets halted as the structures are I use are not serializable. I want to do so without having to use long complicated code and multi-dimensional string arrays. My thanks in advance.

    S 1 Reply Last reply
    0
    • W WiseHacker

      Does anyone know how I can serialize a StringDictonary to XML? Failing that, is there another structure that I can use that is serializable? I'm trying to use WSRF.Net but my code gets halted as the structures are I use are not serializable. I want to do so without having to use long complicated code and multi-dimensional string arrays. My thanks in advance.

      S Offline
      S Offline
      Stefan Troschuetz
      wrote on last edited by
      #2

      The StringDictionary has the SerializableAttribute, so you should be able to use the XmlSerializer in order to serialze or deserialize instances of the class to or from a XML document, respectively.


      "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook

      www.troschuetz.de

      W 1 Reply Last reply
      0
      • S Stefan Troschuetz

        The StringDictionary has the SerializableAttribute, so you should be able to use the XmlSerializer in order to serialze or deserialize instances of the class to or from a XML document, respectively.


        "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook

        www.troschuetz.de

        W Offline
        W Offline
        WiseHacker
        wrote on last edited by
        #3

        I know that, but this is where it gets frustrating. StringDictionary implements the IDictonary interface and the serializer aborts saying classes implementing that interface are not supported yet.

        S 1 Reply Last reply
        0
        • W WiseHacker

          I know that, but this is where it gets frustrating. StringDictionary implements the IDictonary interface and the serializer aborts saying classes implementing that interface are not supported yet.

          S Offline
          S Offline
          Stefan Troschuetz
          wrote on last edited by
          #4

          WiseHacker wrote:

          StringDictionary implements the IDictonary interface and the serializer aborts saying classes implementing that interface are not supported yet.

          So I guess you have to do it on your own. Should not be to hard using the XmlTextWriter and XmlTextReader classes. Simply iterate over the dictionary and use the appropriate WriteXX or ReadXX methods to store or retrieve each dictionary entry. The resulting XML could look like that:

          <dictionary>
          <entry>
          <key>key1</key>
          <value>value1</value>
          </entry>
          <entry>
          <key>key2</key>
          <value>value2</value>
          </entry>
          ...
          </dictionary>


          "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook

          www.troschuetz.de

          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