XSD.exe 和“循环组引用”

发布于 2024-08-24 18:53:00 字数 338 浏览 4 评论 0原文

我正在尝试构建一些类,以便可以反序列化由第三方应用程序创建的 XML 文件。幸运的是,第 3 方应用程序的开发人员在其代码中包含了一个架构文件,以便可以理解 XML 文件。

当我使用 Visual Studio 中的 XSD.exe 工具时,进程失败并报告以下错误

“来自 targetNamespace='' 的组 'SegGroupOrSegmentGrouping' 具有无效定义:循环组引用。”

任何关于如何根据此错误生成类文件的帮助将不胜感激。 可以在此处找到架构文件的副本:架构文件

I am attempting to build some classes so that I can deserialise an XML file created by a third party application. Luckily the developer of the 3rd party application included a schema file with their code so that the XML file can be understood.

When I use the XSD.exe tool from Visual Studio the process fails reporting the following error

"Group 'SegGroupOrSegmentGrouping' from targetNamespace='' has invalid definition: Circular group reference."

Any help in how I can generate the class files in light of this error would be appreciated.
A copy of the schema file can be found here : schema file

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

巷雨优美回忆 2024-08-31 18:53:00

尝试使用svcutil;它可以处理循环引用。

在以下示例中,eExact-Schema.xsdxsd.exe 无法处理的 XSD。

示例:

C:\SRC\Exact>svcutil eExact-Schema.xsd /language:C# /dataContractOnly /importxmltypes /out:exact.cs

这始终是一个好的起点;您现在可以使用此类并进行更改以适合您的风格/需求、添加注释等,这将为您节省大量时间/搜索而不是从头开始完成这一切。

Try using svcutil; it can handle the circular references.

In the following example, eExact-Schema.xsd is an XSD that xsd.exe cannot handle.

Example:

C:\SRC\Exact>svcutil eExact-Schema.xsd /language:C# /dataContractOnly /importxmltypes /out:exact.cs

This is always a good place to start; you can now use this class and alter to suit your style/needs, add comments, etc, and it will save you a lot of time/searching over doing it all from scratch.

一片旧的回忆 2024-08-31 18:53:00

我最近遇到了同样的问题,

第三方公司给了我一个 Schema,该公司从 Web 服务返回 xml 结构。然后我想使用 NHibernate 反序列化响应并将信息存储到数据库中。

没问题,我想我只要使用 xsd.exe 就可以上课了。不幸的是,事实并非如此。 Xsd.exe 失败,并出现与您遇到的完全相同的错误。这是因为它无法解决循环引用。

我花了好几天的时间寻找替代方案,直到最后我将自己的类结构写入模式并能够完美地反序列化。这里的答案是编写您自己的 C# 类并使用适当的属性来装饰它们。

为自己节省一些时间和心痛,不要继续尝试最终自动生成您需要的类,尽管您编写的类很耗时,但不会做出大多数工具(不能完美工作)会让您做出的妥协制作。

我花了大约 3 天的时间来编写类结构(它很大),但我最终得到了一个高质量的解决方案。

有一点是肯定的,您将无法使用 xsd.exe 和我在谷歌搜索后尝试过的大多数其他工具,要么无法正常工作,要么有错误。

I had this same problem recently,

I was given a Schema from a third party company who were returning an xml structure from a webservice. I then wanted to deserialise the response and store the information into a database with NHibernate.

No problem I thought I'll just use xsd.exe and I'll have my classes. Unfortunately this was not to be. Xsd.exe failed with exactly the same error you are getting. This is because it is unable to resolve circular references.

I spent a good few days looking at alternatives until in the end I wrote my own class structure to the schema and was able to deserialise perfectly. The answer here is to write your own C# classes and decorate them with the appropriate attributes.

Save yourself some time and heartache and don't continue to try and generate the classes you need automatically in the end although time consuming the classes you write won't make the compromises that most tools (which don't work perfectly) will make you make.

Took me about 3 days to write the class structure (it was large) but I ended up with a quality solution.

One thing is certain you will not be able to use xsd.exe and most other tools I tried after googling this either did not work properly or were buggy.

我家小可爱 2024-08-31 18:53:00

在尝试了几个第三方工具后,我发现 Liquid Technologies 有一个非常强大的生成器,名为 Liquid XML 数据绑定器 2012。它能够处理我面临的循环组引用问题。它可以为 2.0 以后的几乎任何版本的 .net 生成代码。它生成的类确实依赖于它们提供的可重新分发的 dll。我正在使用试用版,如果在发布之前需要购买完整版,我不会感到惊讶。然而,由于我节省了大约一百个小时或更长时间的容易出错的手工编码,我不能抱怨。

After trying several third party tools, I found that Liquid Technologies has a very robust generator called Liquid XML Data Binder 2012. It was able to handle the circular group reference problem I faced. It can generate code for just about any version of .net from 2.0 on. The classes it generates do depend on a redistributable dll that they provide. I'm using the trial version and I wouldn't be surprised if a purchase of the full version will be necessary before I go to release. However, having saved me probably a hundred hours or more of error prone hand coding, I can't complain.

羁绊已千年 2024-08-31 18:53:00

对我来说最简单的方法是使用 XSD.EXE 从实际的 XML 文件创建 XSD 文件。然后从新的 XSD 文件创建一个类。如果引入原始 XML 中不存在的节点或类型,您可能需要定期修改该类,但您会节省几个小时的编码时间!

The easiest method for me is to create the XSD file from the actual XML file with XSD.EXE. Then create a class from the new XSD file. You may be required to modify the class periodically if nodes or types are introduced that did not exist in the original XML but you will save yourself HOURS of coding time!!!!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文