从原型转换为 XSD [英] Convert from Proto to XSD
问题描述
我需要能够从 proto 转换为 xsd,我知道有一些工具可以从 XSD 转换为 PROTO,但我需要 oppositive.
I need to be able to convert from proto to xsd, I know that there is some tools to convert from XSD to PROTO, but I need the oppositive.
可能是 .NET 或 Java
Could be in .NET or Java
谢谢
推荐答案
您没有指定最终要接收的 XSD 示例.实际上,Protobuf 消息可以通过多种方式在 XSD 中表示.
You did not specified example of XSD you'd like to receive in the end. Actually, there are multiple ways how Protobuf messages could be represented in XSD.
可能会出现一些问题:
- 您希望如何存储 PROTO 字段:作为属性或元素(对于像
string/bool/int
这样的简单类型)? - 您是否想要固定的 XML 元素顺序?(换句话说,您想在
xs:complexType
定义中使用xs:sequence
还是xs:all
?)
- How would you like to store PROTO fields: as attributes or elements (for simple types like
string/bool/int
)? - Would you like to have fixed order of XML elements or not? (Another words, would you like to use
xs:sequence
orxs:all
in yourxs:complexType
definitions?)
到目前为止我遇到了同样的问题.我解决了我的任务并在博客文章中描述了它.
I had same issue not so far. I solved my task and described it in blog post.
我的任务的解决方案是:
Solution for my task was:
- 使用
protogen.exe
将 PROTO 序列化为 XML 表示 - 然后运行自定义编写的 XSLT 以生成 XSD 架构
- use
protogen.exe
to serialize PROTO to XML representation - then run custom written XSLT to generate XSD schema
实际上,我写了 XSLTprotogen.exe
生成 XSD.使用它,这个 PROTO 将转换为这个XSD.
Actually, I wrote XSLT for protogen.exe
to generate XSD. Using it, this PROTO will be converted to this XSD.
您可以根据需要自定义此 XSLT.希望这会有所帮助!
You can customize this XSLT for your needs. Hope this helps!
这篇关于从原型转换为 XSD的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!