Java Reference
In-Depth Information
</xs:element>
<xs:element name="title" type="xs:string"/>
<xs:element name="authors">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" ref="author"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="price" type="xs:decimal"/>
<xs:element name="category" type="xs:NCName"/>
<xs:element name="author" type="xs:string"/>
</xs:schema>
Discussion
As you can see, Trang does a good job of inferring appropriate values from your XML source.
A book can have one author or a set of authors, and Trang figures out how to make a choice
element and add references.
One thing worth noting is that the schema design pattern used in Trang may not be exactly
what you want, depending on your use case. The elements in the preceding example are all
global and in the default namespace.
When working with SOA, you definitely are going to need to do your best to ensure interop-
erability. You therefore will probably want to employ the option to disable abstract types, like
this:
-o disable-abstract-elements
In general, you'll want to start with a schema if you can. Sometimes you won't have that lux-
ury, and sometimes it will be much quicker and easier to write the XML instance you know
you'll need for your SOAP payload or whatever you're working with, and then generate a
schema that you can tweak somewhat (or a lot) to make it conform with a design pattern that
you want.
You can use Trang to generate DTD and Relax NG for you as well—that is actually its original
purpose. But here we limit our focus to XML schema, as it is the most widely used way of
representing a valid XML structure.
Generating a set of schemas from a single XML document
Maybe you have an XML document that defines a variety of namespaces, and you'd like
Trang to generate corresponding schemas for each of them. You can do that too.
Search WWH ::




Custom Search