File: conIntroToTheSchemaTypeSystem.html

package info (click to toggle)
xmlbeans 2.5.0-4
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 8,076 kB
  • sloc: java: 90,788; xml: 3,177; sh: 108; sql: 48; makefile: 29
file content (229 lines) | stat: -rw-r--r-- 12,001 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
<!doctype HTML public "-//W3C//DTD HTML 4.0 Frameset//EN">

<!-- Copyright 2004 The Apache Software Foundation

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

         http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License. -->
<html>
<head>
<!-- InstanceBeginEditable name="doctitle" -->
<title>Introduction to Schema Type Signatures</title>
<!-- InstanceEndEditable -->
<!--(Meta)==========================================================-->

<meta http-equiv=Content-Type content="text/html; charset=$CHARSET;">


<!-- InstanceBeginEditable name="metatags" -->

<meta content="your name" name="author">
<meta content="A description of the topic contents." name="description">
<meta content="keywords to help in searches" name="keywords">
<meta content="10/25/02" name="date last modified">
<!-- InstanceEndEditable -->

<!--(Links)=========================================================-->
<!-- InstanceBeginEditable name="head" -->
<link href="../xmlbeans.css" rel="stylesheet" type="text/css">
<!-- InstanceEndEditable -->
<link href="../xmlbeans.css" rel="stylesheet" type="text/css">
<a href="../../../core/index.html" id="index"></a>
<script language="JavaScript" src="../../../core/topicInfo.js"></script>
<script language="JavaScript" src="../../../core/CookieClass.js"></script>
<script language="JavaScript" src="../../../core/displayContent.js"></script>
</head>

<!--(Body)==========================================================-->
<body>
<script language="JavaScript">

</script>
<!-- InstanceBeginEditable name="body" -->
<h1> Introduction to Schema Type Signatures</h1>
<div id="topictext">
  <p>When you compile schema, the API generated from your schema is integrated
    with the XMLBeans type system that represents the underlying XML schema. All
    together, these types make up the <em>schema type system</em> to which your
    code has access. When handling XML based on the schema, you typically call
    methods of the API generated when you compiled the schema. However, for the
    cases when you want to get information about the schema itself, you use the
    schema type system API.</p>
  <p>In the XMLBeans API, you have access to the system itself through <a href="../reference/org/apache/xmlbeans/SchemaTypeSystem.html"><span class="langinline">SchemaTypeSystem</span></a>
    and related classes. These make up a kind of &quot;meta-API,&quot; or a view
    on the schema. You can use the schema type system API to discover the type
    system at run time. See the reference topic on that interface for an overview
    of the schema type system.</p>
  <h2>Schema Type &quot;Signatures&quot;</h2>
  <p>A schema is made up of schema components. Schema components are the pieces
    of a schema, such as a type definition, an element declaration, attribute
    declaration, and so on. To mirror these in the schema type system, a <a href="../reference/org/apache/xmlbeans/SchemaComponent.html"><span class="langinline">SchemaComponent</span></a>
    instance represents a component in the underlying schema; separate components
    have corresponding types. For example you would have a <span class="langinline"><a href="../reference/org/apache/xmlbeans/SchemaType.html">SchemaType</a></span>
    object for a <span class="langinline">CustomerType</span> your schema defined,
    or a <a href="../reference/org/apache/xmlbeans/SchemaGlobalElement.html"><span class="langinline">SchemaGlobalElement</span></a>
    object for a global <span class="langinline">PurchaseOrder</span> element.
    You would also have a <span class="langinline">SchemaType</span> for built-in
    schema types, such as <span class="langinline">xs:string</span> or <span class="langinline">xs:datetime</span>.
    XMLBean provides a &quot;signature&quot; to describe each type. You can retrieve
    this signature by calling the SchemaType class's <span class="langinline">toString</span>
    method.</p>
  <p>The <span class="langinline">toString</span> method returns XMLBeans' version
    of a unique signature for a schema type. This string is useful for debugging
    because it describes a given type even when the type doesn't have a name.
  </p>
  <p class="notepara"><strong>Note:</strong> It's important to remember that this
    signature is an XMLBeans convention, rather than a standard from the schema
    working group. The working group has not yet standardized a signature for
    XML schema types. As a result the signature you'll see from XMLBeans is subject
    to change &#8212; whatever the schema working group comes up with in the end
    (if anything) is probably what will be used by this API. In other words, don't
    write a program to decode the signature.</p>
  <p>You can use the following description to understand how a signature is constructed.</p>
</div>
<ul>
  <li>
    <div><strong>Global types.</strong> If the type has a name, it's a global
      type. The following form is used:</div>
    <div>
      <div>
        <pre>T=&lt;localname&gt;@&lt;targetNamespace&gt;</pre>
      </div>
    </div>
    <p>The &quot;T&quot; is for &quot;type,&quot; of course. &quot;localname&quot;
      is a convention used by qnames (qualified names), which include a local
      name and the namespace URI (if any). So an example might be:</p>
    <pre>T=customer@openuri.org</pre>
  </li>
  <li><strong>Document types and global attribute types.</strong> These correspond
    to a special anonymous type containing one global element or attribute. These
    special types are generated by XMLBeans to represent global types declared
    with the &lt;element&gt; or &lt;attribute&gt; tag in schema. Because such
    types are types, but are declared as elements or attributes, they require
    special treatment. The following signature form is used:
    <div>
      <pre>
