Parsing XmlAttribute as complex type



I'm trying to create object model of SVG format. So, as it XML, i'm using XmlSerializer. But i have a problem. There're some xml attributes named "style". It looks like complex type, but represents as string. There's example of this attribute:



style="fill:none;stroke:#00ff00;stroke-width:8.7489996;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:8.74900006"



As you can see, there're properties like "fill", "stroke", "stroke-width" and etc. I wrote the class



public class SvgStyle
{
public string FillColor { get; set; }
public string StrokeColor { get; set; }
public float StrokeWidth { get; set; }
public int StrokeMiterlimit { get; set; }
public float StrokeOpacity { get; set; }
public float StrokeDashoffset { get; set; }
public string StrokeDasharray { get; set; }
}


and an another class



public abstract class SvgGraphicElement
{
[XmlAttribute("style")]
public SvgStyle Style { get; set; }
}


All i got is exception



Cannot serialize member 'Style' of type Svg.SvgStyle. XmlAttribute/XmlText cannot be used to encode complex types.



I tries to use IXmlSerializable interface implemantation and OnSerializing/OnDeserializing methods, but all i got was another exceptions. Is there any way to deserialize this string to my class? Thanks.


No comments:

Post a Comment