Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
369 views
in Technique[技术] by (71.8m points)

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

Hi iam 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 is happing

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...