Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries >Thread Prev - xml parsing >Thread Next - Re: xml parsing Re: xml parsingTo: NULL Date: 5/11/2008 8:14:00 AM
"beppe85" <beppeaiello85@l...> wrote in message
news:4e9266b1-5f1d-439c-9cfc-eb5dd4d1ccec@3......
> Hi, i've a problem with my astoria project.
> i've created a db named SalesOrderCompany and from this the entity
> model of the db that it's used in the web service of the astoria
> project. i would like to display in a silverlight datagrid thr result
> of the query (select customer):
> "http://localhost:50527/SalesCompanyService.svc/Customer?
> $orderby=Cognome"
>
> following the instruction provided there:
> http://weblogs.asp.net/scottgu/pages/silverlight-tutorial-part-3-using-networking-to-retrieve-data-and-populate-a-datagrid.aspx
> i've associated a silverlight project to the "astoria" but in order to
> set the item source of the datagrid i've to parse the following xml:
>
> <feed xml:base="http://localhost:50527/SalesCompanyService.svc/"
> xmlns:ads="http://schemas.microsoft.com/ado/2007/08/dataweb"
> xmlns:adsm="http://schemas.microsoft.com/ado/2007/08/dataweb/metadata"
> xmlns="http://www.w3.org/2005/Atom">
> <id>http://localhost:50527/SalesCompanyService.svc/Customer</id>
> <updated />
> <title>Customer</title>
> <link rel="self" href="Customer" title="Customer" />
> <entry adsm:type="SalesCompanyModel.Customer">
> <id>http://localhost:50527/SalesCompanyService.svc/Customer(4)</
> id>
> <updated />
> <title />
> <author>
> <name />
> </author>
> <link rel="edit" href="Customer(4)" title="Customer" />
> <content type="application/xml">
> <ads:SalesOrderID adsm:type="Int32">4</ads:SalesOrderID>
> <ads:Nome>Simone</ads:Nome>
> <ads:Cognome>Arcangeli</ads:Cognome>
> <ads:Indirizzo>Viale Pelleia</ads:Indirizzo>
> <ads:Città>Genova</ads:Città>
> <ads:Paese>Italia</ads:Paese>
> <ads:Zip>16147</ads:Zip>
> <ads:Telefono>3380980789</ads:Telefono>
> </content>
> <link rel="related" title="SalesOrder" href="Customer(4)/
> SalesOrder" type="application/atom+xml;type=entry" />
> </entry>
> <entry adsm:type="SalesCompanyModel.Customer">
> <id>http://localhost:50527/SalesCompanyService.svc/Customer(0)</
> id>
> <updated />
> <title />
> <author>
> <name />
> </author>
> <link rel="edit" href="Customer(0)" title="Customer" />
> <content type="application/xml">
> <ads:SalesOrderID adsm:type="Int32">0</ads:SalesOrderID>
> <ads:Nome>Giovanni</ads:Nome>
> <ads:Cognome>Napoli</ads:Cognome>
> <ads:Indirizzo>Via Capelloni 6</ads:Indirizzo>
> <ads:Città>Sanremo</ads:Città>
> <ads:Paese>Italia</ads:Paese>
> <ads:Zip>23456</ads:Zip>
> <ads:Telefono>3338478921</ads:Telefono>
> </content>
> <link rel="related" title="SalesOrder" href="Customer(0)/
> SalesOrder" type="application/atom+xml;type=entry" />
> </entry>
> <entry adsm:type="SalesCompanyModel.Customer">
> <id>http://localhost:50527/SalesCompanyService.svc/Customer(2)</
> id>
> <updated />
> <title />
> <author>
> <name />
> </author>
> <link rel="edit" href="Customer(2)" title="Customer" />
> <content type="application/xml">
> <ads:SalesOrderID adsm:type="Int32">2</ads:SalesOrderID>
> <ads:Nome>Andrea</ads:Nome>
> <ads:Cognome>Pepato</ads:Cognome>
> <ads:Indirizzo>Piazza Fattoni 3</ads:Indirizzo>
> <ads:Città>Genova</ads:Città>
> <ads:Paese>Italia</ads:Paese>
> <ads:Zip>16147</ads:Zip>
> <ads:Telefono>3459098098</ads:Telefono>
> </content>
> <link rel="related" title="SalesOrder" href="Customer(2)/
> SalesOrder" type="application/atom+xml;type=entry" />
> </entry>
> <entry adsm:type="SalesCompanyModel.Customer">
> <id>http://localhost:50527/SalesCompanyService.svc/Customer(1)</
> id>
> <updated />
> <title />
> <author>
> <name />
> </author>
> <link rel="edit" href="Customer(1)" title="Customer" />
> <content type="application/xml">
> <ads:SalesOrderID adsm:type="Int32">1</ads:SalesOrderID>
> <ads:Nome>Mattia</ads:Nome>
> <ads:Cognome>Pini</ads:Cognome>
> <ads:Indirizzo>Via Zorco 12</ads:Indirizzo>
> <ads:Città>Amsterdam</ads:Città>
> <ads:Paese>Olanda</ads:Paese>
> <ads:Zip>67899</ads:Zip>
> <ads:Telefono>3456780098</ads:Telefono>
> </content>
> <link rel="related" title="SalesOrder" href="Customer(1)/
> SalesOrder" type="application/atom+xml;type=entry" />
> </entry>
> <entry adsm:type="SalesCompanyModel.Customer">
> <id>http://localhost:50527/SalesCompanyService.svc/Customer(3)</
> id>
> <updated />
> <title />
> <author>
> <name />
> </author>
> <link rel="edit" href="Customer(3)" title="Customer" />
> <content type="application/xml">
> <ads:SalesOrderID adsm:type="Int32">3</ads:SalesOrderID>
> <ads:Nome>Fabrizio</ads:Nome>
> <ads:Cognome>Sossan</ads:Cognome>
> <ads:Indirizzo>Via Belin</ads:Indirizzo>
> <ads:Città>Milano</ads:Città>
> <ads:Paese>Italia</ads:Paese>
> <ads:Zip>16456</ads:Zip>
> <ads:Telefono>3456789028</ads:Telefono>
> </content>
> <link rel="related" title="SalesOrder" href="Customer(3)/
> SalesOrder" type="application/atom+xml;type=entry" />
> </entry>
> </feed>
>
> i've tried with this:
> (the string xmlContent contains the xml above)
> System.Collections.IEnumerable retrieveData(string xmlContent)
> {
> XDocument xml = XDocument.Parse(xmlContent);
>
> var customers = from customer in
> xml.Descendants("Customer")
> select new Customer
> {
> SalesOrderID =
> (int)customer.Attribute("SalesOrderID"),
> Nome =
> (string)customer.Attribute("Nome"),
> Cognome =
> (string)customer.Attribute("Cognome"),
> Indirizzo =
> (string)customer.Attribute("Indirizzo"),
> Città =
> (string)customer.Attribute("Città"),
> Paese =
> (string)customer.Attribute("Paese"),
> Zip =
> (string)customer.Attribute("Zip"),
> Telefono =
> (string)customer.Attribute("Telefono")
> };
>
> return customers;
>
> }
> but it doesn't seem to work. i'm not an expert about xml so i can't
> think of another method to retrieve the customers from this xml...Any
> help will be greatly appreciated
Basically the problem is a common one, namespaces and particularly the
default namespace. See here for details:
http://www.dpawson.co.uk/xsl/sect2/N5536.html especially numbers 13 & 23.
For LINQ applicable code see:
http://weblogs.asp.net/scottgu/archive/2007/08/07/using-linq-to-xml-and-how-to-build-a-custom-rss-feed-reader-with-it.aspx
--
Joe Fawcett (MVP - XML)
http://joe.fawcett.name
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
