反序列化XML文件 - XML文档中的错误(1,2)? [英] Deserialize an XML file - an error in XML document (1, 2)?
问题描述
大家好,
我正在尝试反序列化XML,但是我得到了这个例外:
XML文档(1,2)中存在错误。
InnerException消息
System.Xml.dll中发生了'System.InvalidOperationException'类型的异常,但未在用户代码中处理。 ..
我的尝试:
我搜索过stackoverflow论坛,谷歌和实施的建议,但我仍然得到相同的错误。请查看附带的xml文件的一些内容:
Hi Guys,
I'm trying to deserialize an XML, however i'm getting this exception:
There is an error in XML document (1,2).
InnerException Message
An exception of type 'System.InvalidOperationException' occurred in System.Xml.dll but was not handled in user code...
What I have tried:
I've searched the stackoverflow forum, google and implemented the advice, however I'm still getting the same error. Please find the enclosed some content of the xml file:
supplying XML as
<question xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<details>
<text>
<questiontext>Keyboard is an input or output device?
<Option answer="true">
<questionoption>input
</Option>
<Option answer="false">
<questionoption>output
</Option>
<Option answer="false">
<questionoption>both
</Option>
<Option answer="false">
<questionoption>none
</Option>
<mediaurl>
<url>~/Core/MediaFiles/Keyboard_27_02_38_19_27.JPG
XML.CS
using System;
using System.Xml.Serialization;
using TeTec.Business.Entities.Common;
using TeTec.Business.Entities.Model;
using TeTec.Utility.XML;
namespace TeTec.Business.Entities.Model.Question
{
[XmlRoot(ElementName = "Question")]
public class QuestionDetailsInfo : ICBO<int>
{
[XmlIgnore]
public int ID { get; set; }
[XmlIgnore]
public long QuestionID { get; set; }
[XmlIgnore]
public int QuestionLanguageID { get; set; }
private QuestionDetailsXMLInfo _questionDetailsXML = new QuestionDetailsXMLInfo();
[XmlIgnore]
public string DetailXml
{
get { return XMLSerializer.GetXML<questiondetailsxmlinfo>(_questionDetailsXML, true); }
set { if (!string.IsNullOrEmpty(value)) _questionDetailsXML = XMLSerializer.GetObject<questiondetailsxmlinfo>(value); }
}
[XmlElement(ElementName = "Details")]
public QuestionDetailsXMLInfo QuestionDetailsXML
{
get { return _questionDetailsXML; }
set { _questionDetailsXML = value; }
}
[XmlIgnore]
public bool? IsActive { get; set; }
[XmlIgnore]
public DateTime Updated { get; set; }
[XmlIgnore]
public int Identity => ID;
}
}
任何人都可以帮助我。
谢谢
anyone can please help me.
Thanks
推荐答案
您的文件不是XML文件。
Your file is not an XML file.
<text>
<questiontext>Keyboard is an input or output device?</questiontext>
</text>
<Option answer="true">
<questionoption>input</questionoption>
</Option>
<Option answer="false">
<questionoption>output</questionoption>
</Option>
<Option answer="false">
<questionoption>both</questionoption>
</Option>
<Option answer="false">
<questionoption>none</questionoption>
</Option>
只是修正的一部分使您的文件成为XML。
Just a part of the corrections to make your file an XML.
这篇关于反序列化XML文件 - XML文档中的错误(1,2)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!