Reputation: 435
I have created such classes:
[XmlRoot(ElementName = "Control", Namespace = "http://schemas.microsoft.com/VisualStudio/2011/storyboarding/stencilDocument"),Serializable]
public class ControlStencilXML
{
[XmlAttribute("ReferenceName")]
public string ReferenceName;
[XmlAttribute("DisplayName")]
public string DisplayName;
[XmlAttribute("Revision")]
public int Revision;
[XmlAttribute("IsBackground")]
public bool IsBackground;
[XmlAttribute("DefaultInsertionPoint")]
public string DefaultInsertionPoint;
[XmlAttribute("IsAnimated")]
public bool IsAnimated;
[XmlAttribute("KeyWords")]
public string KeyWords;
[XmlAttribute("ToolTip")]
public string ToolTip;
[XmlElement("ShapeLayouts")]
public List<ShapeLayout> ShapeLayouts;
}
[XmlRoot(ElementName = "ShapeLayout", Namespace = "http://schemas.microsoft.com/VisualStudio/2011/storyboarding/stencilDocument")]
public class ShapeLayout
{
[XmlAttribute("Name")]
string Name;
[XmlAttribute("HorizontalAlignment")]
string HorizontalAlignment;
[XmlAttribute("VerticalAlignment")]
string VerticalAlignment;
}
XLM that I want to deserialize:
<?xml version="1.0" encoding="utf-8"?>
<Control ReferenceName="System.Storyboarding.Common.CheckBoxChecked" DisplayName="Checkbox (checked)" ToolTip="Checked checkbox with a text label" Revision="1" IsBackground="false" DefaultInsertionPoint="Default" Keywords="Toggle, Phone" IsAnimated="false" xmlns="http://schemas.microsoft.com/VisualStudio/2011/storyboarding/stencilDocument">
<ShapeLayouts>
<ShapeLayout Name="Check" HorizontalAlignment="Left" VerticalAlignment="Center" />
<ShapeLayout Name="CheckBox" HorizontalAlignment="Left" VerticalAlignment="Center" />
<ShapeLayout Name="Content" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
</ShapeLayouts>
</Control>
There is no errors when I am trying to deserialize, the problem is that I am getting only first ShapeLayout object, and all of its values are equal to null. Where did I make mistake? How to fix it?
Upvotes: 0
Views: 113
Reputation: 3726
you'll need one more wrapper object to conform to the provided XML
-
[XmlRoot(ElementName = "ShapeLayouts", Namespace = "http://schemas.microsoft.com/VisualStudio/2011/storyboarding/stencilDocument")]
public class ShapeLayouts
{
[XmlElement(ElementName = "ShapeLayout", Namespace = "http://schemas.microsoft.com/VisualStudio/2011/storyboarding/stencilDocument")]
public List<ShapeLayout> ShapeLayout { get; set; }
}
Upvotes: 1