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/13/2008 10:40:00 AM On 11 Mag, 09:13, "Joe Fawcett" <joefawc...@newsgroup.nospam> wrote:
> "beppe85" <beppeaiell...@libero.it> 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=3DCognome"
>
> > following the instruction provided there:
> >http://weblogs.asp.net/scottgu/pages/silverlight-tutorial-part-3-usin...
> > 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
>
> 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.htmlespecially numbers 13 & 23.
> For LINQ applicable code see:http://weblogs.asp.net/scottgu/archive/2007/0=
8/07/using-linq-to-xml-a...
>
> --
>
> Joe Fawcett (MVP - XML)http://joe.fawcett.name
Following your advice i've tried with this:
IEnumerable<Customer> DisplayQuery(string xmlContent)
{
XNamespace xmlns =3D "http://www.w3.org/2005/Atom";
XDocument xml =3D XDocument.Parse(xmlContent);
var customers =3D from customer in xml.Descendants(xmlns +
"entry")
select new Customer
{
SalesOrderID =3D
(int)customer.Attribute(xmlns + "SalesOrderID"),
Nome =3D
(string)customer.Attribute(xmlns + "Nome"),
Cognome =3D
(string)customer.Attribute(xmlns + "Cognome"),
Indirizzo =3D
(string)customer.Attribute(xmlns + "Indirizzo"),
Citt=E0 =3D
(string)customer.Attribute(xmlns + "Citt=E0"),
Paese =3D
(string)customer.Attribute(xmlns + "Paese"),
Zip =3D (string)customer.Attribute(xmlns
+ "Zip"),
Telefono =3D
(string)customer.Attribute(xmlns + "Telefono")
};
return customers;
}
but it doesn't work either. i've put a breakpoint to the function and
when during the execution it arrives at the point "var customers =3D
from customer in xml.Descendants(xmlns + "entry")" it skips directly
to the return statement with an empty collection. is the namespace
the right one?
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
