c# - How can I load list of child elements from XML? -


I have to list the titles in each inquiry below, I am only inquired, but it is not a list of list rows.

  XElement myElement = XElement.Load ("Inquiries.xml"); Select var query = in MyElement.Elements ("Inquiry"). Select the new {InquiryId = (int) s.Element ("InquiryId"), first name = (string) s.Element ("FirstName"), LastName = (string). Element ("last name"), from LineEtems = myElement.Elements ("Inquiry"). Element ("LineItems") Select new {quantity = (int) l.Attribute ("volume"), PartNumber = (string) L. Attribution ("Partnumber")}}; Var Results = Query.toList ();   

XML:

  & lt; Inquiries & gt; & Lt; Inquiries & gt; & Lt; InquiryId & gt; 0 & lt; / InquiryId & gt; & Lt; FirstName & gt; John & lt; / First name & gt; & Lt; Last name & gt; Smith & lt; / Last name & gt; & Lt; Line items & gt; & Lt; LineItem Volume = "2" partnumber = "abc" & gt; & Lt; / LineItem & gt; & Lt; LineItem Volume = "3" partnumber = "abc" & gt; & Lt; / LineItem & gt; & Lt; LineItem Volume = "6" partnumber = "abc" & gt; & Lt; / LineItem & gt; & Lt; / Line item & gt; & Lt; / Inquiries & gt; & Lt; Inquiries & gt; & Lt; InquiryId & gt; 1 & lt; / InquiryId & gt; & Lt; FirstName & gt; Epic & lt; / First name & gt; & Lt; Last name & gt; Beardman & lt; / Last name & gt; & Lt; Line items & gt; & Lt; LineItem Volume = "2" partnumber = "abc" & gt; & Lt; / LineItem & gt; & Lt; LineItem Volume = "3" partnumber = "abc" & gt; & Lt; / LineItem & gt; & Lt; LineItem Volume = "6" partnumber = "abc" & gt; & Lt; / LineItem & gt; & Lt; / Line item & gt; & Lt; / Inquiries & gt; & Lt; / Inquiries & gt;    

  XElement myElement = XElement.Load ("Inquiries.xml"); Var query = from my element. Select Elements ("Inquiry") New {InquiryId = Convert.ToInt32 (s.Element ("InquiryId"). Value), FirstName = s.Element ("FirstName"). Value, LastName = ("LineItems") Elements ("LineItem") Select New {quantity = ConverttoInt32 (l.Attribute ("Quantity").), Partnumber = L. Specialty ("Partnumber"). Values}). ToList ()}; Var Results = Query.toList ();    

Comments

Popular posts from this blog

python - Assemble mpeg file unable to play in mediaplayer -

c# - crystal report failed -

mongodb - CakePHP paginator ignoring order, but only for certain values -