I have xml files with following to generate the menu for our web site.
<xs:element name="Menu">
<xs:complexType>
<xs:sequence>
<xs:element name="MenuItem" type="MenuItemType" maxOccurs="unbounded"></xs:element>
</xs:sequence>
<xs:attribute name="Title" type="xs:string"></xs:attribute>
<xs:attribute name="Type" type="xs:string"></xs:attribute>
</xs:complexType>
</xs:element>
<xs:complexType name="MenuItemType">
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="MenuItem" type="MenuItemType" />
</xs:choice>
<xs:attribute name="Text" type="xs:string"></xs:attribute>
<xs:attribute name="Url" type="xs:string"></xs:attribute>
</xs:complexType>
Right now I am using xmlserializer to convert these xml files in to Menu objects and use them to generate the menu. I want to use LINQ to xml to convert these xml files in to same object. Any help will be appreciated. Generated class for above xml file is
public partial class Menu {
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("MenuItem")]
public MenuItemType[] MenuItem;
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string Title;
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string Type;
}
public partial class MenuItemType {
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("MenuItem")]
public MenuItemType[] Items;
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string Text;
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string Url;
}