Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries >Thread Prev - Re: xml parsing >Thread Next - Re: xml parsing Re: xml parsingTo: NULL Date: 5/14/2008 6:29:00 PM
beppe85 wrote:
> Following your advice i've tried with this:
>
> IEnumerable<Customer> DisplayQuery(string xmlContent)
> {
> XNamespace xmlns = "http://www.w3.org/2005/Atom";
> XDocument xml = XDocument.Parse(xmlContent);
> var customers = from customer in xml.Descendants(xmlns +
> "entry")
> select new Customer
> {
> SalesOrderID =
> (int)customer.Attribute(xmlns + "SalesOrderID"),
> Nome =
> (string)customer.Attribute(xmlns + "Nome"),
The entry elements in an Atom feed do not have any attributes named
SalesOrderID or Nome. I think what you are looking for with your code is
the content child elements which then has child elements of that name e.g.
XNamespace atom = "http://www.w3.org/2005/Atom";
XNamespace ads = "http://schemas.microsoft.com/ado/2007/08/dataweb";
IEnumerable<Customer> DisplayQuery(string xmlContent)
{
XNamespace atom = "http://www.w3.org/2005/Atom";
XNamespace ads = "http://schemas.microsoft.com/ado/2007/08/dataweb";
XDocument xml = XDocument.Parse(xmlContent);
var customers = from entry in xml.Descendants(atom +
"entry")
select new Customer
{
SalesOrderID =
(int)entry.Element(atom + "content").Element(ads + "SalesOrderID"),
Nome =
(string)entry.Element(atom + "content").Element(ads + "Nome"),
and so on for the other elements.
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
