views:

106

answers:

1

HI,

I would like to have the configuration data for my application stored in a XML config file that I modify manually, however, I'm not sure how I would go about storing more complex types.

For example, If I wanted to store X,Y coordinates and I had a class to represent this, its easy enough to specify the data type, but I have no idea how this would look serialized.

So how can I change an XML file by hand and represent complex types.

+1  A: 

There are two ways to store structured data in XML: attributes, and child elements. Attributes are easier to use, but only support primitive types; child elements support nested types and arrays as well.

Suppose you have your class Point, and support you have a value origin of type Point. Using attributes, the xml should look like this

<origin x='10' y='7'/>

If you want child elements instead, you write

<origin>
 <x>10</x>
 <y>7</x>
</origin>
Martin v. Löwis
Thanks Martin, its a little clearer now. But lets just say that System.Drawing.Point was an attribute of an element. How would I express this?
Sir Psycho
Not sure we use the same terminology: "attribute" and "element" are XML terms. They have nothing to do with your programming language. Attributes are the things with = sign; elements are the things with less-than and greater-then. Wrt. System.Drawing.Point: what is the name of the field in the class that has the type Point?
Martin v. Löwis