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

Hi i will write this code

"

XmlTextReader read = new XmlTextReader("http://msdn.microsoft.com/rss.xml"); DataSet ds = new DataSet(); ds.ReadXml(read); ListView1.DataSource = ds.Tables[4]; ListView1.DataBind(); " 

and this error occurs hpping

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

+6
source share
4 answers

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

So for example, if you have

 <Item>Bicycle</Item> 

and then in the document you

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

XSD will not be able to create the correct schema for the second Item attribute structure, since it already defined the element as a SimpleContent column based on an earlier declaration.

The solution is to (naturally) avoid using the same element name for different structures in your XML. Obviously, this is inconvenient in your case, since Microsoft owns the XML in question (hypothetically, since a comment from Deni indicates that this site no longer exists.) You will have to use XMLWriter or some other option to change the name of the violating element for something something unique.

+8
source

It looks like your xml contains an element that has both text files (simple content) and other child elements.

A DataSet does not allow a table to have both simple content columns and element columns.

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

0
source

In my case, this error appeared on the WCF client side. On the WCF server side, this was caused by a lack of SQL SELECT permission for the function System.Data.SqlClient.SqlException.

A WCF client trying to deserialize a dataset that obviously wasnโ€™t displaying the message "Unable to add SimpleContent ...". I would not call this a misleading message, but rather what should be correctly interpreted.

0
source

I think this error will be displayed when trying ReadXml from a Responsetext from service calls. In this case, just select the required node attribute, which is required in outerxml format. Those who do not necessarily miss this item.

For instance,

  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 the above example, I want only the "records" of the node in the response stream. So I only extract this and pass the data set for processing.

Hope this helps !!!!!!!!!!!!!!!!!!!!!!!!!!!!!

0
source

Source: https://habr.com/ru/post/897903/


All Articles