D=&lt;document-element-name&gt;@&lt;targetNamespace&gt;
R=&lt;attribute-type-name&gt;@&lt;targetNamespace&gt;
</pre>
      <div></div>
    </div>
    <div>
      <div>Note that these are also the signatures of a type returned by a FooDocument.type
        or FooAttribute.type method call.</div>
    </div>
  </li>
  <li><strong>Anonymous types.</strong> If the type is anonymous, it is defined
    as an element or attribute, or within a further anonymous type. In this case,
    the signature is built by establishing the local context (in order words,
    what is the anonymous type nested in?). From the local context, the larger
    context is built recursively. In other words, the signature is built by giving
    not only the anonymous type itself, but also by describing its context.
    <p> The following rules are used for building a signature for an anonymous
      type. </p>
    <ul>
      <li> It might be an anonymous type defined inside a local element or attribute,
        which in turn is defined within something else:
        <p>If the element is <span class="langinline" style="langinline">form=&quot;qualified&quot;</span>
          (the usual default):</p>
      </li>
    </ul>
  </li>
  <blockquote>
    <div>
      <pre>E=&lt;eltname&gt;|&lt;signature of the type within which the elt is defined&gt;</pre>
    </div>
    <div>If the element is <span class="langinline" style="langinline">form=&quot;unqualified&quot;</span>:</div>
    <div>
      <pre>U=&lt;eltname&gt;|&lt;signature of the type within which the elt is defined&gt;</pre>
    </div>
    <div>If the attribute is <span class="langinline" style="langline">form=&quot;unqualified&quot;</span>
      (the usual default):</div>
    <div>
      <pre>A=&lt;attrname&gt;|&lt;signature of the type within the attr is defined&gt;</pre>
    </div>
    <div>if the attribute is <span class="langinline" style="langinline">form=&quot;qualified&quot;</span>:</div>
    <div>
      <pre>Q=&lt;attrname&gt;|&lt;signature of the type within the attr is defined&gt;</pre>
    </div>
  </blockquote>
  <ul>
    <li>It might be an anonymous type defined a simple restriction, union, or
      list definition:</li>
  </ul>
  <blockquote>
    <div>
      <pre>M=#|&lt;signature of the containing union type&gt;</pre>
      <p>(The # is a number indicating which union member it is, by source order
        &#8212; such as 0,1,2, etc.)</p>
      <pre>B=|&lt;signature of the containing base type for a restriction&gt;</pre>
      <pre>I=|&lt;signature of the containing list type&gt;</pre>
    </div>
  </blockquote>
  <ul>
    <li>
      <div> In the future if anonymous types are allowed in some other context,
        there may be more codes.</div>
    </li>
  </ul>
</ul>
<h2>An Example</h2>
<p>So, for example, if you have a type that describes the list items within an
  attribute of an instance that looks like this:</p>
<blockquote>
  <div>
    <pre> &lt;root mylist=&quot;432 999 143 123&quot;/&gt;</pre>
  </div>
</blockquote>
<div> The schema, if done with lots of nested types, could look something like
  this:</div>
<blockquote>
  <div>
    <pre>
&lt;schema targetNamespace=&quot;myNamespace&quot; elementFormDefault=&quot;qualified&quot;&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;element name=&quot;root&quot;&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;complexType&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;attribute name=&quot;mylist&quot;&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;simpleType&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;list&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;simpleType&gt; &lt;!--This is the type that the signature is for --&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;restriction base=&quot;xs:nonNegativeInteger&quot;&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;totalDigits value=&quot;3&quot;/&gt;..
</pre>
  </div>
</blockquote>
<div> The signature for the simpleType indicated in the example would be:</div>
<blockquote>
  <pre>I=|A=mylist|E=root|D=root@myNamespace</pre>
</blockquote>
<div>
  <p>You could read this as: </p>
</div>
<blockquote>
  <div>&quot;The type of the list item | within the type of the mylist attribute's
    type | within the type of the root element | within the document type for
    &lt;root&gt; documents | in the myNamespace namespace&quot;.</div>
</blockquote>
<div>
  <p>Note that the signature structure mirrors the Java class structure generated
    by XMLBeans when compiling the schema. In other words, if you were to compile
    a schema that included the preceding snippet, you would be able to access
    an instance of the schema with Java code like the following:</p>
  <pre>SchemaType sType = RootDocument.Root.MyList.Item.type;</pre>
</div>
<p class="relatedtopics">Related Topics</p>
<p><a href="conGettingStartedwithXMLBeans.html">Getting Started with XMLBeans</a></p>
<!-- InstanceEndEditable -->
<script language="JavaScript">

</script>
</body>
</html>