c# - 捕获无效的 XML
问题描述
我有以下代码用于解析包含对象集合的 XML 字符串。如果无法解析,我想将任何给定对象的 XML 捕获为字符串。如果解析不正确,我想存储它并分析它。我不希望做出根本性的改变,但我不知道如何抓取无效的 XML 部分并捕获它。xmlReader.ReadOuterXml() 无法解析时抛出异常。提前致谢。
// we want to read each canonical item in the report from oracle separately
while (xmlReader.ReadToFollowing(ROOT_ELEMENT))
{
string itemXml = String.Empty;
try
{
// this gives us the whole segment of xml including the root element tag
itemXml = xmlReader.ReadOuterXml();
xmlReader.
T processedItem = default;
processedItem = reportMapper.Mapper(itemXml);
successfulItems.Add(new ProcessingResult<T>()
{
ProcessedItem = processedItem
});
}
解决方案
推荐阅读
- tinymce - 摆脱 TinyMCE 插入文本的多余元素
- reactjs - 如何为返回 ListItem 并具有多个道具的 React Native 组件编写单元测试。我正在努力这样做。有什么建议么?
- javascript - 对单个数组元素进行数学运算比在 forEach 循环中进行运算更快?
- mui-datatable - 如何摆脱表格顶部的 MUI-Datatable“选定行”面板
- testcomplete - 脚本执行的测试完成/Windows 版本问题
- c# - 如何在 C# 中将 DataTable 的内容保存到文本文件中
- ssas - 清除挂起的 SSAS 刷新进程
- java - 这些名字消失了arraylist,如何让它们留在原地?
- gcc - 链接描述文件 - 映射非连续内存
- dataframe - 基于joined-dataframe列是否加入多个数据框