In Java, how do I parse an xml schema (xsd) to learn what's valid at a given element?

前端 未结 6 1957
感动是毒
感动是毒 2021-02-08 23:01

I\'d like to be able to read in an XML schema (i.e. xsd) and from that know what are valid attributes, child elements, values as I walk through it.

For example, let\'s

6条回答
  •  悲哀的现实
    2021-02-08 23:30

    It's agood bit of work depending on how compex your xsd is but basically.

    if you had

    
    

    And you wanted to find out where were the alowable children of header you'd (taking account of namespaces) Xpath would have you look for '/element[name="Document"]/element[name="Header"]'

    After that it depends on how much you want to do. You might find it easier to write or find something that loads an xsd into a DOM type structure. Course you are going to possibly find all sorts of things under that elment in xsd, choice, sequence, any, attributes, complexType, SimpleContent, annotation.

    Loads of time consuming fun.

提交回复
热议问题