Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: xml parsing

From: Martin Honnen <mahotrash@-----.-->
To: 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/


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent