Quantcast
Channel: XML, System.Xml, MSXML and XmlLite forum
Viewing all articles
Browse latest Browse all 935

xelement error - This operation would create an incorrectly structured document.

$
0
0

Hi, 

I am trying to iterate the article and all its descendent's nodes, but i am currently getting exception on the line of code:

exception --> This operation would create an incorrectly structured document.

code line -->  xDoc.Add(article);

I tried changing the first node but I cannot get this error to resolve.  Please advise.  Thank you

public  string createArticleALL()
        {

            XDocument xDoc = new XDocument(new XElement("Root"));

            using (....))
            {
                con.Open();
                ....
                {
                    XElement article;
                    SqlDataReader reader = command.ExecuteReader();
                    while (reader.Read())
                    {

						article = new XElement("article");

                        article.Add(new XElement("status", "Approved"));

                        string title;
                        article.Add(new XElement("title", title = reader.GetString(0)));
                        article.Add(new XElement("subtitle", title));
                        article.Add(new XElement("synopsis", reader.GetString(4) + "..."));

                        string pub = reader["publication_id"].ToString();
                        string iss = reader["issue_id"].ToString();
                        string sid = reader["STORYID"].ToString();

                        string c = url(title, pub, iss, sid);
                        article.Add(new XElement("url", c));

                        article.Add(new XElement("display_date", DateTime.Today));

                        xDoc.Add(article);

                    }
                }
            }
            return xDoc.ToString();

        }


Viewing all articles
Browse latest Browse all 935

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>