Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
XML
data.xmlanalysis
mappoint.webservice
msf
msxml-webrelease
netmyservices.sdk
passport.sdk
soap
soapsdk
uddi.general
uddi.programming
uddi.specification
xml
xmlsqlwebrelease
xsl
  
 
date: Sat, 10 May 2008 07:37:03 -0700 (PDT),    group: microsoft.public.xml        back       


xml parsing   
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왩;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왩;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왩;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왩;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왩;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
date: Sat, 10 May 2008 07:37:03 -0700 (PDT)   author:   beppe85

Re: xml parsing   
"beppe85"  wrote in message 
news:4e9266b1-5f1d-439c-9cfc-eb5dd4d1ccec@34g2000hsf.googlegroups.com...
> 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
date: Sun, 11 May 2008 08:13:32 +0100   author:   Joe Fawcett am

Re: xml parsing   
"Joe Fawcett" <joefawcett@newsgroup.nospam> wrote in message 
news:7968DB54-2CCD-4FA1-A168-715723268EB9@microsoft.com...
>
>
> "beppe85"  wrote in message 
> news:4e9266b1-5f1d-439c-9cfc-eb5dd4d1ccec@34g2000hsf.googlegroups.com...
>> 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
And this: http://msdn.microsoft.com/en-us/library/bb669152.aspx

-- 

Joe Fawcett (MVP - XML)
http://joe.fawcett.name
date: Sun, 11 May 2008 09:17:20 +0100   author:   Joe Fawcett am

Re: xml parsing   
On 11 Mag, 09:13, "Joe Fawcett" <joefawc...@newsgroup.nospam> wrote:
> "beppe85"  wrote in message
>
> news:4e9266b1-5f1d-439c-9cfc-eb5dd4d1ccec@34g2000hsf.googlegroups.com...
>
> > 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-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="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왩;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왩;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왩;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왩;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왩;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.htmlespecially numbers 13 & 23.
> For LINQ applicable code see:http://weblogs.asp.net/scottgu/archive/2007/08/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 = "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"),
                                Cognome =
(string)customer.Attribute(xmlns  "Cognome"),
                                Indirizzo =
(string)customer.Attribute(xmlns  "Indirizzo"),
                                Città =
(string)customer.Attribute(xmlns  "Città"),
                                Paese =
(string)customer.Attribute(xmlns  "Paese"),
                                Zip = (string)customer.Attribute(xmlns
 "Zip"),
                                Telefono =
(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 =
from customer in xml.Descendants(xmlns  "entry")" it skips directly
to the return statement with an  empty collection. is the namespace
the right one?
date: Tue, 13 May 2008 10:39:56 -0700 (PDT)   author:   beppe85

Re: xml parsing   
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/
date: Wed, 14 May 2008 18:29:28 +0200   author:   Martin Honnen

Re: xml parsing   
On 14 Mag, 18:29, Martin Honnen  wrote:
> 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/

IT WORKS! THANK YOU VERY MUCH! Is it  possible to generalize the
process so i could for example display the content of another table
and not only Customer?
date: Thu, 15 May 2008 12:14:52 -0700 (PDT)   author:   beppe85

Re: xml parsing   
beppe85 wrote:

> Is it  possible to generalize the
> process so i could for example display the content of another table
> and not only Customer?

I can help writing the LINQ to XML query if needed but I am currently 
not familiar with "Astoria" so you need to find a newsgroup or forum 
dealing with Astoria questions and discussions if "generalize the 
process" refers to Astoria.

-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/
date: Fri, 16 May 2008 14:14:36 +0200   author:   Martin Honnen

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us