I have this tables to DataSet, by I can't read other parameters by product id like photo or parameter, because dataset gives new table to. How to access to this parameters by id from dataset?
var result = (from p in XDocument.Load("xxx.xml").Descedants("product")
where p.Attribute("id").Value=="your value here"
select new
{
Addr = p.Element("photos").Element("photo").Attribute("addr).Value,
ParameterName = p.Element("parameters").Element("parameter").Attribute("name).Value
});
aidzas
0 Points
1 Post
C# how to read child elements like photo or parameter when i need to read by product id?
Feb 29, 2012 05:24 PM|LINK
hello, I have folowing xml document:
<products> <product id="1"> <photos> <photo addr="1.jpg" /> </photos> <parameters> <parameter name="a" /> </parameters> </product> <product id="2"> <photos> <photo addr="1.jpg" /> </photos> <parameters> <parameter name="n" /> </parameters> </product> </products>I have this tables to DataSet, by I can't read other parameters by product id like photo or parameter, because dataset gives new table to. How to access to this parameters by id from dataset?
kavita_khand...
Star
9767 Points
1930 Posts
Re: C# how to read child elements like photo or parameter when i need to read by product id?
Mar 01, 2012 09:53 AM|LINK
Do you want to search in XML document or inthe Dataset?
I would love to change the world, but they wont give me the source code.
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: C# how to read child elements like photo or parameter when i need to read by product id?
Mar 02, 2012 12:47 AM|LINK
Hello aidzas:)
I prefer to use XDocument(LINQ TO XML)——
var result = (from p in XDocument.Load("xxx.xml").Descedants("product") where p.Attribute("id").Value=="your value here" select new { Addr = p.Element("photos").Element("photo").Attribute("addr).Value, ParameterName = p.Element("parameters").Element("parameter").Attribute("name).Value });