Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use LINQ to convert a xml file in to an object
    primarykey
    data
    text
    <p>I have xml files with following to generate the menu for our web site.</p> <pre><code> &lt;xs:element name="Menu"&gt; &lt;xs:complexType&gt; &lt;xs:sequence&gt; &lt;xs:element name="MenuItem" type="MenuItemType" maxOccurs="unbounded"&gt;&lt;/xs:element&gt; &lt;/xs:sequence&gt; &lt;xs:attribute name="Title" type="xs:string"&gt;&lt;/xs:attribute&gt; &lt;xs:attribute name="Type" type="xs:string"&gt;&lt;/xs:attribute&gt; &lt;/xs:complexType&gt; &lt;/xs:element&gt; &lt;xs:complexType name="MenuItemType"&gt; &lt;xs:choice minOccurs="0" maxOccurs="unbounded"&gt; &lt;xs:element name="MenuItem" type="MenuItemType" /&gt; &lt;/xs:choice&gt; &lt;xs:attribute name="Text" type="xs:string"&gt;&lt;/xs:attribute&gt; &lt;xs:attribute name="Url" type="xs:string"&gt;&lt;/xs:attribute&gt; &lt;/xs:complexType&gt; </code></pre> <p>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</p> <pre><code> public partial class Menu { /// &lt;remarks/&gt; [System.Xml.Serialization.XmlElementAttribute("MenuItem")] public MenuItemType[] MenuItem; /// &lt;remarks/&gt; [System.Xml.Serialization.XmlAttributeAttribute()] public string Title; /// &lt;remarks/&gt; [System.Xml.Serialization.XmlAttributeAttribute()] public string Type; } public partial class MenuItemType { /// &lt;remarks/&gt; [System.Xml.Serialization.XmlElementAttribute("MenuItem")] public MenuItemType[] Items; /// &lt;remarks/&gt; [System.Xml.Serialization.XmlAttributeAttribute()] public string Text; /// &lt;remarks/&gt; [System.Xml.Serialization.XmlAttributeAttribute()] public string Url; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload