I have the following XML Document loaded in a XDocument
<XXXXXXXXXXXXXXXXXX xmlns:XXXXX="http://XXXXX/XXXXX/XXXXX/" xmlns:mbs="http://www.microsoft.com/xml">
<ProdOrderRoutingLine xmlns="Prod. Order Routing Line" />
<Count>2</Count>
<Records>
<Record>
<Field>
<Name xmlns="Name">Company-Company-Company-Company</Name>
<Value xmlns="Value">CRONUS Canada, Inc.</Value>
<FieldCaption xmlns="FieldCaption">Name</FieldCaption>
</Field>
<Field>
<Name xmlns="Name">Operation No.</Name>
<Value xmlns="Value">020</Value>
<Caption xmlns="Caption">Operation No.</Caption>
</Field>
<Field>
<Name xmlns="Name">Line No.</Name>
<Value xmlns="Value">771521</Value>
<Caption xmlns="Caption" />
</Field>
</Record>
<Record>
<Field>
<Name xmlns="Name">Company-Company-Company-Company</Name>
<Value xmlns="Value">CRONUS Canada, Inc.</Value>
<FieldCaption xmlns="FieldCaption">Name</FieldCaption>
</Field>
<Field>
<Name xmlns="Name">Operation No.</Name>
<Value xmlns="Value">020</Value>
<Caption xmlns="Caption">Operation No.</Caption>
</Field>
<Field>
<Name xmlns="Name">Line No.</Name>
<Value xmlns="Value">798122</Value>
<Caption xmlns="Caption" />
</Field>
</Record>
</Records>
</XXXXXXXXXXXXXXXXXX>
I am trying to read it using LINQ and populate this class for each record
public class Record
{
public IEnumerable<Field> Fields { get; set; }
public Record()
{
Fields = new List<Field>();
}
}
public class Field
{
public string Name { get; set; }
public string Value { get; set; }
public string Caption { get; set; }
}
Any proper way of feeding the XML inside my collection is welcome.
I tried messing around with :
var doc = XDocument.Load(@"c:\test\output.xml");
var query = from table in doc.Element("XXXXXXXXXXXXXXXXXX").Element("Records").Elements("Record")
select new
{
name = table.Elements("Field").Attributes("Name"),
value = table.Elements("Field").Attributes("Value"),
caption = table.Elements("Field").Attributes("FieldCaption")
};
I get nothing close to what I am looking for.