How to generate XSD from elements of XML

前端 未结 5 1456
故里飘歌
故里飘歌 2021-02-19 23:23

I have a XML input


  id
  string
  42
  

        
5条回答
  •  Happy的楠姐
    2021-02-20 00:08

    If all you want is an XSD so that the XML you gave conforms to it, you'd be much better off by crafting it yourself rather than using a tool.

    No one knows better than you the particularities of the schema, such as which valid values are there (for instance, is the element required? are true and false the only valid values for ?).

    If you really want to use a tool (I'd only advice using it if you haven't designed the XML and really can't get the real XSD - or if you designed it, double check the generated XSD), you could try Trang. It can infer an XSD Schema from a number of example XML's.

    You'll have to take into account that the XSD a tool can infer you might be incomplete or inaccurate if XML samples aren't representative enough.

    java -jar trang.jar sampleXML.xml inferredXSD.xsd
    

    You can find a usage example of Trang here.

提交回复
热议问题