2016-05-31 29 views
0

Ich habe solche Klassen erstellt:Deserialisieren XML-Objekt, falsche Werte

[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, die ich deserialisieren möchten:

<?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> 

Es gibt keine Fehler, wenn ich deserialisieren bin versucht, das Problem ist, dass ich nur das erste ShapeLayout-Objekt bekomme und alle seine Werte gleich null sind. Wo habe ich Fehler gemacht? Wie man es repariert?

Antwort

1

Sie ein weiteres Wrapper-Objekt muss die vorgesehenen XML anzupassen - Arbeits

[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; } 
} 
+0

Vielen Dank. Ich habe auch die Sichtbarkeit der ShapeLayout-Felder geändert. – buks