views:

707

answers:

3
public string GetArtistThumbnail(string artistName)
{
    var request =
        WebRequest.Create("http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist=" + artistName +
        "&api_key=" +
         APIKey) as HttpWebRequest;

    using (var response = request.GetResponse() as HttpWebResponse)
    {
        var ds = new DataSet();
        ds.ReadXml(response.GetResponseStream()); // <-- Exception is thrown here
    }

    return "";   
}

The above method basically retrieves an xml file from one of LastFM's API Services.

Now, I am facing the following exception when filling the dataset from the xml with the ReadXml method:

The table (artist) cannot be the child table to itself in nested relations.


Here is an example of an XML file that is being retrieved

Notice that there is a nested Artist in the XML file, and I obviously presume that that is the reason for the exception.


My question, how can I prevent this from happening? as regards the nested tables

+2  A: 

As far as I know, DataSets aren't meant to hold just about any type of XML. Do you really need a dataset in this case?

I suggest switching to linq 2 xml or XmlDocument to manipulate the results of the web service.

eglasius
Switched to using Linq2Xml with an Xdocument
Andreas Grech
+1  A: 

I think Freddy's answer has merit, but you might be able to define the DataSet schema manually before ReadXml is invoked, instead of relying on the xml to define the schema.

You could also try separating ReadXml from GetResponse and perform an xslt before ReadXml is invoked, i.e. make the schema compatible with a DataSet.

Long shot...turn off DataSet.EnforceConstraints

Si
A: 

try to use the http://ws.audioscrobbler.com/2.0/artist/iron+maiden/info.xml format

Cuneyt