Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries [Thread Prev] >Thread Next - Re: xml parsing xml parsingTo: NULL Date: 5/10/2008 7:37:00 AM 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=3DCognome"
following the instruction provided there:
http://weblogs.asp.net/scottgu/pages/silverlight-tutorial-part-3-using-netwo=
rking-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=3D"http://localhost:50527/SalesCompanyService.svc/"
xmlns:ads=3D"http://schemas.microsoft.com/ado/2007/08/dataweb"
xmlns:adsm=3D"http://schemas.microsoft.com/ado/2007/08/dataweb/metadata"
xmlns=3D"http://www.w3.org/2005/Atom">
<id>http://localhost:50527/SalesCompanyService.svc/Customer</id>
<updated />
<title>Customer</title>
<link rel=3D"self" href=3D"Customer" title=3D"Customer" />
<entry adsm:type=3D"SalesCompanyModel.Customer">
<id>http://localhost:50527/SalesCompanyService.svc/Customer(4)</
id>
<updated />
<title />
<author>
<name />
</author>
<link rel=3D"edit" href=3D"Customer(4)" title=3D"Customer" />
<content type=3D"application/xml">
<ads:SalesOrderID adsm:type=3D"Int32">4</ads:SalesOrderID>
<ads:Nome>Simone</ads:Nome>
<ads:Cognome>Arcangeli</ads:Cognome>
<ads:Indirizzo>Viale Pelleia</ads:Indirizzo>
<ads:Citt=E0>Genova</ads:Citt=E0>
<ads:Paese>Italia</ads:Paese>
<ads:Zip>16147</ads:Zip>
<ads:Telefono>3380980789</ads:Telefono>
</content>
<link rel=3D"related" title=3D"SalesOrder" href=3D"Customer(4)/
SalesOrder" type=3D"application/atom+xml;type=3Dentry" />
</entry>
<entry adsm:type=3D"SalesCompanyModel.Customer">
<id>http://localhost:50527/SalesCompanyService.svc/Customer(0)</
id>
<updated />
<title />
<author>
<name />
</author>
<link rel=3D"edit" href=3D"Customer(0)" title=3D"Customer" />
<content type=3D"application/xml">
<ads:SalesOrderID adsm:type=3D"Int32">0</ads:SalesOrderID>
<ads:Nome>Giovanni</ads:Nome>
<ads:Cognome>Napoli</ads:Cognome>
<ads:Indirizzo>Via Capelloni 6</ads:Indirizzo>
<ads:Citt=E0>Sanremo</ads:Citt=E0>
<ads:Paese>Italia</ads:Paese>
<ads:Zip>23456</ads:Zip>
<ads:Telefono>3338478921</ads:Telefono>
</content>
<link rel=3D"related" title=3D"SalesOrder" href=3D"Customer(0)/
SalesOrder" type=3D"application/atom+xml;type=3Dentry" />
</entry>
<entry adsm:type=3D"SalesCompanyModel.Customer">
<id>http://localhost:50527/SalesCompanyService.svc/Customer(2)</
id>
<updated />
<title />
<author>
<name />
</author>
<link rel=3D"edit" href=3D"Customer(2)" title=3D"Customer" />
<content type=3D"application/xml">
<ads:SalesOrderID adsm:type=3D"Int32">2</ads:SalesOrderID>
<ads:Nome>Andrea</ads:Nome>
<ads:Cognome>Pepato</ads:Cognome>
<ads:Indirizzo>Piazza Fattoni 3</ads:Indirizzo>
<ads:Citt=E0>Genova</ads:Citt=E0>
<ads:Paese>Italia</ads:Paese>
<ads:Zip>16147</ads:Zip>
<ads:Telefono>3459098098</ads:Telefono>
</content>
<link rel=3D"related" title=3D"SalesOrder" href=3D"Customer(2)/
SalesOrder" type=3D"application/atom+xml;type=3Dentry" />
</entry>
<entry adsm:type=3D"SalesCompanyModel.Customer">
<id>http://localhost:50527/SalesCompanyService.svc/Customer(1)</
id>
<updated />
<title />
<author>
<name />
</author>
<link rel=3D"edit" href=3D"Customer(1)" title=3D"Customer" />
<content type=3D"application/xml">
<ads:SalesOrderID adsm:type=3D"Int32">1</ads:SalesOrderID>
<ads:Nome>Mattia</ads:Nome>
<ads:Cognome>Pini</ads:Cognome>
<ads:Indirizzo>Via Zorco 12</ads:Indirizzo>
<ads:Citt=E0>Amsterdam</ads:Citt=E0>
<ads:Paese>Olanda</ads:Paese>
<ads:Zip>67899</ads:Zip>
<ads:Telefono>3456780098</ads:Telefono>
</content>
<link rel=3D"related" title=3D"SalesOrder" href=3D"Customer(1)/
SalesOrder" type=3D"application/atom+xml;type=3Dentry" />
</entry>
<entry adsm:type=3D"SalesCompanyModel.Customer">
<id>http://localhost:50527/SalesCompanyService.svc/Customer(3)</
id>
<updated />
<title />
<author>
<name />
</author>
<link rel=3D"edit" href=3D"Customer(3)" title=3D"Customer" />
<content type=3D"application/xml">
<ads:SalesOrderID adsm:type=3D"Int32">3</ads:SalesOrderID>
<ads:Nome>Fabrizio</ads:Nome>
<ads:Cognome>Sossan</ads:Cognome>
<ads:Indirizzo>Via Belin</ads:Indirizzo>
<ads:Citt=E0>Milano</ads:Citt=E0>
<ads:Paese>Italia</ads:Paese>
<ads:Zip>16456</ads:Zip>
<ads:Telefono>3456789028</ads:Telefono>
</content>
<link rel=3D"related" title=3D"SalesOrder" href=3D"Customer(3)/
SalesOrder" type=3D"application/atom+xml;type=3Dentry" />
</entry>
</feed>
i've tried with this:
(the string xmlContent contains the xml above)
System.Collections.IEnumerable retrieveData(string xmlContent)
{
XDocument xml =3D XDocument.Parse(xmlContent);
var customers =3D from customer in
xml.Descendants("Customer")
select new Customer
{
SalesOrderID =3D
(int)customer.Attribute("SalesOrderID"),
Nome =3D
(string)customer.Attribute("Nome"),
Cognome =3D
(string)customer.Attribute("Cognome"),
Indirizzo =3D
(string)customer.Attribute("Indirizzo"),
Citt=E0 =3D
(string)customer.Attribute("Citt=E0"),
Paese =3D
(string)customer.Attribute("Paese"),
Zip =3D
(string)customer.Attribute("Zip"),
Telefono =3D
(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
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
