任何工具都可以从xml生成xsd吗?

时间:2011-03-08 22:43:42

标签: java xml

我想知道是否有使用Java从xml推断xsd的工具?

3 个答案:

答案 0 :(得分:2)

结帐xmlspy。 这是一个非常方便的xml工具。

也有不可避免的免费工具。

Prasheel Oggu建议http://www.freeformatter.com/xsd-generator.html

我从未使用过该工具, 所以我既不推荐也不反对。

答案 1 :(得分:1)

我在实用程序中取得了很大成功: inst2xsd ,由 xmlbeans 提供。 您可以在Apache网站上阅读更多相关信息:xmlbeans.apache.org(直接链接到inst2xsd文档here。该工具是免费的。

该工具易于使用,并提供了大量选项,这些选项始终符合我的要求。

基本用法是:inst2xsd [file.xml]

示例XML(car.xml):

<XML>
<Car>
<Headlight>true</Headlight>
<Wheels count="4">Black</Wheels>
</Car>
<Car>
<Headlight>true</Headlight>
<Wheels count="4">Black</Wheels>
</Car>
</XML>

这将生成以下文件:schema0.xsd:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="XML" type="XMLType"/>
  <xs:complexType name="WheelsType">
    <xs:simpleContent>
      <xs:extension base="xs:string">
        <xs:attribute type="xs:byte" name="count" use="optional"/>
      </xs:extension>
    </xs:simpleContent>
  </xs:complexType>
  <xs:complexType name="CarType">
    <xs:sequence>
      <xs:element type="xs:string" name="Headlight"/>
      <xs:element type="WheelsType" name="Wheels"/>
    </xs:sequence>
  </xs:complexType>
  <xs:complexType name="XMLType">
    <xs:sequence>
      <xs:element type="CarType" name="Car" maxOccurs="unbounded" minOccurs="0"/>
    </xs:sequence>
  </xs:complexType>
</xs:schema>

答案 2 :(得分:0)

您可能想尝试trang。在debian / ubuntu上,它很容易安装:

sudo apt-get install trang

不是我见过的最精美的软件,但它在这里完成了它的工作。

因为它是纯Java,所以在其他系统上安装它应该不难。

ubuntu 11.04提供的时间戳为20091111,而http://www.thaiopensource.com/relaxng/trang.html提及20081028为最新版本。我没有试着理解这个原因。