从运行时加载的XSD创建有效的XML(不带xsd.exe)

时间:2022-01-14 17:17:56

Possible Duplicate:

可能重复:

Here's the scenario: I've created an application that hooks into a commercial CRM product using their web service API, which unfortunately has a different schema for every installation, based on how the users create their custom fields. This schema can also be modified at any time. This application will be installed at the customer location, and will need to function even when they change their field structure.

这是一个场景:我创建了一个应用程序,它使用他们的Web服务API挂钩到商业CRM产品,不幸的是,根据用户创建自定义字段的方式,每个安装都有不同的架构。也可以随时修改此架构。此应用程序将安装在客户位置,即使在更改其字段结构时也需要运行。

In order to insert or update a record, I first call their Project.GetSchema() method, which returns the XSD file based on the current set of fields, and then I can call the Project.AddProject() method, passing in an XML file containing the project data.

为了插入或更新记录,我首先调用他们的Project.GetSchema()方法,该方法根据当前字段集返回XSD文件,然后我可以调用Project.AddProject()方法,传入XML包含项目数据的文件。

My question is: What's the best way to generate the XML from the XSD file at runtime? I need to be able to check for the existence of fields, and fill them out only if they exist (for instance, if the customer deleted or renamed some fields).

我的问题是:在运行时从XSD文件生成XML的最佳方法是什么?我需要能够检查字段是否存在,并且只有在它们存在时填写它们(例如,如果客户删除或重命名某些字段)。

I really don't want to have the application attempting to recompile classes on the fly using xsd.exe. There simply must be a better way.

我真的不希望应用程序尝试使用xsd.exe动态重新编译类。必须有一个更好的方法。

[update] My current solution, that I'm working on, is to basically parse out the XSD file myself, since the majority of the schema is going to be the same for each installation. It's just an ugly solution, and I was hoping there was a better way. The biggest problem I have is that their schema uses xsd:sequence, so putting things in a different order always breaks validation.

[更新]我当前正在研究的解决方案是基本解析XSD文件,因为每个安装的大部分架构都是相同的。这只是一个丑陋的解决方案,我希望有更好的方法。我遇到的最大问题是他们的模式使用xsd:sequence,因此将事物放在不同的顺序总是会破坏验证。

1 个解决方案

#1


0  

For others that wound up here: the best solution given the constraints, create XML at runtime and using .NET, is probably the first link:
Is there a class to generate a sample XML document from XSD schema in .NET

对于其他人来说:给出约束的最佳解决方案,在运行时创建XML并使用.NET,可能是第一个链接:是否有一个类从.NET中的XSD架构生成示例XML文档

At least, that's what I am going to try :).

至少,这就是我要尝试的:)。

#1


0  

For others that wound up here: the best solution given the constraints, create XML at runtime and using .NET, is probably the first link:
Is there a class to generate a sample XML document from XSD schema in .NET

对于其他人来说:给出约束的最佳解决方案,在运行时创建XML并使用.NET,可能是第一个链接:是否有一个类从.NET中的XSD架构生成示例XML文档

At least, that's what I am going to try :).

至少,这就是我要尝试的:)。