Now what I am looking for is, want to get object of particular nodes, with all the elements underneath that.
What I means is
1. In First XML, I want to get an Object of "ReportSummary" which should have two properties "ReportName" and "ReportId" and want to fill that object out of this XML.
So want to read from XML File, and create array of "ReportSummary" object where each object will have two properties filled out as "ReportName" and "ReportID".
2. In Second XML also, I want read this XML from File, get array of "ExpenseEntry" object same way with having "UserID", "RpeKey" and "ApprovedAmount" as its properties.
I am using visual studio 2010 so can you tell me what is the best way to achieve this?
1. In First XML, I want to get an Object of "ReportSummary" which should have two properties "ReportName" and "ReportId" and want to fill that object out of this XML.
So want to read from XML File, and create array of "ReportSummary" object where each object will have two properties filled out as "ReportName" and "ReportID".
Hi,
1) For your first problem,you can really use XDocument to cope with the problem:
niravparekh
Member
704 Points
427 Posts
How to get all elements under specific nodes
Jan 03, 2013 09:08 PM|LINK
Hi,
This is my two XML.
Now what I am looking for is, want to get object of particular nodes, with all the elements underneath that.
What I means is
1. In First XML, I want to get an Object of "ReportSummary" which should have two properties "ReportName" and "ReportId" and want to fill that object out of this XML.
So want to read from XML File, and create array of "ReportSummary" object where each object will have two properties filled out as "ReportName" and "ReportID".
2. In Second XML also, I want read this XML from File, get array of "ExpenseEntry" object same way with having "UserID", "RpeKey" and "ApprovedAmount" as its properties.
I am using visual studio 2010 so can you tell me what is the best way to achieve this?
Thanks in advance,
sen338
Member
498 Points
118 Posts
Re: How to get all elements under specific nodes
Jan 03, 2013 09:15 PM|LINK
XmlDocument input = new XmlDocument();
input.Load(
@"C:/testfile.xml");
XmlNodeList List = input.SelectNodes("/Entries/ExpenseEntry");
Get the xmlnode list which will give you all node under "/Entries/ExpenseEntry" then try to do what ever you want
niravparekh
Member
704 Points
427 Posts
Re: How to get all elements under specific nodes
Jan 04, 2013 02:00 PM|LINK
I tried this, somehow could not get the nodes.
Is there better way to do this using XDocument?
I mean where I can fill objects using Linq?
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: How to get all elements under specific nodes
Jan 05, 2013 12:41 AM|LINK
Hi,
1) For your first problem,you can really use XDocument to cope with the problem:
2) Remove "ns" and have a try this: