0

I'm using ReadXML from DataSet to read a XML document without any schema. There are 2 'duration' tags each in a different parent tag. That is why ReadXML complaining:

System.Data.DataException: The table 'duration' is already allocated as a child of another table 'video'. Cannot set table 'asset' as parent table.

This is the XML doc it's trying to read:

http://pastebin.com/39VStzcw

(I couldn't paste XML here properly)

This is the C# code that i use:

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

        using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())  
        {  
            resultDs.ReadXml(response.GetResponseStream());  
        }  
        return resultDs;

Is there any other way I can read this XML doc?

Please enlight,

Simplecode

RoundOutTooSoon
  • 9,821
  • 8
  • 35
  • 52

1 Answers1

0

There are many ways to read XML, depends on your personal taste. Here are some examples:

I tried reading with DataSet.ReadXml and it creates tables fine without any problem. Only difference is, I was accessing XML from local computer, not through web like you:

const string xmlPath = @"XmlFile.xml";
var ds = new DataSet();
var fs = new FileStream(xmlPath, FileMode.Open);

try
{
    ds.ReadXml(fs);
    foreach (DataTable table in ds.Tables)
    {
        Console.WriteLine("Table name: " + table.TableName);
    }
    Console.WriteLine("Test");
}
catch (Exception e)
{
    Console.WriteLine(e.Message);
}
finally
{
    fs.Close();
}
Jernej Jerin
  • 3,179
  • 9
  • 37
  • 53