Is there a way with Linq to XML to isolate and retrieve the attributes of the encoding declaration?
<?xml version="1.0" encoding="UTF-8" ?>
It seems like you can initalize an XDoc or XElement with the whole document or just a starting element, but how would you Isolate this tag... it doesnt have a name... or at least I dont know if it does.
You can use the XDocument.Declaration Property:
XDocument document = XDocument.Load(xmlFilePath);
string encoding = document.Declaration.Encoding;
As a bonus, you can get the version number too:
string version = document.Declaration.Version;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With