使用 Java 将 XSD 转换为树结构

Convert XSD to tree structure with Java(使用 Java 将 XSD 转换为树结构)
本文介绍了使用 Java 将 XSD 转换为树结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我想为 XML 模式生成文档.

I want to generate documentation for XML schemas.

我的目标是分析 xsd 文件并将其显示为树结构(解决所有复杂/匿名类型).此外,我需要用它们的基数(由模式定义)注释该树中的所有项目.

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]

有人知道这个问题的基于 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 规范化为可理解的数据结构,您可以循环并打印出来.

XSOM can normalize an XSD into a comprehensible data structure that you can loop over and print out.

这篇关于使用 Java 将 XSD 转换为树结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)