gpt4 book ai didi

c# - 用于 XML 模式扁平化的库

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:53:02 25 4
gpt4 key购买 nike

有一组 N 个 XSD 文件可以相互引用(使用 include/import/redefine 标签)。任务是将这组 N 个 XSD 文件转换为最少可能数量的 M 个 XSD 文件。转换意味着尽可能就地插入包含的文件、解析引用等。

此功能在某些 UI XML 编辑器中成功运行。

是否有任何免费或商业库( native 或 .NET)可以让我执行 XML 架构扁平化?或者可能有一些关于展平算法的引用资料?

最佳答案

我认为您不需要图书馆。使用标准的 .NET 模式类,这是将带有一堆包含的 XSD 转换为单个 XSD 的代码:

static private void ResolveExternal(
XmlSchema rootSchema,
XmlSchema curSchema,
List<string> processed
)
{
// Loop on all the includes
foreach (XmlSchemaExternal external in curSchema.Includes) {
// Avoid processing twice the same include file
if (!processed.Contains(external.SchemaLocation)) {
processed.Add(external.SchemaLocation);
XmlSchema cur = external.Schema;
// Recursive calls to handle includes inside the include
ResolveExternal(rootSchema, cur, processed);
// Move the items from the included schema to the root one
foreach (XmlSchemaObject item in cur.Items) {
rootSchema.Items.Add(item);
}
}
}
curSchema.Includes.Clear();
} // ResolveExternal

static public void ResolveExternal(XmlSchema schema)
{
List<string> processed = new List<string>();
ResolveExternal(schema, schema, processed);
} // ResolveExternal

您应该能够以类似的方式处理导入和重新定义。

关于c# - 用于 XML 模式扁平化的库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13706649/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com