查看原始的MSDN示例:
http://msdn.microsoft.com/en-us/library/ms172454.aspx
ValidationEventHandler的ValidationEventArgs参数具有Exception.LineNumber:
private void SchemaValidationEventHandler(object sender, ValidationEventArgs e) {
Console.WriteLine("XML {0}: {1} (Line {2})",
e.Severity,
e.Message,
e.Exception.LineNumber);
}
Run Code Online (Sandbox Code Playgroud)
由于@chris-watts 建议再次发布我的评论作为答案。这里是。
如果文档加载了适当的标志,则该文档只有行号信息:
var opts = LoadOptions.PreserveWhitespace
| LoadOptions.SetLineInfo;
XDocument doc = XDocument.Load(fileStream, opts);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7470 次 |
| 最近记录: |