Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The XmlReader state should be Interactive

Tags:

c#

linq-to-xml

I am trying to load an xml into an XDocument object.

public void ValidateRules(XmlReader xml)
{
    xml.MoveToContent();
    XDocument xDoc = new XDocument();
    xDoc = XDocument.Load(xml);
}

But, I keep getting the error "The XmlReader state should be Interactive". I searched for a work around for this, and added MoveToContent() method at the top(as it was mentioned that, this will change the ReadState to Interactive), but it didn't work. ReadState is read-only and I cannot change the value.

What can be the problem over here?

P.S. The XML file which I am trying to load has a DTD reference. It is present at the same path as the XML. Do not know whether this is of any significance.

like image 487
Ashwin Venkatesh Prabhu Avatar asked Sep 30 '22 22:09

Ashwin Venkatesh Prabhu


1 Answers

XML data is null attempt read via reader. reader's ReadState situation will be Initial or EndOfFile (https://msdn.microsoft.com/en-us/library/fxtcxd31.aspx)

public void ValidateRules(XmlReader reader)
{
    XDocument xDoc = XDocument.Load(reader);
}
like image 52
Developer33 Avatar answered Nov 15 '22 07:11

Developer33