(client) feat:添加将XML读取为XML组件的函数
This commit is contained in:
@ -19,7 +19,7 @@ namespace Data
|
||||
public void Init()
|
||||
{
|
||||
// 加载所有 XML 文件路径
|
||||
var xmlFilePaths = FileHandler.LoadXmlFilesFromPaths(dataSetFilePath);
|
||||
var xmlFilePaths = FileHandler.GetXmlFilePathsFromPaths(dataSetFilePath);
|
||||
|
||||
// 遍历并加载每个 XML 文件
|
||||
foreach (var xmlFilePath in xmlFilePaths)
|
||||
|
@ -1,8 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Xml;
|
||||
using Newtonsoft.Json;
|
||||
using UnityEngine;
|
||||
using Formatting = Newtonsoft.Json.Formatting;
|
||||
|
||||
namespace Utils
|
||||
{
|
||||
@ -158,7 +160,7 @@ namespace Utils
|
||||
/// </summary>
|
||||
/// <param name="paths">文件夹路径</param>
|
||||
/// <returns></returns>
|
||||
public static List<string> LoadXmlFilesFromPaths(string[] paths)
|
||||
public static List<string> GetXmlFilePathsFromPaths(string[] paths)
|
||||
{
|
||||
var xmlFilePaths = new List<string>();
|
||||
|
||||
@ -194,6 +196,38 @@ namespace Utils
|
||||
|
||||
return xmlFilePaths;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从指定路径加载所有 XML 文件并解析为 XmlDocument 对象。
|
||||
/// </summary>
|
||||
/// <param name="paths">文件夹路径数组。</param>
|
||||
/// <returns>包含所有解析后的 XmlDocument 对象的列表。</returns>
|
||||
public static List<XmlDocument> LoadXmlFromPaths(string[] paths)
|
||||
{
|
||||
var xmlDocuments = new List<XmlDocument>();
|
||||
var xmlFilePaths = GetXmlFilePathsFromPaths(paths);
|
||||
|
||||
foreach (var filePath in xmlFilePaths)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 创建一个新的 XmlDocument 实例
|
||||
var xmlDoc = new XmlDocument();
|
||||
|
||||
// 加载 XML 文件内容
|
||||
xmlDoc.Load(filePath);
|
||||
|
||||
// 将解析后的 XmlDocument 添加到结果列表中
|
||||
xmlDocuments.Add(xmlDoc);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.Error.WriteLine($"加载 XML 文件 {filePath} 时发生错误: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
return xmlDocuments;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user