hi all,
I am very new to xml and LINQ.
i have an xml as follows
And i am using linq for reading the xml. Here is my code for reading xml
When i am reading the xml i am getting only the first value from the xml (i.e. pop1) but i want the six items in a list.
how to get the six items in a single list. and is that xml valid?
please help..
Regards
Veena
I am very new to xml and LINQ.
i have an xml as follows
Code:
<?xml version='1.0' encoding='utf-8' ?>
<Purchase_Info>
<Purchase_Order_Proposal>
<Purchase_Order_Proposal id='1'>pop1</Purchase_Order_Proposal>
<Purchase_Order_Proposal id='2'>pop2</Purchase_Order_Proposal>
<Purchase_Order_Proposal id='3'>pop3</Purchase_Order_Proposal>
<Purchase_Order_Proposal id='4'>pop4</Purchase_Order_Proposal>
<Purchase_Order_Proposal id='5'>pop5</Purchase_Order_Proposal>
<Purchase_Order_Proposal id='6'>pop6</Purchase_Order_Proposal>
</Purchase_Order_Proposal>
<Purchase_Order>
<Purchase_Order id='1'>po1</Purchase_Order>
<Purchase_Order id='2'>po2</Purchase_Order>
<Purchase_Order id='3'>po3</Purchase_Order>
<Purchase_Order id='4'>po4</Purchase_Order>
<Purchase_Order id='5'>po5</Purchase_Order>
<Purchase_Order id='6'>po6</Purchase_Order>
</Purchase_Order>
</Purchase_Info>
And i am using linq for reading the xml. Here is my code for reading xml
Code:
string filePath = “C:\\allFields.xml";
System.IO.StreamReader streamReader = new System.IO.StreamReader(filePath);
string strFileContent = streamReader.ReadToEnd();
XDocument xDocument = XDocument.Parse(strFileContent);
var listArray = from g in xDocument.Descendants().Descendants("Purchase_Info")
select new
{
fields = g.Element("Purchase_Order_Proposal").Value
};
foreach (var itm in listArray)
{
var fields = itm.fields.Trim();
}
how to get the six items in a single list. and is that xml valid?
please help..
Regards
Veena
Comment