Cannot add a nested relation or an element column to a table containing a SimpleContent column

前端 未结 4 1340
执念已碎
执念已碎 2020-12-04 01:55

Hi iam write this code

\"

 XmlTextReader read = new XmlTextReader(\"http://msdn.microsoft.com/rss.xml\");
        DataSet ds = new DataSet();
                


        
相关标签:
4条回答
  • 2020-12-04 02:35

    Your problem is you have the same element name with a different structure somewhere in the document.

    So, for example, if you have

    <Item>Bicycle</Item>
    

    and later in the document you have

    <Item Type="Sports"><Name>Bicycle</Name></Item>
    

    The XSD will fail to generate a proper schema for the second Item attribute structure because it's already defined Item as a SimpleContent column based on the earlier declaration.

    The solution is to (naturally) avoid using the same element name for different structures within your XML. Obviously in your case that's kind of inconvenient since Microsoft owns the XML in question (hypothetically, since the comment from Deni indicates this site no longer exists.) You'd have to use XMLWriter or some variant to swap out the name of the offending element for something unique.

    0 讨论(0)
  • 2020-12-04 02:35

    I think this error will display when you are trying to ReadXml from Responsetext from service calls. In this Case Just Fetch the necessary node attribute which you require in outerxml format . Those who are not neccessary skip that element.

    E.g

     var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
                    XmlDocument doc = new XmlDocument();
                    DataSet ds = new DataSet();
                    doc.LoadXml(responseString);
    
                    foreach (XmlNode node in doc.SelectNodes("result/records"))
                    {
                        doc = new XmlDocument();
                        doc.LoadXml(node.OuterXml.ToString());
                    }
    
                    using (XmlReader reader = new XmlNodeReader(doc.DocumentElement))
                    {
                        ds.ReadXml(reader);
                        reader.Close();
                    }
    

    In Above example I want only 'records' node in response stream . So that I am fetching only that & given to dataset for processing.

    I hope it helps!!!!!!!!!!!!!!!!!!!!!!!!!!!

    0 讨论(0)
  • 2020-12-04 02:42

    In my case this error appeared on WCF client's side. On WCF server's side it was caused by missing SQL SELECT permission on a function -- System.Data.SqlClient.SqlException.

    WCF client trying to deserialize a dataset, which was obviously not there, kept displaying "Cannot add a SimpleContent..." error. I would not call it a misleading message, but rather one that must be interpreted properly.

    0 讨论(0)
  • 2020-12-04 02:45

    It looks like your xml contains an element which has both text children (simple content) and other element children.

    DataSet does not allow a table to have both simple content columns as well as element columns.

    See http://msdn2.microsoft.com/en-us/library/zx8h06sz.aspx

    0 讨论(0)
提交回复
热议问题