Click here to Skip to main content
15,506,209 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am trying to parse my database feed data as XML, however on the client side I am keep getting this error:
C#
XML Parsing Error: not well-formed
Location: http://localhost:12736/Test.aspx
Line Number 7, Column 26:        

<Publication Date>29/04/2015 09:40:53</Publication Date>
------------------^


I have tried converting the datetime parameter 'ActivateDate' into string, but I am still getting the same error on the 'publication date' node. I have also tried looking online for a solution but I am still unable to solve this.

Here is my server code for further reference:
C#
Response.Clear();
         Response.ContentType = "text/xml";
         using (XmlTextWriter xml = new XmlTextWriter(Response.OutputStream, Encoding.UTF8))
         {
             xml.Formatting = Formatting.Indented;
             xml.Indentation = 4;
             xml.WriteStartDocument();
             xml.WriteStartElement("items");

             foreach (DataRow oFeedItem in dt.Rows)
             {

                // DateTime dtt = DateTime.Parse(oFeedItem["ACTIVEDATE"].ToString());

                 string dat = Convert.ToString(oFeedItem["ACTIVEDATE"].ToString());

                // dat.ToString("dd MMMM yyyy");
                 xml.WriteStartElement("Article");
                 xml.WriteElementString("title", oFeedItem["title"].ToString());
                 xml.WriteStartElement("description");
                 xml.WriteCData(oFeedItem["Body"].ToString());
                 xml.WriteEndElement();
                 xml.WriteElementString("categories", oFeedItem["categories"].ToString());
                 xml.WriteElementString("Publication Date", dat);
                 xml.WriteEndElement();
             }

             xml.WriteEndElement();
             xml.WriteEndDocument();
             xml.Flush();
             xml.Close();

             Response.End();

         }


Thank you
Posted

What can be unclear in this message? Of course, this is not XML at all. Not well-formed "wanna-be-XML" is not XML.

What could "Publication Date" be? If you think it could be an element/tag name, thing again: such name should not contain a blank space character. If you think "Date" could be an XML attribute, you would be wrong again: it should always have a value.
So, it could be
HTML
<PublicationTime>29/04/2015 09:40:53</PublicationTime>
<!-- or: -->
<Publication time="29/04/2015 09:40:53">...</Publication>
Note, I replaced pretty ridiculous word "Date" with "time", more adequate to your sample.

And please don't tell me that this is XML not yours but was given to you by someone. In this case, tell this person that it wasn't XML and ask for real XML. (Sorry if this part of my advice is redundant; I gave you only because too many inquirers behave this way, so it was just in case.)

After all, read any XML manual or specification and only then proceed with your work.

—SA
 
Share this answer
 
v3
Comments
Maciej Los 29-Apr-15 14:43pm    
Wanna-be-Maestro, 5!
Sergey Alexandrovich Kryukov 29-Apr-15 15:02pm    
Thank you, Maciej. :-)
—SA
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 29-Apr-15 15:02pm    
Useful links, a 5.
—SA
Maciej Los 29-Apr-15 15:04pm    
Thank you, Sergey ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900