Help reading recursive XML using XML.LINQ (C#) -


I have just started using LINQ and I'm having some problems that can be read continuously from an XML file

If I have the same XML

  & gt; & Lt; ProjectTemplates & gt; & Gt; & Lt; Project template name = "standard" & gt; & Gt; & Lt; DeliverableTemplates & gt; & Gt; & Lt; DeliverableTemplate Name = "Each Deliverable" & gt; & Gt; & Lt; DependantDeliverables & gt; & Gt; & Lt; DeliverableTemplate name = "can be a collection" & gt; & Gt; & Lt; DependantDeliverables & gt; & Gt; & Lt; DeliverableTemplate name = "dependent deliverables" & gt; & Gt; & Lt; DependantDeliverables & gt; & Gt; & Lt; DeliverableTemplate name = "recurring" & gt; & Gt; & Lt; DependantDeliverables / & gt; & Gt; & Lt; / DeliverableTemplate & gt; & Gt; & Lt; / DependantDeliverables & gt; & Gt; & Lt; / DeliverableTemplate & gt; & Gt; & Lt; / DependantDeliverables & gt; & Gt; & Lt; / DeliverableTemplate & gt; & Gt; & Lt; / DependantDeliverables & gt; & Gt; & Lt; / DeliverableTemplate & gt; & Gt; & Lt; / DependantDeliverables & gt; & Gt; & Lt; / DeliverableTemplate & gt; & Gt; & Lt; / DependantDeliverables & gt; & Gt; & Lt; / DeliverableTemplate & gt; & Gt; & Lt; / ProjectTemplates & gt;   

And I'm trying to read it in simple sections

  internal class project {public string name; Public list & amp; the lift; Deliverable & gt; Deliverable; } Internal category distributed {public string name; Public list & amp; the lift; Deliverable & gt; DependantDeliverables; Public Deliverable () {Dependent Deliverables = New List & amp; the lift; Deliverable & gt; (); }}   

But I'm sure how to go about it. This is as far as I have found

  var xmlProjects = XElement.Load (XMLPath); ("Project Template") Select Elements ("Project Template") New Project {name = el.Attribute ("name") value, Deliverables = (el.Deliverables to el.Elements ("DeliverableTemplates") elements (. Select "DeliverableTemplate") New Deliverable {name = elDeliverables.Attribute ("name") value, DependantDeliverables = new list. & Lt; deliverable & gt; ()}) .toList & LT; Deliverable & gt; ()}) .toList & LT; Project & gt; (); I have problems making a list of dependable deliverables. I am also not sure whether I can do it in a statement like this.  

Can anyone help?

Jason

I will change the code> deliverable class so that It takes its creator in XElement corresponding to a given & lt; DeliverableTemplate & gt; . This is the reason why the manufacturer will be responsible for traversing XElement, looking for children, placing the list with & lt; >, And further constructors proceed further and passing in XElements until you have reached and parsed all your nodes .

Comments