我正在使用以下行读取XML文档,该文档可能会或可能不会<!-- -->在我的XML文件顶部附近放置一些注释:
XDocument xe1 = XDocument.Load(filepath)
Run Code Online (Sandbox Code Playgroud)
我如何阅读评论并存储为字符串?
我在MS Visual Studio C#中这样做.
我知道有一些叫做"XComment"的东西,但我找不到一个简单的例子,它在读取XML时使用它(我只能找到创建新XML文件的例子).
-Adeena
max*_*xnk 14
使用此代码段获取XDocument中的所有注释:
var document = XDocument.Load("test.xml");
var comments = from node in document.Elements().DescendantNodesAndSelf()
where node.NodeType == XmlNodeType.Comment
select node as XComment;
Run Code Online (Sandbox Code Playgroud)
这只解析顶级评论:
var document = XDocument.Load("test.xml");
var comments = from node in document.Nodes()
where node.NodeType == XmlNodeType.Comment
select node as XComment;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2983 次 |
| 最近记录: |