Serializing StringDictonary to XML
-
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.
-
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.
The
StringDictionary
has theSerializableAttribute
, so you should be able to use theXmlSerializer
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
-
The
StringDictionary
has theSerializableAttribute
, so you should be able to use theXmlSerializer
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
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.
-
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.
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
andXmlTextReader
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