問題描述
我想為 XML 模式生成文檔.
I want to generate documentation for XML schemas.
我的目標(biāo)是分析 xsd 文件并將其顯示為樹結(jié)構(gòu)(解決所有復(fù)雜/匿名類型).此外,我需要用它們的基數(shù)(由模式定義)注釋該樹中的所有項(xiàng)目.
My goal is to analyze the xsd file and to display it as a tree structure (with all complex / anonymous types resolved). Furthermore I need to annotate all items in that tree with their cardinality (as defined by the schema).
下面的小例子可能有助于澄清我的問題.
The following small example might help to clarify my problem.
a) xsd 文件:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="client" type="clientType" />
<xs:complexType name="clientType">
<xs:sequence minOccurs="1" maxOccurs="1">
<xs:element name="first_name"/>
<xs:element name="last_name"/>
<xs:element name="address" type="addressType"
minOccurs="1" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="addressType">
<xs:sequence>
<xs:element name="street"/>
<xs:element name="number" minOccurs="0" maxOccurs="1"/>
<xs:element name="city"/>
<xs:element name="zipcode"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
b) 我想看到的輸出:
b) Output I'd like to see:
client [1]
first_name [1]
last_name [1]
address [1..n]
street [1]
number [0..1]
city [1]
zipcode [1]
有人知道這個(gè)問題的基于 java 的解決方案嗎?最好基于 Eclipse Schema Infoset,但我也很樂意使用其他庫.
Does anybody know a java based solution for this problem? Preferably based on Eclipse Schema Infoset, but I'm happy to use other libraries as well.
推薦答案
XSOM 可以將 XSD 規(guī)范化為可理解的數(shù)據(jù)結(jié)構(gòu),您可以循環(huán)并打印出來.
XSOM can normalize an XSD into a comprehensible data structure that you can loop over and print out.
這篇關(guān)于使用 Java 將 XSD 轉(zhuǎn)換為樹結(jié)構(gòu)的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!