简体   繁体   English

xml文档中有错误(2 2)xmlns =“

[英]there is an error in xml document (2 2) xmlns='' was not expected

The error I am getting is all over stackoverflow answered again and again, I have tried few changes in the code but not able to remove the error. 我遇到的错误遍及整个stackoverflow,一次又一次地回答,我尝试对代码进行少量更改,但无法消除该错误。 here is the class I am using for serialization and deserialization. 这是我用于序列化和反序列化的类。 Please have a look at it. 请看看。

I don't understand terms like XMLroot, XML element and namespace. 我不了解XMLroot,XML元素和名称空间之类的术语。 So please answer accordingly, like what namespace should I give, what could be the XML root. 因此,请相应地回答,例如我应该提供什么名称空间,它应该是XML根。

If u can edit it, it would be great: 如果您可以编辑它,那就太好了:

namespace tudumo9
{

  public class data
  {
    public string project_name;
    public string note_text;
    public string tag_text;
    public DateTime start_date;
    public DateTime due_date;
    public string action;

    public  data(){}

  }
}

My XML: 我的XML:

<?xml version="1.0"?>
<ArrayOfData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
             xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <data>
    <project_name>p1</project_name>
    <tag_text>tagged</tag_text>
    <start_date>0001-01-01T00:00:00</start_date>
    <due_date>0001-01-01T00:00:00</due_date>
    <action>Action</action>
  </data>
</ArrayOfData>

Try this 尝试这个

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Xml;
using System.Xml.Serialization;


namespace ConsoleApplication25
{
    class Program
    {
        const string FILENAME = @"c:\temp\test.xml";
        static void Main(string[] args)
        {
            XmlSerializer xs = new XmlSerializer(typeof(ArrayOfData));
            XmlTextReader reader = new XmlTextReader(FILENAME);
            ArrayOfData newArrayOfData = (ArrayOfData)xs.Deserialize(reader);

        }

    }
    [XmlRoot("ArrayOfData")]
    public class ArrayOfData
    {
        [XmlElement("data")]
        public List<data> c_Data { get; set; }
    }

    [XmlRoot("data")]
    public class data
    {
        [XmlElement("project_name")]
        public string project_name { get; set; }
        [XmlElement("note_text")]
        public string note_text { get; set; }
        [XmlElement("tag_text")]
        public string tag_text { get; set; }
        [XmlElement("start_date")]
        public DateTime start_date { get; set; }
        [XmlElement("due_date")]
        public DateTime due_date { get; set; }
        [XmlElement("action")]
        public string action { get; set; }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 xmlns=&#39;&#39;&gt; 不是预期的。 - XML 文档中存在错误 (2, 2) - xmlns=''> was not expected. - There is an error in XML document (2, 2) xmlns=&#39;&#39;&gt; 不是预期的。 - DeserializeXml to object 时 XML 文档 (2, 2) 中存在错误 - xmlns=''> was not expected. - There is an error in XML document (2, 2) while DeserializeXml to object 将 Xml 反序列化为对象时出错 - 不需要 xmlns=&#39;&#39; - Error Deserializing Xml to Object - xmlns='' was not expected 从 XML 文档中选择一个值,错误为<SalesDataOrderInterface xmlns=''>没想到 - Select a value from XML document, errors with <SalesDataOrderInterface xmlns=''> was not expected 无法反序列化XML文档(内部例外: - Unable to Deserialize XML document (Inner Exception: <ArrayOfString xmlns ="> was not expected) XML反序列化-不需要xmlns - XML Deserialization - xmlns not expected xml文档(1、2)中的错误……未预期到 - Error in xml document (1, 2) … was not expected 将XML响应转换为C#对象-错误(不期望xmlns =&#39;&#39;&gt;) - Converting XML response to C# object - Error ( xmlns=''> was not expected ) C# 反序列化 XML 为 Model Class 错误 -<xmlns=“”> 没有预期</xmlns=“”> - C# Deserialize XML to Model Class error - <xmlns=“”> Not expected XML反序列化 <rss xmlns=''> 没想到 - XML Deserialize <rss xmlns=''> was not expected
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM