Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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
Posted
Updated 1-Jun-22 7:01am
v3
Comments
Dave Kreskowiak 27-Nov-16 12:03pm    
That's not an XML file. It's greatly malformed.

I'm assuming you have a closing tag for the root tag "question" and for the tags "details" an "text". You have no closing tags for any of your "questionoption" or "questiontext" tags, nor that "ur" tag.

Your file is not an XML file.
HTML
<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>

Just a part of the corrections to make your file an XML.
 
Share this answer
 
Comments
abdul subhan mohammed 28-Nov-16 0:31am    
i have added xml class, could u plz check.
In your class, you should add the namespace attribute as follows:

[XmlRoot(ElementName = "Question", Namespace = "http://www.w3.org/2001/XMLSchema")]
 
Share this answer
 

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