XML解析错误:格式不正确 [英] XML Parsing Error: not well-formed

查看:689
本文介绍了XML解析错误:格式不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将我的数据库提要数据解析为XML,但是在客户端我不断收到此错误:

I am trying to parse my database feed data as XML, however on the client side I am keep getting this error:

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>
------------------^





我尝试将datetime参数'ActivateDate'转换为字符串,但我在发布日期仍然遇到相同的错误节点。我也试过在线寻找解决方案,但我仍然无法解决这个问题。



这是我的服务器代码供进一步参考:



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:

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

推荐答案

这条消息中有什么不清楚的地方?当然,这根本不是XML。格式不好想成为XML不是XML。



发布日期是什么?如果您认为它可能是元素/标记名称,则再次发生:此名称不应包含空格字符。如果您认为Date可能是XML属性,那么您将再次出错:它应该总是有一个值。

所以,它可能是

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
<PublicationTime>29/04/2015 09:40:53</PublicationTime>
<!-- or: -->
<Publication time="29/04/2015 09:40:53">...</Publication>

注意,我用时间替换了非常荒谬的单词Date,更适合您的样本。



请不要告诉我这不是你的XML,而是某人给你的。在这种情况下,告诉这个人它不是XML并要求真正的XML。 (对不起,如果我的建议的这一部分是多余的;我只是因为太多的询问者这样做而给你,所以这是以防万一。)



毕竟,阅读任何XML手册或规范,然后继续工作。



-SA

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


我建议回到基础: XML元素,属性和类型(XML设计器) [ ^ ]



命名元素的一些规则 [ ^ ]

XML元素和属性名称指南 [ ^ ]
I'd suggest to go back to basics: XML Elements, Attributes, and Types (XML Designer) [^]

Some Rules for Naming Elements[^]
XML Element and Attribute Name Guidelines[^]


这篇关于XML解析错误:格式不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