XmlDocument.Load (string) to XmlDocument.Load (XmlReader) regression ?

  • Thread starter Thread starter Duvernet Vincent
  • Start date Start date
D

Duvernet Vincent

Guest
Hello,

I'm updating old code loading a simple XML file :

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<root>
<Percents>0.006 0.3893 </Percents>
<Interval>.083333</Interval>
</root>

This code is working :

XmlDocument docXML2 = new XmlDocument() { XmlResolver = null };
docXML2.Load(StoragePath);

Where StoragePath is the full path of file. It's a string.

Code analysis reports CA3075 unsafe override of Load() method.

I've updated the code to this :

XmlDocument docXML = new XmlDocument() { XmlResolver = null };
System.IO.StringReader sreader = new System.IO.StringReader(StoragePath);
using (XmlReader reader = XmlReader.Create(sreader, new XmlReaderSettings() { XmlResolver = null }))
{
docXML.Load(reader);

// other things
}

But now, the docXML.Load (reader) throw an exception :

System.Xml.XmlException : 'Données non valides au niveau racine. Ligne 1, position 1.'

I don't understand why ? :/

Can someone explain me ?

Thanks,

Vincent

Continue reading...
 
Back
Top