Can any tool generate xsd from xml? [closed]
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 8 years ago.
Improve this questionI am wondering if there is tool to infer xsd from xml using Java?
Check out xmlspy. It is a very handy tool for xml stuffs.
There are inevitably free tools to do this as well.
Prasheel Oggu suggests http://www.freeformatter.com/xsd-generator.html
I've never used that tool, so I neither recommend nor suggest against it.
I have had good success with the utility: inst2xsd which is provided by xmlbeans. You can read more about it at the Apache website: xmlbeans.apache.org (with the direct link to inst2xsd documentation here. The tool is free.
The tool is easy to use and comes with plenty of options, which have always met my requirements.
Basic usage is: inst2xsd [file.xml]
Example 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>
This will produce the following file: 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>
you might want to try trang
. on debian/ubuntu it's easily installed:
sudo apt-get install trang
not the most polished piece of software I've seen, but it did its job here.
since it's pure Java, it should not be difficult to install it on other systems.
ubuntu 11.04 offers a version that is timestamped as 20091111, while http://www.thaiopensource.com/relaxng/trang.html mentions 20081028 as newest available version. I did not try to understand the reason of this.
精彩评论