我应该如何创建&将描述某些导入数据的 XML 文件映射到 DTO?

发布于 2024-08-22 05:06:29 字数 336 浏览 4 评论 0原文

我必须编写一个导入实用程序,它将导入 xml 文件中保存的一些数据。我想我将创建一个简单的 DTO 对象,它是导入数据的表示,然后编写所有代码,以便它基于该对象进行导入。

XML 文件将定义传输格式,因此我希望第三方能够生成该格式的文件,以便能够将数据导入应用程序。该格式将来还可能会扩展,以允许导入更多类型的数据。

我想要的是一种简单的方法,让我的对象填充所有要从 XML 文件处理的导入数据。

我以为我可以反序列化 xml 文件,但担心第三方在没有首先序列化 DTO 对象的情况下创建文件可能会出现问题。这可能是个问题吗?还有哪些其他替代方案,最好不涉及手动读取 xml 文件,但显然这将是后备解决方案。

I have to write a import utility which will import some data held in an xml file. I imagine that I will create a simple DTO object which is the representation of the import data and then write all my code so that it does the import based on this object.

The XML file will be the definition of the transfer format, so I expect that 3rd parties will produce files in the format to be able to import data into the application. The format may also be expanded in the future, to allow import of more types of data.

What I would like is a simply way of getting my object populated with all the import data to process from the XML file.

I was thinking that I could just deserialise the xml file, but am concerned that there might be issues for 3rd parties creating the files without having the DTO object to serialise in the first place. Is this likely to be a problem? What are the other alternatives, preferably which don't involve reading the xml file manually, but obviously that will be the fall back solution.

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

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

发布评论

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

评论(1

待天淡蓝洁白时 2024-08-29 05:06:29

如果您创建一个表示有线格式(在本例中为 XML 格式)的架构并将该架构分发给第 3 方,他们可以在其本机平台中创建该对象。有许多工具适用于所有不同平台上的所有语言,可以获取模式并从中生成源代码中的对象 DTO。

XSD.EXE 是针对.Net 的。

如果您期望将来的扩展,请为每个扩展创建一个新架构或使用 XSD:ANY 元素来保存将来的扩展。

这样您就可以继续使用 XmlSerializer 并使您的生活更轻松。

希望这有帮助,

If you create a schema that represents the wire-format (XML format in this case) and hand out the schema to the 3rd parties, they can create the object in their native platform. There are many tools for all languages on all different platforms to take a schema and make the object DTO in source code from it.

XSD.EXE is the one for .Net.

if you expect future extensions, make a new schema per extension or use an XSD:ANY element to hold your extensions in the future.

That way you can keep on using the XmlSerializer and make your life easier.

Hope this helps,

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