(client) feat:添加查找指定文档类型函数
This commit is contained in:
@ -1,4 +1,6 @@
|
|||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Xml;
|
||||||
|
|
||||||
namespace Data
|
namespace Data
|
||||||
{
|
{
|
||||||
@ -16,7 +18,39 @@ namespace Data
|
|||||||
|
|
||||||
public void LoadPack(string packPath)
|
public void LoadPack(string packPath)
|
||||||
{
|
{
|
||||||
|
var packDatas=Utils.FileHandler.LoadXmlFromPath(packPath);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 从 List<c>XmlDocument</c> 中查找指定根元素名称的文档。
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="xmlDocuments">XML 文档列表。</param>
|
||||||
|
/// <param name="rootName">目标根元素名称。</param>
|
||||||
|
/// <returns>符合条件的 XML 文档列表。</returns>
|
||||||
|
public static List<XmlDocument> FindDocumentsWithRootName(List<XmlDocument> xmlDocuments, string rootName)
|
||||||
|
{
|
||||||
|
var result = new List<XmlDocument>();
|
||||||
|
|
||||||
|
foreach (var xmlDoc in xmlDocuments)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// 获取根节点
|
||||||
|
var root = xmlDoc.DocumentElement;
|
||||||
|
|
||||||
|
if (root != null && root.Name == rootName)
|
||||||
|
{
|
||||||
|
// 如果根节点名称匹配,则添加到结果列表
|
||||||
|
result.Add(xmlDoc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.Error.WriteLine($"处理 XML 文档时发生错误: {ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user