views:

23

answers:

1

I want to serialize the following structure in xml with C#.

<?xml version="1.0" encoding="UTF-8"?>
...
<complement>
<hello:world color="0" number="1" >
</complement>
...

... or something like that. I'm interested in namespaces and attributes serializing :P

[(namespace)]
class { } 

etc.

Thanks

+1  A: 

You can specify namespaces in the various XML serialization attributes. Here is a sample:

[XmlRoot(Namespace = "http://schemas.fabrikam.com/mynamespace")]
[XmlType(Namespace = "http://schemas.fabrikam.com/mynamespace")]
public class MyObject
{
    [XmlElement(Namespace = "http://schemas.fabrikam.com/anothernamespace")]
    public string MyElement { get; set; }

    [XmlAttribute(Namespace = "http://schemas.fabrikam.com/yetanothernamespace")]
    public string MyAttribute { get; set; }
}
kbrimington