jeudi 9 mars 2017

Reading an utf8 encoded xml file in C#: the stream solution

All is in the title.
using (Stream str = System.IO.File.Open(@"fileName.xml", FileMode.Open)) {
    XmlReaderSettings p = new XmlReaderSettings {
        DtdProcessing = DtdProcessing.Parse
    };
    using (XmlReader xr = XmlReader.Create(new StreamReader(str, Encoding.UTF8), p)) {
        XDocument xDoc = XDocument.Load(xr);
        // or
        //XElement xEl = XElement.Load(xr);
   
        //do your stuff here.
    }
}

Aucun commentaire:

Enregistrer un commentaire