Is there a tool to generate a JSON schema from an XML schema through Java?

前端 未结 5 991
滥情空心
滥情空心 2020-12-14 08:20

Is anyone aware of a tool or approach from which we can generate a JSON schema from XML schema or XML schema from JSON schema by Java?

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-14 09:06

    I'd expect you to be able to write an XSLT script that generated JSON structures from the XML schema fairly easily. This works because XSLT is prefectly happy to read and transform XML, and an XML schema is just XML.

    Going the other way would be a bit harder. You need somthing that can read a JSON schema and spit out XML. For this you need a parser, and likely something that builds an AST of the parse. With that and a tree walk you're likely to be able to generate an XML schema fairly easily.

    ANTLR will let you define grammars, build a parser and an AST fairly easily. It has some kind of "Structured Text" generator that might work for walking the AST.

    Our DMS Software Reengineering Toolkit is like ANTLR but with more machinery. With DMS you can define the JSON syntax, build ASTs, and then write source-to-source tranformatinos to map that to XML representing your schema.

提交回复
热议问题