Reputation: 4514
We have hundreds of XML files with no XML schema (XSD) defined in advance. I was able to generate an XSD from one of those files with a tool (IntelliJ Idea), but it is not smart enough to recognize which elements and attributes are optional and which are required.
One way to automate that would be to reverse engineer XSD from multiple XML files using the following heuristic:
An attribute/element is optional (
use="optional"
/minOccurs=0
) if in some instances it occurs and in other does not. Otherwise, it is required (use="required"
/minOccurs=1
).
Obviously, the heuristic would work also for a single XML file, if this XML is sufficiently representative.
For instance, aflightNumber
would be considered optional given the following input:
<list>
<carrier name="BA" flightNumber="213" />
<carrier name="CY" />
</list>
Do you know any tool to generate XSD and recognize whether an attribute/element is optional?
Upvotes: 0
Views: 439
Reputation: 21658
Try QTAssistant (I am associated with it). Under the Tools tab
There's an XSD from XMLs command.
Your XML files should ALL be in one folder. From the dialog box, you'll have to select the ones you want to consider in generating the XSD(s). The XSDs will be generated in the same folder and loaded for you.
However, I haven't tried it for hundreds of XML files. If you run into any troubles, let me know through the support address on our web site. The download is free of charge to try it, but it requires registration.
Upvotes: 1