是否有一种方法可以使用Linq to XML来隔离和检索编码声明的属性?
<?xml version="1.0" encoding="UTF-8" ?>
Run Code Online (Sandbox Code Playgroud)
好像你可以initalize XDOC一个或者用的XElement整个文档或只是一个开始元素,但如何将你隔离这个标记......它没有名字......至少我不知道如果这样做.
您可以使用XDocument.Declaration属性:
XDocument document = XDocument.Load(xmlFilePath);
string encoding = document.Declaration.Encoding;
Run Code Online (Sandbox Code Playgroud)
作为奖励,您也可以获得版本号:
string version = document.Declaration.Version;
Run Code Online (Sandbox Code Playgroud)