Search code examples
javaprotocol-buffersprotobuf-net

Convert from Proto to XSD


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.

Could be in .NET or Java

Thanks


Solution

  • 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.

    Some of questions may arise:

    • 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 or xs:all in your xs:complexType definitions?)

    I had same issue not so far. I solved my task and described it in blog post.

    Solution for my task was:

    • use protogen.exe to serialize PROTO to XML representation
    • then run custom written XSLT to generate XSD schema

    Actually, I wrote XSLT for protogen.exe to generate XSD. Using it, this PROTO will be converted to this XSD.

    You can customize this XSLT for your needs. Hope this helps!