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.
我们有数百个XML文件,没有预先定义的XML架构(XSD)。我能够使用工具(IntelliJ Idea)从其中一个文件生成XSD,但它不够聪明,无法识别哪些元素和属性是可选的,哪些是必需的。
One way to automate that would be to reverse engineer XSD from multiple XML files using the following heuristic:
自动化的一种方法是使用以下启发式从多个XML文件反向设计XSD:
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
).属性/元素是可选的(use =“optional”/ minOccurs = 0),如果在某些情况下它发生而在其他情况下不发生。否则,它是必需的(use =“required”/ minOccurs = 1)。
Obviously, the heuristic would work also for a single XML file, if this XML is sufficiently representative.
显然,如果这个XML具有足够的代表性,那么启发式算法也适用于单个XML文件。
For instance, aflightNumber
would be considered optional given the following input:
例如,给定以下输入,aflightNumber将被视为可选:
<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?
您是否知道生成XSD的任何工具并识别属性/元素是否可选?
1 个解决方案
#1
1
Try QTAssistant (I am associated with it). Under the Tools tab
尝试QTAssistant(我与之相关)。在“工具”选项卡下
There's an XSD from XMLs command.
XMLs命令有一个XSD。
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.
您的XML文件应该都在一个文件夹中。在对话框中,您必须选择要在生成XSD时考虑的那些。 XSD将在同一文件夹中生成并为您加载。
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.
但是,我没有尝试过数百个XML文件。如果您遇到任何麻烦,请通过我们网站上的支持地址告诉我。下载是免费试用,但它需要注册。
#1
1
Try QTAssistant (I am associated with it). Under the Tools tab
尝试QTAssistant(我与之相关)。在“工具”选项卡下
There's an XSD from XMLs command.
XMLs命令有一个XSD。
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.
您的XML文件应该都在一个文件夹中。在对话框中,您必须选择要在生成XSD时考虑的那些。 XSD将在同一文件夹中生成并为您加载。
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.
但是,我没有尝试过数百个XML文件。如果您遇到任何麻烦,请通过我们网站上的支持地址告诉我。下载是免费试用,但它需要注册。