First Commit from Source Code Reply

This commit is contained in:
vincenzofariello
2024-05-09 17:40:24 +02:00
parent 11e3b57c5b
commit 107a016cb9
35225 changed files with 1111346 additions and 1 deletions

View File

@@ -0,0 +1,346 @@
<!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><!-- InstanceBegin template="file:///C|/p4/main/help/ide/en/Templates/Command.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<!-- InstanceBeginEditable name="doctitle" -->
<title>xmlbean Ant Task</title>
<!-- InstanceEndEditable -->
<!--(Meta)==========================================================-->
<meta http-equiv=Content-Type content="text/html; charset=$CHARSET;">
<!-- InstanceBeginEditable name="metatags" -->
<meta name="component" content="">
<!-- In the description metatag, please provide a BRIEF description of the topic contents. -->
<meta name="description" content="">
<!-- In the component metatag, please list keywords that will help a user search for this topic. -->
<meta name="keywords" content="">
<!-- InstanceEndEditable -->
<!--(Links)=========================================================-->
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
<link href="../xmlbeans.css" rel="stylesheet" type="text/css">
</head>
<!--(Body)==========================================================-->
<body>
<!-- InstanceBeginEditable name="body" -->
<div id=topictitle>
<H1 class=Title>xmlbean Ant Task</h1>
</div>
<div id=topictext>
<p>Compiles a set of XSD and/or WSDL files into XMLBeans. This is useful for
building an XMLBean JAR from XSD and WSDL files. If desired, the task can
also generate the source code that makes up the XMLBean type system specified
by the schema files.</p>
<p class="notepara"><b>Note:</b> This task depends on two external libraries not
included in the Ant distribution: one called xbean.jar, one called jsr173_1.0_api.jar.
Both can be found in the XMLBeans developer kit at <a
href="http://xmlbeans.apache.org/" target="_blank">http://xmlbeans.apache.org/</a>.
The build script will need to include a taskdef for xmlbean, which could look
like this:</p>
</div>
<blockquote>
<div class="notepara">
<pre>&lt;taskdef name="xmlbean"<br> classname="org.apache.xmlbeans.impl.tool.XMLBean"<br> classpath="path/to/xbean.jar:path/to/jsr173_1.0_api.jar" /&gt;</pre>
</div>
</blockquote>
<div>
<p>It is possible to refine the set of files that are being processed. This
can be done with the <span class="langinline">includes</span>, <span class="langinline">includesfile</span>,
<span class="langinline">excludes</span>, <span class="langinline">excludesfile</span>
and <span class="langinline">defaultexcludes</span> attributes. With the <span class="langinline">includes</span>
or <span class="langinline">includesfile</span> attribute you specify the
files you want to have included by using patterns. The <span class="langinline">exclude</span>
or <span class="langinline">excludesfile</span> attributes are used to specify
the files you want to have excluded. This is also done with patterns. And
finally with the <span class="langinline">defaultexcludes</span> attribute,
you can specify whether you want to use default exclusions or not. See the
section on <a
href="http://ant.apache.org/manual/dirtasks.html#directorybasedtasks" target="_blank">directory
based tasks</a> in the <a href="http://ant.apache.org/manual/" target="_blank">Ant
documentation</a>, on how the inclusion/exclusion of files works, and how
to write patterns.</p>
<p>This task forms an implicit <a
href="http://ant.apache.org/manual/CoreTypes/fileset.html" target="_blank">FileSet</a>
and supports all attributes of <code>&lt;fileset&gt;</code> (<code>dir</code>
becomes <code>basedir</code>) as well as the nested <code>&lt;include&gt;</code>,
<code>&lt;exclude&gt;</code> and <code>&lt;patternset&gt;</code> elements.</p>
<h3>Parameters</h3>
<table border="1" cellpadding="2" cellspacing="0">
<tbody>
<tr>
<td valign="top"><b>Attribute</b></td>
<td valign="top"><b>Description</b></td>
<td align="center" valign="top"><b>Required</b></td>
</tr>
<tr>
<td valign="top">schema</td>
<td valign="top">A file that points to either an individual schema file
or a directory of files. &nbsp;Not a path reference. &nbsp;If multiple
schema files need to be built together, use a nested fileset instead
of setting schema.</td>
<td align="center" valign="top">Yes, unless a fileset element is nested.</td>
</tr>
<tr>
<td valign="top">destfile</td>
<td valign="top">Define the name of the jar file created.&nbsp; For instance,
"myXMLBean.jar" will output the results of this task into a jar with
the same name.</td>
<td align="center" valign="top">No, default is "xmltypes.jar".</td>
</tr>
<tr>
<td valign="top">download</td>
<td valign="top">Set to true to permit the compiler to download URLs for
imports and includes.&nbsp; Defaults to false, meaning all imports and
includes must be copied locally.<br> </td>
<td align="center" valign="top">No, default is false.</td>
</tr>
<tr>
<td valign="top">classgendir<br> </td>
<td valign="top">Set a location to generate CLASS files into.<br> </td>
<td valign="top" align="center">No<br> </td>
</tr>
<tr>
<td valign="top">srconly<br> </td>
<td valign="top">A value of true means that only source will be generated.<br>
</td>
<td valign="top" align="center">No, default is false.</td>
</tr>
<tr>
<td valign="top">srcgendir<br> </td>
<td valign="top">Set a location to generate JAVA files into.<br> </td>
<td valign="top" align="center">No<br> </td>
</tr>
<tr>
<td valign="top">javasource<br> </td>
<td valign="top">Generate java source compatible with the given
version. Currently only "1.4" and "1.5" are supported. <br> </td>
<td valign="top" align="center">No, Default is "1.4"</td>
</tr>
<tr>
<td valign="top">classpath</td>
<td valign="top">The classpath to use if schemas in the fileset import
definitions that are supplied by other compiled XMLBeans JAR files,
or if JAVA files are in the schema fileset. Also supports a nested classpath.</td>
<td align="center" valign="top">No</td>
</tr>
<tr>
<td valign="top">classpathref</td>
<td valign="top">Adds a classpath, given as <a
href="http://ant.apache.org/manual/using.html#references" target="_blank">reference</a>
to a path defined elsewhere.</td>
<td align="center" valign="top">No</td>
</tr>
<tr>
<td valign="top">includes</td>
<td valign="top">Comma- or space-separated list of patterns of files that
must be included. All files are included when omitted.</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">includesfile</td>
<td valign="top">The name of a file. Each line of this file is taken to
be an include pattern.</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">excludes</td>
<td valign="top">Comma- or space-separated list of patterns of files that
must be excluded. No files (except default excludes) are excluded when
omitted.</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">excludesfile</td>
<td valign="top">The name of a file. Each line of this file is taken to
be an exclude pattern.</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">defaultexcludes</td>
<td valign="top">Indicates whether default excludes should be used or
not ("yes"/"no"). Default excludes are used when omitted.</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">debug</td>
<td valign="top">Indicates whether source should be compiled with debug
information; defaults to <code>off</code>. If set to <code>off</code>,
<code>-g:none</code> will be passed on the command line for compilers
that support it (for other compilers, no command line argument will
be used). If set to <code>true</code>, the value of the <code>debuglevel</code>
attribute determines the command line argument.</td>
<td align="center" valign="top">No</td>
</tr>
<tr>
<td valign="top">debuglevel</td>
<td valign="top">Keyword list to be appended to the <code>-g</code> command-line
switch. This will be ignored by all implementations except <code>modern</code>
and <code>classic(ver &gt;= 1.2)</code>. Legal values are <code>none</code>
or a comma-separated list of the following keywords: <code>lines</code>,
<code>vars</code>, and <code>source</code>. If <code>debuglevel</code>
is not specified, by default, nothing will be appended to <code>-g</code>.
If <code>debug</code> is not turned on, this attribute will be ignored.
</td>
<td align="center" valign="top">No</td>
</tr>
<tr>
<td valign="top">optimize</td>
<td valign="top">Indicates whether source should be compiled with optimization;
defaults to <code>off</code>.</td>
<td align="center" valign="top">No</td>
</tr>
<tr>
<td valign="top">includeAntRuntime</td>
<td valign="top">Whether to include the Ant run-time libraries in the
classpath; defaults to <code>yes</code>.</td>
<td align="center" valign="top">No</td>
</tr>
<tr>
<td valign="top">includeJavaRuntime</td>
<td valign="top">Whether to include the default run-time libraries from
the executing VM in the classpath; defaults to <code>no</code>.</td>
<td align="center" valign="top">No</td>
</tr>
<tr>
<td valign="top">fork</td>
<td valign="top">Whether to execute <code>javac</code> using the JDK compiler
externally; defaults to <code>yes</code>.</td>
<td align="center" valign="top">No, default is true</td>
</tr>
<tr>
<td valign="top">executable</td>
<td valign="top">Complete path to the <code>javac</code> executable to
use in case of <code>fork=&quot;yes&quot;</code>. Defaults to the compiler
of the Java version that is currently running Ant. Ignored if <code>fork=&quot;no&quot;</code></td>
<td align="center" valign="top">No</td>
</tr>
<tr>
<td valign="top">memoryInitialSize</td>
<td valign="top">The initial size of the memory for the underlying VM,
if <code>javac</code> is run externally; ignored otherwise. Defaults
to the standard VM memory setting. (Examples: <code>83886080</code>,
<code>81920k</code>, or <code>80m</code>)</td>
<td align="center" valign="top">No</td>
</tr>
<tr>
<td valign="top">memoryMaximumSize</td>
<td valign="top">The maximum size of the memory for the underlying VM,
if <code>javac</code> is run externally; ignored otherwise. Defaults
to the standard VM memory setting. (Examples: <code>83886080</code>,
<code>81920k</code>, or <code>80m</code>)</td>
<td align="center" valign="top">No</td>
</tr>
<tr>
<td valign="top">compiler</td>
<td valign="top">The compiler implementation to use. If this attribute
is not set, the value of the <code>build.compiler</code> property, if
set, will be used. Otherwise, the default compiler for the current VM
will be used.
<td align="center" valign="top">No</td>
</tr>
<tr>
<td valign="top">failonerror</td>
<td valign="top"> Determines whether or not the ant target will continue
if the XMLBean creation encounters a build error.<br> </td>
<td align="center" valign="top">No, default is true.</td>
</tr>
<tr>
<td valign="top">verbose<br> </td>
<td valign="top">Controls the amount of build message output.<br> </td>
<td valign="top" align="center">No, default is true.</td>
</tr>
<tr>
<td valign="top">quiet<br> </td>
<td valign="top">Controls the amount of build message output.<br> </td>
<td valign="top" align="center">No, default is false.</td>
</tr>
<tr>
<td valign="top">typesystemname<br> </td>
<td valign="top">The name of the package that the TypeSystemHolder class
should be generated in.&nbsp; Normally this should be left unspecified.
None of the XMLBeans are generated in this package. Use .xsdconfig files
to modify XMLBean package or class names.<br> </td>
<td valign="top" align="center">No<br> </td>
</tr>
<tr>
<td valign="top">noupa</td>
<td valign="top">Do not enforce the unique particle attribution rule.<br> </td>
<td align="center" valign="top">No, default is false.</td>
</tr>
<td valign="top">nopvr</td>
<td valign="top">Do not enforce the particle valid (restriction) rule.<br> </td>
<td align="center" valign="top">No, default is false.</td>
</tr>
<tr>
<td valign="top">noann</td>
<td valign="top">Skip over schema &lt;annotation&gt; elements<br> </td>
<td align="center" valign="top">No, default is false.</td>
</tr>
<tr>
<td valign="top">nopvr</td>
<td valign="top">Do not validate the contents of schema &lt;documentation&gt; elements.<br> </td>
<td align="center" valign="top">No, default is false.</td>
</tr>
<tr>
<td valign="top">ignoreDuplicatesInNamespaces</td>
<td valign="top">Comma separated list of one or more namespaces
in which duplicate definitions are to be ignored.
</td>
<td align="center" valign="top">No</td>
</tr>
</tbody>
</table>
<h3>Example</h3>
</div>
<div id=topictext> Be sure to define the task in your script, like this:</div>
<div>
<pre>&lt;taskdef name="xmlbean"<br> classname="org.apache.xmlbeans.impl.tool.XMLBean"<br> classpath="path/to/xbean.jar:path/to/jsr173_1.0_api.jar" /&gt;</pre>
<p>The following builds all the schemas in the schemas directory and creates
a jar called &quot;Schemas.jar&quot;. (Note: both xbean.jar and
jsr173_1.0_api.jar must be on the classpath when the task executes).</p>
</div>
<div>
<pre>
&lt;xmlbean schema="schemas" destfile="Schemas.jar"
classpath="path/to/xbean.jar:path/to/jsr173_1.0_api.jar" /&gt;</pre>
The following compiles the schema &quot;ourSchema.xsd&quot; into the default
jar &quot;xmltypes.jar&quot;. &nbsp;If &nbsp;any imports and includes are defined
by remote URLs, they are downloaded during the build.
<div>
<pre>&lt;xmlbean schema="schemas/ourSchema.xsd" download="true"<br> classpath="path/to/xbean.jar:path/to/jsr173_1.0_api.jar" /&gt;</pre>
</div>
<div>
<h4>Using a fileset</h4>
</div>
<div>
<pre>&lt;xmlbean classgendir="${build.dir}" classpath="${class.path}"<br> failonerror="true"&gt;<br> &lt;fileset basedir="src" excludes="**/*.xsd"/&gt;<br> &lt;fileset basedir="schemas" includes="**/*.*"/&gt;<br>&lt;/xmlbean&gt;</pre>
</div>
<div> Gathers all the files in the src directory except XSD files, along with
every file in the schemas directory, and compiles them. The fileset can include
schema files that refer to previously compiled schema components.&nbsp; The
fileset can also contain JAVA files.&nbsp; The classpath parameter defines
the classpath necessary to resolve compiled schema and java references (and must include xbean.jar and jsr173_1.0_api.jar).<br>
<br>
The built classes will go into ${build.dir}.</div>
<div>
<p class=relatedtopics>Related Topics</p>
<p>None.</p>
</div>
</div>
<!-- InstanceEndEditable -->
</body>
<!-- InstanceEnd --></html>

View File

@@ -0,0 +1,531 @@
<!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>Getting Started with XMLBeans</title>
<!-- InstanceEndEditable -->
<!--(Meta)==========================================================-->
<meta http-equiv=Content-Type content="text/html; charset=$CHARSET;">
<!-- InstanceBeginEditable name="metatags" -->
<meta name="author" content="your name">
<meta name="description" content="A description of the topic contents.">
<meta name="keywords" content="keywords to help in searches">
<meta name="date last modified" content="10/25/02">
<!-- 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> Getting Started with XMLBeans</h1>
<div id="topictext">
<p>XMLBeans provides intuitive ways to handle XML that make it easier for you
to access and manipulate XML data and documents in Java. </p>
<p>Characteristics of XMLBeans approach to XML:</p>
</div>
<ul>
<li>
<div>It provides a familiar Java object-based view of XML data without losing
access to the original, native XML structure.</div>
</li>
<li>
<div>The XML's integrity as a document is not lost with XMLBeans. XML-oriented
APIs commonly take the XML apart in order to bind to its parts. With XMLBeans,
the entire XML instance document is handled as a whole. The XML data is
stored in memory as XML. This means that the document order is preserved
as well as the original element content with whitespace.</div>
</li>
<li>
<div>With types generated from schema, access to XML instances is through
JavaBean-like accessors, with get and set methods.</div>
</li>
<li>
<div>It is designed with XML schema in mind from the beginning &#8212; XMLBeans
supports all XML schema definitions.</div>
</li>
<li>Access to XML is fast.</li>
</ul>
<div>
<p>The starting point for XMLBeans is XML schema. A schema (contained in an
XSD file) is an XML document that defines a set of rules to which other XML
documents must conform. The XML Schema specification provides a rich data
model that allows you to express sophisticated structure and constraints on
your data. For example, an XML schema can enforce control over how data is
ordered in a document, or constraints on particular values (for example, a
birth date that must be later than 1900). Unfortunately, the ability to enforce
rules like this is typically not available in Java without writing custom
code. XMLBeans honors schema constraints.</p>
<p class="notepara"><strong>Note:</strong> Where an XML schema defines rules
for an XML document, an XML <em>instance</em> is an XML document that conforms
to the schema.</p>
<p>You compile a schema (XSD) file to generate a set of Java interfaces that
mirror the schema. With these types, you process XML instance documents that
conform to the schema. You bind an XML instance document to these types; changes
made through the Java interface change the underlying XML representation.</p>
<p>Previous options for handling XML include using XML programming interfaces
(such as DOM or SAX) or an XML marshalling/binding tool (such as JAXB). Because
it lacks strong schema-oriented typing, navigation in a DOM-oriented model
is more tedious and requires an understanding of the complete object model.
JAXB provides support for the XML schema specification, but handles only a
subset of it; XMLBeans supports all of it. Also, by storing the data in memory
as XML, XMLBeans is able to reduce the overhead of marshalling and demarshalling.</p>
<h1>Accessing XML Using Its Schema</h1>
<p>To get a glimpse of the kinds of things you can do with XMLBeans, take a
look at an example using XML for a purchase order. The purchase order XML
contains data exchanged by two parties, such as two companies. Both parties
need to be able to rely on a consistent message shape, and a schema specifies
the common ground. </p>
<p>Here's what a purchase order XML instance might look like.</p>
<pre>
&lt;po:purchase-order xmlns:po="http://openuri.org/easypo"&gt;
&lt;po:customer&gt;
&lt;po:name&gt;Gladys Kravitz&lt;/po:name&gt;
&lt;po:address&gt;Anytown, PA&lt;/po:address&gt;
&lt;/po:customer&gt;
&lt;po:date&gt;2003-01-07T14:16:00-05:00&lt;/po:date&gt;
&lt;po:line-item&gt;
&lt;po:description&gt;Burnham's Celestial Handbook, Vol 1&lt;/po:description&gt;
&lt;po:per-unit-ounces&gt;5&lt;/po:per-unit-ounces&gt;
&lt;po:price&gt;21.79&lt;/po:price&gt;
&lt;po:quantity&gt;2&lt;/po:quantity&gt;
&lt;/po:line-item&gt;
&lt;po:line-item&gt;
&lt;po:description&gt;Burnham's Celestial Handbook, Vol 2&lt;/po:description&gt;
&lt;po:per-unit-ounces&gt;5&lt;/po:per-unit-ounces&gt;
&lt;po:price&gt;19.89&lt;/po:price&gt;
&lt;po:quantity&gt;2&lt;/po:quantity&gt;
&lt;/po:line-item&gt;
&lt;po:shipper&gt;
&lt;po:name&gt;ZipShip&lt;/po:name&gt;
&lt;po:per-ounce-rate&gt;0.74&lt;/po:per-ounce-rate&gt;
&lt;/po:shipper&gt;
&lt;/po:purchase-order&gt;</pre>
<p>This XML includes a root element, <span class="langinline">purchase-order</span>,
that has three kinds of child elements: <span class="langinline">customer</span>,
<span class="langinline">date</span>, <span class="langinline">line-item</span>,
and <span class="langinline">shipper</span>. An intuitive, object-based view
of this XML would provide an object representing the <span class="langinline">purchase-order</span>
element, and it would have methods for getting the date and for getting subordinate
objects for <span class="langinline">customer</span>, <span class="langinline">line-item</span>,
and <span class="langinline">shipper</span> elements. Each of the last three
would have its own methods for getting the data inside them as well.</p>
<h2>Looking at the Schema</h2>
<p>The following XML is the the schema for the preceding purchase order XML.
It defines the XML's &quot;shape&quot; &#8212; what its elements are, what
order they appear in, which are children of which, and so on.</p>
</div>
<div>
<pre>
&lt;xs:schema targetNamespace="http://openuri.org/easypo"
xmlns:po="http://openuri.org/easypo"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified"&gt;
&lt;xs:element name="purchase-order"&gt;
&lt;xs:complexType&gt;
&lt;xs:sequence&gt;
&lt;xs:element name="customer" type="po:customer"/&gt;
&lt;xs:element name="date" type="xs:dateTime"/&gt;
&lt;xs:element name="line-item" type="po:line-item" minOccurs="0" maxOccurs="unbounded"/&gt;
&lt;xs:element name="shipper" type="po:shipper" minOccurs="0"/&gt;
&lt;/xs:sequence&gt;
&lt;/xs:complexType&gt;
&lt;/xs:element&gt;
&lt;xs:complexType name="customer"&gt;
&lt;xs:sequence&gt;
&lt;xs:element name="name" type="xs:string"/&gt;
&lt;xs:element name="address" type="xs:string"/&gt;
&lt;/xs:sequence&gt;
&lt;/xs:complexType&gt;
&lt;xs:complexType name="line-item"&gt;
&lt;xs:sequence&gt;
&lt;xs:element name="description" type="xs:string"/&gt;
&lt;xs:element name="per-unit-ounces" type="xs:decimal"/&gt;
&lt;xs:element name="price" type="xs:double"/&gt;
&lt;xs:element name="quantity" type="xs:int"/&gt;
&lt;/xs:sequence&gt;
&lt;/xs:complexType&gt;
&lt;xs:complexType name="shipper"&gt;
&lt;xs:sequence&gt;
&lt;xs:element name="name" type="xs:string"/&gt;
&lt;xs:element name="per-ounce-rate" type="xs:decimal"/&gt;
&lt;/xs:sequence&gt;
&lt;/xs:complexType&gt;
&lt;/xs:schema&gt;</pre>
<div>
<p>This schema describes the purchase order XML instance by defining the following:</p>
</div>
<ul>
<li>
<div>Definitions for three complex types &#8212; customer, line-item, and
shipper. These are the types used for the children of the purchase-order
element. In schema, a complex type is one that defines an element that
may have child elements and attributes. The sequence element nested in
the complex type lists its child elements.</div>
<p>These are also <em>global</em> types. They are global because they are
at the top level of the schema (in other words, just beneath the <span class="langinline">schema</span>
root element). This means that they may be referenced from anywhere else
in the schema.</p>
</li>
</ul>
</div>
<div>
<ul>
<li>Use of simple types within the complex types. The name, address, and description
elements (among others) are typed as simple types. As it happens, these
are also <em>built-in</em> types. A built-in type (here, one with the &quot;xs&quot;
prefix) is part of the schema specification. (The specification defines
46 built-in types.)</li>
<li>A global element called purchase-order. This element definition includes
a nested complex type definition that specifies the child elements for a
purchase-order element. Notice that the complex type includes references
to the other complex types defined in this schema.</li>
</ul>
<div></div>
<p>In other words, the schema defines types for the child elements and describes
their position as subordinate to the root element, <span class="langinline">purchase-order</span>.</p>
<p>When you use the XMLBean compiler with an XSD file such as this one, you
generate a JAR file containing the interfaces generated from the schema.</p>
<h2>Writing Java Code That Uses the Interfaces</h2>
<p>With the XMLBeans interfaces in your application, you can write code that
uses the new types to handle XML based on the schema. Here's an example that
extracts information about each of the ordered items in the purchase order
XML, counts the items, and calculates a total of their prices. In particular,
look at the use of types generated from the schema and imported as part of
the <span class="langinline">org.openuri.easypo</span> package. </p>
<p>The <span class="langinline">printItems</span> method receives a <span class="langinline">File</span>
object containing the purchase order XML file.</p>
<pre>
package docs.xmlbeans;
import java.io.File;
import org.apache.xmlbeans.*;
import org.openuri.easypo.PurchaseOrderDocument;
import org.openuri.easypo.PurchaseOrder;
import org.openuri.easypo.LineItem;
public class POHandler
{
public static void printItems(File po) throws Exception
{
/*
* All XMLBeans schema types provide a nested Factory class you can
* use to bind XML to the type, or to create new instances of the type.
* Note that a "Document" type such as this one is an XMLBeans
* construct for representing a global element. It provides a way
* for you to get and set the contents of the entire element.
*
* Also, note that the parse method will only succeed if the
* XML you're parsing appears to conform to the schema.
*/
PurchaseOrderDocument poDoc =
PurchaseOrderDocument.Factory.parse(po);
/*
* The PurchaseOrder type represents the purchase-order element's
* complex type.
*/
PurchaseOrder po = poDoc.getPurchaseOrder();
/*
* When an element may occur more than once as a child element,
* the schema compiler will generate methods that refer to an
* array of that element. The line-item element is defined with
* a maxOccurs attribute value of "unbounded", meaning that
* it may occur as many times in an instance document as needed.
* So there are methods such as getLineItemArray and setLineItemArray.
*/
LineItem[] lineitems = po.getLineItemArray();
System.out.println("Purchase order has " + lineitems.length + " line items.");
double totalAmount = 0.0;
int numberOfItems = 0;
/*
* Loop through the line-item elements, using generated accessors to
* get values for child elements such a description, quantity, and
* price.
*/
for (int j = 0; j < lineitems.length; j++)
{
System.out.println(" Line item: " + j);
System.out.println(
" Description: " + lineitems[j].getDescription());
System.out.println(" Quantity: " + lineitems[j].getQuantity());
System.out.println(" Price: " + lineitems[j].getPrice());
numberOfItems += lineitems[j].getQuantity();
totalAmount += lineitems[j].getPrice() * lineitems[j].getQuantity();
}
System.out.println("Total items: " + numberOfItems);
System.out.println("Total amount: " + totalAmount);
}
}
</pre>
<p>Notice that types generated from the schema reflect what's in the XML:</p>
</div>
<ul>
<li>
<div>A <span class="langinline">PurchaseOrderDocument</span> represents the
global root element.</div>
</li>
<li>
<div>A <span class="langinline">getPurchaseOrder</span> method returns a <span class="langinline">PurchaseOrderDocument.PurchaseOrder</span>
type that contains child elements, including <span class="langinline">line-item</span>.
A <span class="langinline">getLineItemArray</span> method returns a <span class="langinline">LineItem</span>
array containing the <span class="langinline">line-item</span> elements.</div>
</li>
<li>Other methods, such as <span class="langinline">getQuantity</span>, <span class="langinline">getPrice</span>,
and so on, follow naturally from what the schema describes, returning corresponding
children of the <span class="langinline">line-item</span> element.</li>
<li>The name of the package containing these types is derived from the schema's
target namespace.</li>
</ul>
<div>
<p>Capitalization and punctuation for generated type names follow Java convention.
Also, while this example parses the XML from a file, other <span class="langinline">parse</span>
methods support a Java <span class="langinline">InputStream</span> object,
a <span class="langinline">Reader</span> object, and so on.</p>
<p>The preceding Java code prints the following to the console:</p>
</div>
<div>
<pre>
Purchase order has 3 line items.
Line item 0
Description: Burnham's Celestial Handbook, Vol 1
Quantity: 2
Price: 21.79
Line item 1
Description: Burnham's Celestial Handbook, Vol 2
Quantity: 2
Price: 19.89
Total items: 4
Total amount: 41.68</pre>
<h2>Creating New XML Instances from Schema</h2>
<p>As you've seen XMLBeans provides a &quot;factory&quot; class you can use
to create new instances. The following example creates a new <span class="langinline">purchase-order</span>
element and adds a <span class="langinline">customer</span> child element.
It then inserts <span class="langinline">name</span> and <span class="langinline">address</span>
child elements, creating the elements and setting their values with a single
call to their <span class="langinline">set</span> methods.</p>
<pre>
public PurchaseOrderDocument createPO()
{
&nbsp;&nbsp;&nbsp;&nbsp;PurchaseOrderDocument newPODoc = PurchaseOrderDocument.Factory.newInstance();
&nbsp;&nbsp;&nbsp;&nbsp;PurchaseOrder newPO = newPODoc.addNewPurchaseOrder();
&nbsp;&nbsp;&nbsp;&nbsp;Customer newCustomer = newPO.addNewCustomer();
&nbsp;&nbsp;&nbsp;&nbsp;newCustomer.setName(&quot;Doris Kravitz&quot;);
&nbsp;&nbsp;&nbsp;&nbsp;newCustomer.setAddress(&quot;Bellflower, CA&quot;);
&nbsp;&nbsp;&nbsp;&nbsp;return newPODoc;
}
</pre>
<p>The following is the XML that results. Note that XMLBeans assigns the correct
namespace based on the schema, using an &quot;ns1&quot; (or, &quot;namespace
1&quot;) prefix. For practical purposes, the prefix itself doesn't really
matter &#8212; it's the namespace URI (http://openuri.org/easypo) that defines
the namespace. The prefix is merely a marker that represents it.</p>
<pre>&lt;ns1:purchase-order xmlns:ns1=&quot;http://openuri.org/easypo&quot;&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;ns1:customer&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;ns1:name&gt;Doris Kravitz&lt;/ns1:name&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;ns1:address&gt;Bellflower, CA&lt;/ns1:address&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;/ns1:customer&gt;
&lt;/ns1:purchase-order&gt;
</pre>
<p>Note that all types (including those generated from schema) inherit from
<span class="langinline">XmlObject</span>, and so provide a <span class="langinline">Factory</span>
class. For an overview of the type system in which <span class="langinline">XmlObject</span>
fits, see <a href="conXMLBeansSupportBuiltInSchemaTypes.html">XMLBeans Support
for Built-In Schema Types</a>. For reference information, see <a href="../reference/org/apache/xmlbeans/XmlObject.html">XmlObject
Interface</a>.</p>
<h1>XMLBeans Hierarchy</h1>
<p>The generated types you saw used in the preceding example are actually part
of a hierarchy of XMLBeans types. This hierarchy is one of the ways in which
XMLBeans presents an intuitive view of schema. At the top of the hierarchy
is <span class="langinline">XmlObject</span>, the base interface for XMLBeans
types. Beneath this level, there are two main type categories: generated types
that represent user-derived schema types, and included types that represent
built-in schema types.</p>
This topic has already introduced generated types. For more information, see
<a href="conJavaTypesGeneratedFromUserDerived.html">Java Types Generated from
User-Derived Schema Types.</a>
<h2>Built-In Type Support</h2>
<p>In addition to types generated from a given schema, XMLBeans provides 46
Java types that mirror the 46 built-in types defined by the XML schema specification.
Where schema defines <span class="langinline">xs:string</span>, <span class="langinline">xs:decimal</span>,
and <span class="langinline">xs:int</span>, for example, XMLBeans provides
<span class="langinline"><a href="../reference/org/apache/xmlbeans/XmlString.html">XmlString</a></span>,
<span class="langinline"><a href="../reference/org/apache/xmlbeans/XmlDecimal.html">XmlDecimal</a></span>,
and <span class="langinline"><a href="../reference/org/apache/xmlbeans/XmlInt.html">XmlInt</a></span>.
Each of these also inherits from <span class="langinline">XmlObject</span>,
which corresponds to the built-in schema type <span class="langinline">xs:anyType</span>.</p>
<p>XMLBeans provides a way for you to handle XML data as these built-in types.
Where your schema includes an element whose type is, for example, <span class="langinline">xs:int</span>,
XMLBeans will provide a generated method designed to return an <span class="langinline">XmlInt</span>.
In addition, as you saw in the preceding example, for most types there will
also be a method that returns a natural Java type such as <span class="langinline">int</span>.
The following two lines of code return the <span class="langinline">quantity</span>
element's value, but return it as different types.</p>
<pre>
// Methods that return simple types begin with an "x".
XmlInt xmlQuantity = lineitems[j].xgetQuantity();
// Methods that return a natural Java type are unadorned.
int javaQuantity = lineitems[j].getQuantity();
</pre>
<p>In a sense both get methods navigate to the <span class="langinline">quantity</span>
element; the <span class="langinline">getQuantity</span> method goes a step
further and converts the elements value to the most appropriate natural Java
type before returning it. (XMLBeans also provides a means for validating the
XML as you work with it.)</p>
<p>If you know a bit about XML schema, XMLBeans types should seem fairly intuitive.
If you don't, you'll learn a lot by experimenting with XMLBeans using your
own schemas and XML instances based on them. </p>
<p>For more information on the methods of types generated from schema, see <a href="conMethodsForGeneratedJavaTypes.html">Methods
for Types Generated From Schema</a>. For more about the how XMLBeans represents
built-in schema types, see <a href="conXMLBeansSupportBuiltInSchemaTypes.html">XMLBeans
Support for Built-In Schema Types</a>.</p>
<h1>Using XQuery Expressions</h1>
<p>With XMLBeans you can use XQuery to query XML for specific pieces of data.
XQuery is sometimes referred to as &quot;SQL for XML&quot; because it provides
a mechanism to access data directly from XML documents, much as SQL provides
a mechanism for accessing data in traditional databases.</p>
<p>XQuery borrows some of its syntax from XPath, a syntax for specifying nested
data in XML. The following example returns all of the <span class="langinline">line-item</span>
elements whose <span class="langinline">price</span> child elements have values
less than or equal to 20.00:</p>
<pre>
PurchaseOrderDocument doc = PurchaseOrderDocument.Factory.parse(po);
/*
* The XQuery expression is the following two strings combined. They're
* declared separately here for convenience. The first string declares
* the namespace prefix that's used in the query expression; the second
* declares the expression itself.
*/
String nsText = "declare namespace po = 'http://openuri.org/easypo'; ";
String pathText = "$this/po:purchase-order/po:line-item[po:price <= 20.00]";
String queryText = nsText + pathText;
XmlCursor itemCursor = doc.newCursor().execQuery(queryText);
System.out.println(itemCursor.xmlText());
</pre>
<p>This code creates a new cursor at the start of the document. From there,
it uses the <span class="langinline">XmlCursor</span> interface's <span class="langinline">execQuery</span>
method to execute the query expression. In this example, the method's parameter
is an XQuery expression that simply says, &quot;From my current location,
navigate through the <span class="langinline">purchase-order</span> element
and retrieve those <span class="langinline">line-item</span> elements whose
value is less than or equal to 20.00.&quot; The <span class="langinline">$this</span>
variable means &quot;the current position.&quot;</p>
<p>For more information about XQuery, see <a href="http://www.w3.org/TR/xquery/" target="_blank">XQuery
1.0: An XML Query Language</a> at the W3C web site.</p>
<h2>Using XML Cursors</h2>
<p>In the preceding example you may have noticed the <span class="langinline"><a href="../reference/org/apache/xmlbeans/XmlCursor.html">XmlCursor</a></span>
interface. In addition to providing a way to execute XQuery expression, an
XML cursors offers a fine-grained model for manipulating data. The XML cursor
API, analogous to the DOM's object API, is simply a way to point at a particular
piece of data. So, just like a cursor helps navigate through a word processing
document, the XML cursor defines a location in XML where you can perform actions
on the selected XML.</p>
<p>Cursors are ideal for moving through an XML document when there's no schema
available. Once you've got the cursor at the location you're interested in,
you can perform a variety of operations with it. For example, you can set
and get values, insert and remove fragments of XML, copy fragments of XML
to other parts of the document, and make other fine-grained changes to the
XML document.</p>
<p>The following example uses an XML cursor to navigate to the <span class="langinline">customer</span>
element's <span class="langinline">name</span> child element.</p>
<pre>
PurchaseOrderDocument doc =
PurchaseOrderDocument.Factory.parse(po);
XmlCursor cursor = doc.newCursor();
cursor.toFirstContentToken();
cursor.toFirstChildElement();
cursor.toFirstChildElement();
System.out.println(cursor.getText());
cursor.dispose();
</pre>
<p>What's happening here? As with the earlier example, the code loads the XML
from a <span class="langinline">File</span> object. After loading the document,
the code creates a cursor at its beginning. Moving the cursor a few times
takes it to the nested <span class="langinline">name </span> element. Once
there, the getText method retrieves the element's value.</p>
<p>This is just an introduction to XML cursors. For more information about using
cursors, see <a href="conNavigatingXMLwithCursors.html">Navigating XML with
Cursors</a>.</p>
<h2>Where to Go Next</h2>
</div>
<ul>
<li>
<div>XMLBeans provides intuitive ways to handle XML, particularly if you're
starting with schema. If you're accessing XML that's based on a schema,
you'll probably find it most efficient to access the XML through generated
types specific to the schema. To do this, you begin by compiling the schema
to generate interfaces. For more information on using XMLBeans types generated
by compiling schema, see <a href="conJavaTypesGeneratedFromUserDerived.html">Java
Types Generated From User-Derived Schema Types</a> and <a href="conMethodsForGeneratedJavaTypes.html">Methods
for Types Generated From Schema</a>.</div>
</li>
<li>
<div>You might be interested in reading more about the type system on which
XMLBeans is based, particularly if you're using types generated from schema.
XMLBeans provides a hierarchical system of types that mirror what you find
in the XML schema specification itself. If you're working with schema, you
might find it helps to understand how these types work. For more information,
see <a href="conXMLBeansSupportBuiltInSchemaTypes.html">XMLBeans Support
for Built-In Schema Types</a> and <a href="conIntroToTheSchemaTypeSystem.html">Introduction
to Schema Type Signatures</a>.</div>
</li>
<li>
<div>XMLBeans provides access to XML through XQuery, which borrows path syntax
from XPath. With XQuery, you can specify specific fragments of XML data
with or without schema. To learn more about using XQuery and XPath in XMLBeans,
see <a href="conSelectingXMLwithXQueryPathXPath.html">Selecting XML with
XQuery and XPath</a>.</div>
</li>
<li>You can use the <span class="langinline">XmlCursor</span> interface for
fine-grained navigation and manipulation of XML. For more information, see
<a href="conNavigatingXMLwithCursors.html">Navigating XML with Cursors</a>.</li>
</ul>
<div>
<p class="notepara"><strong>Note:</strong> The xbean.jar file that contains
the XMLBeans library is fully functional as a standalone library.</p>
<h1>Related Topics</h1>
<p><a href="../../samples/navXMLBeansSamples.html">XMLBeans Samples</a></p>
</div>
<!-- InstanceEndEditable -->
<script language="JavaScript">
</script>
</body>
</html>

View File

@@ -0,0 +1,256 @@
<!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>Handling xs:any with the XMLBeans API </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> Handling xs:any with the XMLBeans API </h1>
<p>Compiling schema for use with XMLBeans generates a kind of custom API specific to your schema. This API includes types with accessors designed to get and set parts of the XML defined by the schema. But if you've compiled schema that includes <code>xs:any</code> particles, you may have noticed that XMLBeans doesn't generate accessors for these these particles. </p>
<p>For example, imagine the accessors generated by compiling the following schema snippet: </p>
<div id="topictext"><pre>&lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://xmlbeans.apache.org/samples/any"
targetNamespace="http://xmlbeans.apache.org/samples/any" elementFormDefault="qualified">
&lt;xs:element name="root">
&lt;xs:complexType>
&lt;xs:sequence>
&lt;xs:element ref="stringelement"/>
&lt;xs:any processContents="lax"/>
&lt;xs:element name="arrayofany">
&lt;xs:complexType>
&lt;xs:sequence>
&lt;xs:any namespace="##any" processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
&lt;/xs:sequence>
&lt;/xs:complexType>
&lt;/xs:element>
&lt;/xs:sequence>
&lt;/xs:complexType>
&lt;/xs:element>
&lt;xs:element name="stringelement" type="xs:string"/>
&lt;xs:complexType name="ListOfStrings">
&lt;xs:sequence>
&lt;xs:element ref="stringelement" minOccurs="0" maxOccurs="unbounded"/>
&lt;/xs:sequence>
&lt;xs:attribute name="id" type="xs:string"/>
&lt;/xs:complexType>
&lt;/xs:schema></pre>
<p>After compilation, you'd have the follow methods for <code>Root</code>, the type that gives you access to the <code>&lt;root&gt;</code> element:</p>
<p><code>addNewArrayofany()</code></p>
<p><code>getArrayofany()</code></p>
<p><code>getStringelement()</code></p>
<p><code>setArrayofany(Arrayofany)</code></p>
<p><code>setStringelement(String)</code></p>
<p><code>xgetStringelement()</code></p>
<p><code>xsetStringelement(XmlString)</code></p>
<p>What's missing? There's no <code>getAny</code> or <code>setAny</code>. How do you get or set the <code>&lt;root&gt;</code> element's second child? As it turns out, you do this by leaving behind (at least for a moment) JavaBeans-style accessors, and picking up any of a number of tools the API provides. These tools include:</p>
<ul>
<li><a href="#using_cursors">Using <code>XmlCursor</code> instances</a> to &quot;walk&quot; the XML, handling elements cursor-style.</li>
<li><a href="#using_xpath">Using the <code>selectPath</code> method</a> to retrieve the XML you want via XPath.</li>
<li><a href="#using_selectchildren">Using the <code>selectChildren</code> method</a> to retrieve child elements by name.</li>
<li> <a href="#using_dom">Using the DOM API</a> to &quot;walk&quot; the node tree, handling elements by name.</li>
</ul>
<h2><a name="using_cursors"></a>Using Cursors to Add XML </h2>
<p>As described in <a href="conNavigatingXMLwithCursors.html">Navigating XML with Cursors</a>, with an <code>XmlCursor</code> instance you can traverse your XML instance's full infoset. A cursor views XML as tokens, and you move a cursor from one token to another as if they were cars in a train.</p>
<p>The following example illustrates how you might, in the course of building out the <code>&lt;root&gt;</code> document, create a second child element <code>&lt;anyfoo&gt;</code> where schema specifies <code>xs:any</code>. You add the element by creating it with a cursor, then (in lieu of a setter) using the <code>XmlCursor.copyXml</code> or <code>XmlCursor.moveXml</code> method to put the element where it needs to go.</p>
<pre>// Start by creating a &lt;root> element that will contain
// the children built by this code.
RootDocument rootDoc = RootDocument.Factory.newInstance();
RootDocument.Root root = rootDoc.addNewRoot();
// Add the first element, &lt;stringelement>.
root.setStringelement("some text");
// Create an XmlObject in which to build the second
// element in the sequence, &lt;anyfoo>. Here, the
// XmlObject instance is simply a kind of incubator
// for the XML. Later the XML will be moved into the
// document this code is building.
XmlObject anyFoo = XmlObject.Factory.newInstance();
// Add a cursor to do the work of building the XML.
XmlCursor anyFooCursor = anyFoo.newCursor();
anyFooCursor.toNextToken();
// Add the element in the schema's namespace, then add
// element content.
anyFooCursor.beginElement(new QName(m_namespaceUri, "anyfoo"));
anyFooCursor.insertChars("some text");
// Move the cursor back to the new element's top, where
// it can grab all of the element's XML.
anyFooCursor.toStartDoc();
anyFooCursor.toNextToken();
// Finally, move the XML into the &lt;root> document by moving it
// from a position at one cursor to a position at
// another.
XmlCursor rootCursor = root.newCursor();
rootCursor.toEndToken();
anyFooCursor.moveXml(rootCursor);</pre>
<p>You might find that this build-and-move-cursor-to-cursor pattern is common when you're creating or moving XML when accessors aren't available. For example, you could do the same sort of thing when your schema defines a type that you want to place into an <code>xs:any</code> space in an instance. The following code adds a <code>&lt;stringelement&gt; </code>element as a child of the <code>&lt;arrayofany&gt;</code> element, which schema defines as containing a sequence of <code>xs:any</code> particles. The <code>&lt;stringlement&gt;</code> element is simple, but it could just as easily be a complex schema type.</p>
<pre>// Create a simple &lt;stringelement>.
StringelementDocument stringElementDoc =
StringelementDocument.Factory.newInstance();
stringElementDoc.setStringelement("some text");
XmlCursor stringElementCursor = stringElementDoc.newCursor();
stringElementCursor.toFirstContentToken();
// Add a cursor to mark the position to which the new child
// XML will be moved.
XmlCursor arrayCursor = arrayOfAny.newCursor();
arrayCursor.toNextToken();
// Move the new &lt;stringelement> into place.
stringElementCursor.moveXml(arrayCursor);
stringElementCursor.dispose();</pre>
<h2><a name="using_xpath"></a>Using XPath and the selectPath Method to Find XML </h2>
<p>XPath is a convenient, direct way to get at specific chunks of XML. In the XMLBeans API, you execute XPath expressions with the <code>XmlObject.selectPath</code> or <code>XmlCursor.selectPath</code> methods. The example in Java below assumes the following instance conforming to the schema introduced at the beginning of this topic:</p>
<pre>&lt;root xmlns="http://xmlbeans.apache.org/samples/any">
&lt;stringelement>some text&lt;/stringelement>
&lt;anyfoo>some text&lt;/anyfoo>
&lt;arrayofany>
&lt;stringelement>some text&lt;/stringelement>
&lt;someelement>
&lt;stringlist id="001">
&lt;stringelement>string1&lt;/stringelement>
&lt;stringelement>string2&lt;/stringelement>
&lt;/stringlist>
&lt;/someelement>
&lt;/arrayofany>
&lt;/root></pre>
<p>The following code uses XPath to reach the <code>&lt;stringelement&gt;</code> element because there is no accessor available. It then shifts the XML around a little, moving <code>&lt;stringelement&gt;</code> up in the hierarchy to replace its parent, <code>&lt;someelement&gt;</code>. </p>
<pre>public boolean editExistingDocWithSelectPath(RootDocument rootDoc)
{
String namespaceUri = "http://xmlbeans.apache.org/samples/any";
// Put a cursor at the top of the &lt;arrayofany> element.
XmlCursor selectionCursor = rootDoc.getRoot().getArrayofany().newCursor();
// Use XPath and cursor movement to position the cursor at
// the &lt;stringlist> element.
String namespaceDecl = "declare namespace any='" + namespaceUri + "'; ";
selectionCursor.selectPath(namespaceDecl +
"$this//any:someelement/any:stringlist");
selectionCursor.toNextSelection();
// Create a new cursor at the same location and move it to
// &lt;stringelement&gt;'s &lt;someelement> parent.
XmlCursor editCursor = selectionCursor.newCursor();
editCursor.toParent();
// Move the &lt;stringelement> element to this position, displacing
// the &lt;someelement> downward. Remove the &lt;someelement> XML,
// effectively replacing &lt;someelement> with &lt;stringlist>.
selectionCursor.moveXml(editCursor);
editCursor.removeXml();
editCursor.dispose();
return rootDoc.validate();
}</pre>
<h2><a name="using_selectchildren"></a>Using the selectChildren Method to Find XML </h2>
<p>The <code>XmlObject.selectChildren</code> method you can retrieve an array of the child elements of a specified name. The method is overloaded to take <code>java.xml.namespace.QName</code> instances or strings as parameters. The following code (based on the instance used in the preceding example) simply finds the <code>&lt;anyfoo&gt;</code> element, an <code>xs:any</code>, and replaces it with an <code>&lt;anybar&gt;</code> element. </p>
<pre>public boolean editExistingDocWithSelectChildren(RootDocument rootDoc)
{
String namespaceUri = "http://xmlbeans.apache.org/samples/any";
RootDocument.Root root = rootDoc.getRoot();
// Select the &lt;anyfoo> children of &lt;root>.
XmlObject[] stringElements =
root.selectChildren(new QName(m_namespaceUri, "anyfoo"));
// If the element is there, replace it with another element.
if (stringElements.length > 0)
{
XmlCursor editCursor = stringElements[0].newCursor();
editCursor.removeXml();
editCursor.beginElement(new QName(namespaceUri, "anybar"));
editCursor.insertChars("some other text");
editCursor.dispose();
}
return rootDoc.validate();
}</pre>
<h2><a name="using_dom"></a>Using the DOM API to Find XML </h2>
<p>Through the <code>getDomNode</code> method (exposed by <code>XmlObject</code> and types generated from schema), you can get a live DOM node representing your XML. For example, calling <code>myElement.getDomNode()</code> will return a <code>org.w3c.dom.Node</code> instance representing the XML bound to <code>myElement</code>. If you're already familiar with DOM-style access to XML, this can be a familiar alternative for handling <code>xs:any</code> instances.</p>
<p> Using the instance introduced earlier in this topic, the following example adds a new <code>&lt;bar&gt;</code> element between the first and second children of the <code>&lt;arrayofany&gt;</code> element. The code also ensures that the first and second children are <code>&lt;stringelement&gt;</code> and <code>&lt;someelement&gt;</code>, respectively.</p>
<pre>public boolean editExistingDocWithDOM(RootDocument rootDoc)
{
RootDocument.Root root = rootDoc.getRoot();
// Get the DOM nodes for the &lt;arrayofany> element's children.
Node arrayOfAnyNode = root.getArrayofany().getDomNode();
// You don't have get* accessors for any of the &lt;arrayofany>
// element's children, so use DOM to identify the first
// and second elements while looping through the child list.
NodeList childList = arrayOfAnyNode.getChildNodes();
Element firstElementChild = null;
Element secondElementChild = null;
// Find the first child element and make sure it's
// &lt;stringelement>.
for (int i = 0; i < childList.getLength(); i++)
{
Node node = childList.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE)
{
if (node.getLocalName().equals("stringelement"))
{
firstElementChild = (Element)node;
break;
}
}
}
if (firstElementChild == null) {return false;}
// Find the second child element and make sure it's
// &lt;someelement>.
Node node = firstElementChild.getNextSibling();
do
{
if (node.getNodeType() == Node.ELEMENT_NODE)
{
if (node.getLocalName().equals("someelement"))
{
secondElementChild = (Element)node;
break;
}
}
node = node.getNextSibling();
} while (node != null);
if (secondElementChild == null) {return false;}
// Create and insert a new &lt;bar> element.
Element fooElement =
secondElementChild.getOwnerDocument().createElementNS("http://openuri.org","bar");
Node valueNode =
fooElement.getOwnerDocument().createTextNode("some text");
fooElement.appendChild(valueNode);
arrayOfAnyNode.insertBefore(fooElement, secondElementChild);
return rootDoc.validate();
}</pre>
</div>
<div>
<h2>Related Topics</h2>
</div>
<p><a href="conGettingStartedwithXMLBeans.html">Getting Started with XMLBeans</a></p>
<!-- InstanceEndEditable -->
<script language="JavaScript">
</script>
</body>
</html>

View File

@@ -0,0 +1,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>

View File

@@ -0,0 +1,471 @@
<!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>Java Types Generated from Schema</title>
<!-- InstanceEndEditable -->
<!--(Meta)==========================================================-->
<meta http-equiv=Content-Type content="text/html; charset=$CHARSET;">
<!-- InstanceBeginEditable name="metatags" -->
<meta name="component" content="">
<!-- In the description metatag, please provide a BRIEF description of the topic contents. -->
<meta name="description" content="">
<!-- In the component metatag, please list keywords that will help a user search for this topic. -->
<meta name="keywords" content="">
<!-- InstanceEndEditable -->
<!--(Links)=========================================================-->
<!-- InstanceBeginEditable name="head" -->
<link href="../xmlbeans.css" rel="stylesheet" type="text/css">
<!--(Meta)==========================================================-->
<meta name="author" content="your name">
<meta name="description" content="A description of the topic contents.">
<meta name="keywords" content="keywords to help in searches">
<meta name="date last modified" content="10/25/02">
<!--(Links)=========================================================-->
<!--(Body)==========================================================--><!-- 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> Java Types Generated from User-Derived Schema Types</h1>
<div id="topictext">
<p>When you compile XML schema, the resulting API is made up of two categories
of types: built-in types that mirror those in the schema specification and
others that are generated from user-derived schema types. This topic provides
an overview of the Java types generated for user-derived types, describing
the methods the Java types provide. For more information about built-in types,
see <a href="conXMLBeansSupportBuiltInSchemaTypes.html">XMLBeans Support for
Built-In Schema Types</a>. For specific information about the methods exposed
by generated types, see <a href="conMethodsForGeneratedJavaTypes.html">Methods
for Generated Java Types</a>.</p>
<p>In general, an API generated from schema is an intuitive means to access
XML instances based on the schema. You'll probably find that for most uses
it's unnecessary to know the rules for generating it in order to use it. However,
for those cases when it's unclear what's going on behind the scenes (or if
you're just curious), this topic describes the rules.</p>
<p class="notepara"><strong>Note:</strong> The XMLBeans API also provides a
way for you to get information <em>about </em>the type system itself &#8212;
in other words, about the API and the underlying schema. For more information,
see <a href="conIntroToTheSchemaTypeSystem.html">Introduction to Schema Type
Signatures</a>.</p>
<p>Each of the types generated when you compile a schema is designed specifically
for access to XML instances conforming to that part of the schema. Start by
taking a look at a simple XML and schema example. The following schema describes
an XML document to contain a stock price quote.</p>
<pre>&lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;
&lt;xs:element name="price-quote"&gt;
&lt;xs:complexType&gt;
&lt;xs:sequence&gt;
&lt;xs:element name="stock-symbol" type="xs:string"/&gt;
&lt;xs:element name="stock-price" type="xs:float"/&gt;
&lt;/xs:sequence&gt;
&lt;/xs:complexType&gt;
&lt;/xs:element&gt;
&lt;/xs:schema&gt;
</pre>
<p>The following is an example of XML that conforms to this schema.</p>
<pre>&lt;price-quote&gt;
&lt;stock-symbol&gt;BEAS&lt;/stock-symbol&gt;
&lt;stock-price&gt;59.21&lt;/stock-price&gt;
&lt;/price-quote&gt;</pre>
<p>When you compile this schema, you get two generated XMLBeans interfaces:
<span class="langinline"> PriceQuoteDocument</span> and <span class="langinline">PriceQuoteDocument.PriceQuote</span>.</p>
<p>From the schema point of view, the generated <span class="langinline">PriceQuote</span>
interface represents the <em>complex type</em> you see inside the schema's
<span class="langinline">price-quote</span> element declaration. Looking at
the XML instance, you can see that this complex type translates into a sequence
of two elements, <span class="langinline">stock-symbol</span> and <span class="langinline">stock-price</span>.
So it's not surprising that the <span class="langinline">PriceQuote</span>
interface exposes methods such as <span class="langinline">getStockPrice</span>
and <span class="langinline">setStockPrice</span> to set the value <span class="langinline">stock-price</span>
element.</p>
<p>The <span class="langinline">PriceQuoteDocument</span> interface, on the
other hand, represents the <span class="langinline">price-quote</span> <em>document</em>
that contains the root <span class="langinline">price-quote</span> element.
XMLBeans creates a special &quot;document&quot; type for global element types.
A document type provides a way for you to get and set the value of the underlying
type, here represented by <span class="langinline">PriceQuote</span>. The
<span class="langinline">price-quote</span> element is considered a <em>global</em>
element because it can be referenced from anywhere else in the schema. For
global elements, the XMLBeans schema compiler generates an interface whose
name ends with &quot;Document.&quot; This is because an XML schema has no
way of defining a &quot;root&quot; element; any global element can be the
root.</p>
<p>The following bit of Java code illustrates how you might use these interfaces
to get the stock price contained in the XML.</p>
<pre>
public static float getStockPrice(java.io.File orderXML) throws Exception
{
PriceQuoteDocument docXML = PriceQuoteDocument.Factory.parse(orderXML);
PriceQuote quoteXML = docXML.getPriceQuote();
float stockPrice = quoteXML.getStockPrice();
return stockPrice;
}
</pre>
<p>This code loads the XML from a <span class="langinline">File</span> object,
converting the <span class="langinline">parse</span> method's return value
to a <span class="langinline">PriceQuoteDocument</span> instance. It then
uses this instance to get an instance of <span class="langinline">PriceQuote</span>.
With <span class="langinline">PriceQuote</span>, the code extracts the stock
price. </p>
</div>
<div>
<div id="topictext">
<p>The XML schema specification provides a rich set of rules through which
you can derive new types. When you generate interfaces from your schema,
XMLBeans uses the schema's rules to determine how to generate interfaces.
The following describes some of the guidelines by which this is done.</p>
<h2>Names for Interfaces</h2>
<p>Interfaces are generated for schema types (both simple and complex). Anonymous
schema types result in inner interfaces inside the type interface in which
they are defined. Their name comes from the element or attribute in which
they is defined.</p>
<p>Names for schema types become Java-friendly names when the schema is compiled.
In other words, names such as "price-quote" become "PriceQuote." In addition,
a schema's XML namespace URIs become package names for XMLBean types generated
from the schema. The way this name translation is done is described by section
C of the Java API for XML Binding (JAXB) specification at <a href="http://java.sun.com/xml/downloads/jaxb.html" target="_blank">
http://java.sun.com/xml/jaxb.html.</a> </p>
<p>Here are a few examples:</p>
<table>
<tr>
<td><strong>Schema Target Namespace</strong></td>
<td width="155"><strong>XML Localname</strong></td>
<td><strong>Fully-Qualified XMLBean Type Name</strong></td>
</tr>
<tr>
<td>http://www.mycompany.com/2002/buyer</td>
<td width="155">purchase-order-4</td>
<td>com.mycompany.x2002.buyer.PurchaseOrder4</td>
</tr>
<tr>
<td>http://myco.com/sample.html</td>
<td width="155">SampleDocument</td>
<td>com.myco.sample.SampleDocument</td>
</tr>
<tr>
<td>http://openuri.org/test_case_1</td>
<td width="155">test_type</td>
<td>org.openuri.testCase1.TestType</td>
</tr>
</table>
<p>When there are name collisions, the generated types will have names with
numerals appended&nbsp;— for example, "TestType2".</p>
<h2>Global Elements and Attributes</h2>
<p>In schema, global element and attribute definitions are those that are
declared at the top level of the schema (that is, immediately within the
<span class="langinline">schema</span> root element). Because they are global,
they may be referenced from inside the schema by name. The <span class="langinline">creditReport</span>
(not the <span class="langinline">creditReportType</span> complex type)
element defined in the following schema is an example.</p>
<pre>
&lt;xs:schema targetNamespace=&quot;http://openuri.org/samples/creditReport&quot;
xmlns:cr=&quot;http://openuri.org/samples/creditReport&quot;
xmlns:xs=&quot;http://www.w3.org/2001/XMLSchema&quot;
elementFormDefault=&quot;qualified&quot;
attributeFormDefault=&quot;unqualified&quot;&gt;
&lt;xs:complexType name=&quot;creditReportType&quot;&gt;
&lt;xs:sequence&gt;
&lt;xs:element name=&quot;bankReport&quot; type=&quot;xs:string&quot;/&gt;
&lt;xs:element name=&quot;taxReport&quot; type=&quot;xs:string&quot;/&gt;
&lt;/xs:sequence&gt;
&lt;/xs:complexType&gt;
&lt;xs:element name=&quot;creditReport&quot; type=&quot;cr:creditReportType&quot;/&gt;
&lt;/xs:schema&gt;</pre>
<p>XMLBeans generates a separate interface for each of these. Also, global
element and attribute types are somewhat unique in that the schema compiler
will create special types to hold the globally defined element or attribute.
The names of these types will be appended with &quot;Document&quot; (for
elements) or &quot;Attribute&quot; (for attributes). You can retrieve the
element or attribute itself (or create a new one) by calling the accessor
methods that the special types provide. The following example would create
a new instance of the creditReport element.</p>
<pre>
// Create an instance of the special document type.
CreditReportDocument reportDoc = CreditReportDocument.Factory.newInstance();
/*
* Use the document type to add a new creditReport element to the XML instance.
* Note that the type returned by the addNewCreditReport method is the
* creditReportType complex type defined for it in schema.
*/
CreditReportType report = reportDoc.addNewCreditReport();
</pre>
<h2>Global User-Derived Types</h2>
<p>A <em>user-derived</em> type is one defined with a <span class="langinline">complexType</span>
or <span class="langinline">simpleType</span> element in schema. User-derived
types at the top level of a schema are global. XMLBeans generates an interface
for each of these, as it does with global elements and attributes. These
interfaces include methods through which you can get and set the type's
values, including any nested derived types it may contain. The following
schema snippet defines a user-derived complex type called <span class="langinline">itemType</span>,
along with a <span class="langinline">priceType</span> that uses it as the
type for an <span class="langinline">item</span> child element.</p>
<pre>
&lt;xs:complexType name=&quot;itemType&quot;&gt;
&lt;xs:sequence&gt;
&lt;xs:element name=&quot;name&quot; type=&quot;xs:string&quot;/&gt;
&lt;xs:element name=&quot;amount&quot; type=&quot;xs:int&quot;/&gt;
&lt;xs:element name=&quot;price&quot; type=&quot;xs:double&quot;/&gt;
&lt;/xs:sequence&gt;
&lt;/xs:complexType&gt;
&lt;xs:complexType name=&quot;priceType&quot;&gt;
&lt;xs:sequence&gt;
&lt;xs:element name=&quot;item&quot; type=&quot;ps:itemType&quot; minOccurs=&quot;0&quot; maxOccurs=&quot;unbounded&quot;/&gt;
&lt;/xs:sequence&gt;
&lt;/xs:complexType&gt;
&lt;xs:element name=&quot;price&quot; type=&quot;ps:priceType&quot;/&gt;
</pre>
<p>By default, the generated Java type for <span class="langinline">itemType</span>
would be an interface called <span class="langinline">ItemType</span>. With
this type, you would be able to get and set the values of its <span class="langinline">name</span>,
<span class="langinline">amount</span>, and <span class="langinline">price</span>
child elements. However, a user-derived type (as opposed to an element or
attribute) is always intended for use as the type to which an element or
attribute is bound. In other words, it's contained by an element or attribute.
While you can create a new instance of a user-derived type, the new instance's
underlying XML is a fragment. As the generated API would make clear, the
<span class="langinline">itemType</span> becomes the return type of a get
method, or the parameter of a set method.</p>
<pre>
// Create a new price document.
PriceDocument priceDoc = PriceDocument.Factory.newInstance();
PriceType price = priceDoc.getPrice();
/*
* Create a new instance of ItemType and set the values of its
* child elements.
*/
ItemType item = ItemType.Factory.newInstance();
item.setName(&quot;bicycle&quot;);
item.setAmount(12);
item.setPrice(560.00);
/*
* Use the new ItemType instance to set the value of the
* price element's first item child element. Notice that the set method
* here is an "Array" method. This is because the item element
* is defined with a maxOccurs="unbounded" attribute. It can occur
* many times as a child of price.
*/
price.setItemArray(0, item);
</pre>
<h2>Nested Elements and Derived Types</h2>
<p>When your schema includes named types that are declared locally—within
the declaration of another element or type—the schema type's generated Java
interface will be an inner interface within the type it's nested in.</p>
<p>For example, the following schema snippet defines <span class="langinline">name</span>
and <span class="langinline">gender</span> elements nested within a <span class="langinline">person</span>
complex type. In particular, note that the gender element is defined as
deriving from the xs:NMTOKEN built-in type.</p>
<pre>
&lt;xs:complexType name="person"&gt;
&lt;xs:sequence&gt;
&lt;xs:element name="name" type="xs:string"/&gt;
&lt;xs:element name="gender"&gt;
&lt;xs:simpleType&gt;
&lt;xs:restriction base="xs:NMTOKEN"&gt;
&lt;xs:enumeration value="male"/&gt;
&lt;xs:enumeration value="female"/&gt;
&lt;/xs:restriction&gt;
&lt;/xs:simpleType&gt;
&lt;/xs:element&gt;
&lt;/xs:sequence&gt;
&lt;/xs:complexType&gt;
</pre>
<p>The generated interfaces for person and gender would be organized in source
something like the following. Of course, you wouldn't see the source, but
you can see here that the Gender interface is nested with Person. Also,
notice that it extends XmlNMTOKEN, mirroring the schema.</p>
<pre>public interface Person extends XmlObject
{
public interface Gender extends XmlNMTOKEN
{
// Methods omitted for this example
}
// Methods omitted for this example
}
</pre>
<p>You could create a new instance of the <span class="langinline">Gender</span>
type in this way (there are also various alternatives to this):</p>
<pre>
// Create a new Person instance.
Person person = Person.Factory.newInstance();
/*
* Set the gender element's value using the
* enumeration generated from the schema.
*/
person.setGender(Gender.FEMALE);</pre>
<h2>User-Derived Simple Types</h2>
<p>In addition to the 46 built-in simple types in XML schema, a schema can
include its own custom simple types using <span class="langinline">xs:simpleType</span>
declarations. These user-derived simple types are always based on the built-in
XML schema types. The built-in types can be modified by <em>restricting</em>
them, taking <em>unions</em> of them, or making space-separated <em>lists</em>
of them. Each XML simple type is translated into a Java type that provides
access to the underlying data.</p>
<h3>Unions</h3>
<p>In schema, you can use <span class="langinline">xs:union</span> to specify
a simple type that is allowed to contain values of a number of other simple
types. XMLBeans generates a type for a union, just as it generates a type
for any other schema type. At run time, you can discover the underlying
type of an instance of a union type by calling the <span class="langinline">XmlObject</span>
interface's <span class="langinline">instanceType</span> method. Once you
have determined the type, you can cast an instance of a union type to the
actual underlying instance type.</p>
<pre>
&lt;xs:simpleType name=&quot;intOrString&quot;&gt;
&lt;xs:union memberTypes=&quot;xs:int xs:string&quot;&gt;
&lt;/xs:simpleType&gt;
</pre>
<p>Given the preceding schema snippet, you could set the intOrString value
to, say, 6 or &quot;six&quot;. The union of <span class="langinline">xs:int</span>
and <span class="langinline">xs:string</span> makes both allowable.</p>
<pre>
// Create a new instance of the type.
IntOrString intOrString = IntOrString.Factory.newInstance();
intOrString.set(&quot;5&quot;);
// This code prints "XmlInt" to the console.
System.out.println(intOrString.instanceType().getShortJavaName());
</pre>
<h3>Restrictions</h3>
<p>XML schema restrictions on simple XMLBeans types are enforced. So, for
example, it is illegal to set a number outside its restricted range. </p>
<h4>Numeric Type Restrictions</h4>
<p>In schema, you can restrict numeric types to allow, for example, only a
particular range of values. For such a restriction, XMLBeans tailors the
resulting natural Java alternative. For example, suppose you have the following
element defined in schema:</p>
<pre>
&lt;xs:element name="number"&gt;
&lt;xs:simpleType&gt;
&lt;xs:restriction base="xs:integer"&gt;
&lt;xs:minInclusive value="1"/&gt;
&lt;xs:maxInclusive value="1000000"/&gt;
&lt;/xs:restriction&gt;
&lt;/xs:simpleType&gt;
&lt;/xs:element&gt;
</pre>
<p>The type is restricted from <span class="langinline">xs:integer</span>,
but because the number's range is limited to between 1 and 1000000, it will
fit into a Java <span class="langinline">int</span>. A <span class="langinline">long</span>
or <span class="langinline">java.math.BigInteger</span> would be too big
for the need. In other words, the <span class="langinline">getNumber</span>
method generated for this type will return an <span class="langinline">int</span>,
rather than a <span class="langinline">BigInteger</span> or a <span class="langinline">long</span>.</p>
<p>By the same token, an long can be compiled to an int if the totalDigits
attribute is &lt;=9, or the min and max attribute values are within 32-bit
2s complement range.</p>
<p>The single primitive XML type xs:decimal can be restricted in several ways
that influence the resulting natural Java type. For example, it can be:</p>
</div>
</div>
<ul>
<li>
<div>
<div>Compiled to a <span class="langinline">BigInteger</span> if its <span class="langinline">fractionDigit</span>
attribute is set to 0. </div>
</div>
</li>
<li>
<div>
<div>Compiled to a <span class="langinline">long</span> if its totalDigits
attribute is &lt;=18, or the min and max are within 64-bit 2s complement
range.</div>
</div>
</li>
</ul>
<div>
<div>
<h3>Enumerations</h3>
<p>In schema, you can derive a new type by restricting a built-in type so
that only a finite set of values are allowable. Where schema does this by
restricting <span class="langinline">xs:string</span>, XMLBeans generates
a special <span class="langinline">Enum</span> type. With an <span class="langinline">Enum</span>,
you can select the enumerated value either by its <span class="langinline">String</span>
value or by a numeric index. The index's value is determined based on the
<span class="langinline">String</span> value's order in the schema. Having
an index can be useful in Java switch statements.</p>
<p>For example, suppose you had a document containing price elements whose
type was the priceType defined in the following schema snippet:</p>
<pre>&lt;xs:complexType name=&quot;priceType&quot;&gt;
&lt;xs:sequence&gt;
&lt;xs:element name=&quot;item&quot; type=&quot;ps:itemType&quot; minOccurs=&quot;0&quot;
maxOccurs=&quot;unbounded&quot;/&gt;
&lt;/xs:sequence&gt;
&lt;xs:attribute name=&quot;threshold&quot;&gt;
&lt;xs:simpleType&gt;
&lt;xs:restriction base=&quot;xs:string&quot;&gt;
&lt;xs:enumeration value=&quot;Below10Dollars&quot;/&gt;
&lt;xs:enumeration value=&quot;Between10And20Dollars&quot;/&gt;
&lt;xs:enumeration value=&quot;Above20Dollars&quot;/&gt;
&lt;/xs:restriction&gt;
&lt;/xs:simpleType&gt;
&lt;/xs:attribute&gt;
&lt;/xs:complexType&gt;</pre>
<p>Using types generated from the schema, you would be able to write the following
Java code to &quot;switch&quot; on the threshold attribute's enumeration:</p>
<pre>
/*
* Use the intValue method provided by the Enum type to determine the threshold
* attribute's current enumeration value.
*/
switch(priceElements[i].getThreshold().intValue())
{
// Use the Threshold type's enumeration values to test for an attribute value.
case PriceType.Threshold.INT_BELOW_10_DOLLARS:
zeroBuffer.append(item.getTitle() + &quot;\n&quot;);
break;
case PriceType.Threshold.INT_BETWEEN_10_AND_20_DOLLARS:
tenBuffer.append(item.getTitle() + &quot;\n&quot;);
break;
case PriceType.Threshold.INT_ABOVE_20_DOLLARS:
twentyBuffer.append(item.getTitle() + &quot;\n&quot;);
break;
default:
System.out.println(&quot;Yo! Something unexpected happened!&quot;);
break;
}</pre>
</div>
<p class="relatedtopics">Related Topics</p>
<p><a href="conXMLBeansSupportBuiltInSchemaTypes.html">XMLBeans Support for
Built-In Schema Types</a></p>
</div>
<!-- InstanceEndEditable -->
<script language="JavaScript">
</script>
</body>
</html>

View File

@@ -0,0 +1,275 @@
<!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>Methods for Types Generated From Schema</title>
<!-- InstanceEndEditable -->
<!--(Meta)==========================================================-->
<meta http-equiv=Content-Type content="text/html; charset=$CHARSET;">
<!-- InstanceBeginEditable name="metatags" -->
<meta name="component" content="">
<!-- In the description metatag, please provide a BRIEF description of the topic contents. -->
<meta name="description" content="">
<!-- In the component metatag, please list keywords that will help a user search for this topic. -->
<meta name="keywords" content="">
<!-- InstanceEndEditable -->
<!--(Links)=========================================================-->
<!-- InstanceBeginEditable name="head" -->
<!-- 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" -->
<div id=topictitle>
<p class=Title>Methods for Types Generated From Schema</p>
</div>
<div id=topictext>
<p>As you may have seen in <a href="conGettingStartedwithXMLBeans.html">Getting
Started with XMLBeans</a>, you use the types generated from schema to access
XML instances based on the schema. If you're familiar with the JavaBeans technology,
the conventions used in the generated API will be recognizable. </p>
<p>In general, elements and attributes are treated as &quot;properties&quot;
in the JavaBeans sense. In other words, as you would with JavaBeans properties,
you manipulate parts of the XML through accessor methods such as getCustomer()
(where you have a &quot;customer&quot; element), setId(String) (where you
have an &quot;id&quot; attribute), and so on. However, because schema structures
can be somewhat complex, XMLBeans provides several other method styles for
handling those structures in XML instances.</p>
<div>
<h2>Prototypes for Methods in Generated Interfaces</h2>
<p>Several methods are generated for each element or attribute within the
complex type. This topic lists each method that could be generated for a
given element or attribute. </p>
<p>Note that whether or not a given method is generated is based on how the
element or attribute is defined in schema. For example, a customer element
definition with a <span class="langinline">maxOccurs</span> attribute value
of 1 will result in a getCustomer method, but not a getCustomerArray method
&#8212; after all, only one customer element is possible in an instance
document.</p>
<p>Note, too, that there may be two sets of parallel methods: one whose prototype
starts with an &quot;x&quot;. An &quot;x&quot; method such as xgetName or
xsetName would be generated for elements or attribute whose type is a simple
type. A simple type may be one of the 44 built-in simple types or may be
a restriction in schema of one of those built-in types. Of course, an attribute
will always be of a simple type. For built-in simple types, an &quot;x&quot;
method will get or set one of the types provided with XMLBeans, such as
<span class="langinline"><a href="../reference/org/apache/xmlbeans/XmlString.html">XmlString</a></span>,
<span class="langinline"><a href="../reference/org/apache/xmlbeans/XmlInteger.html">XmlInteger</a></span>,
<span class="langinline"><a href="../reference/org/apache/xmlbeans/XmlGDay.html">XmlGDay</a></span>,
and so on. For derived types, the &quot;x&quot; method will get or set a
generated type.</p>
<h3>Single Occurrence Methods</h3>
<p>Methods generated for elements or attributes that allow a single occurrence.
An element is singular if it was declared with maxOccurs=&quot;1&quot;.
An attribute is singular if it was not declared with use=&quot;prohibited&quot;.</p>
<pre>
Type getFoo()
void setFoo(Type newValue)
</pre>
</div>
<blockquote>
<div>Returns or sets the value of Foo. Generated when Foo is an attribute,
or is an element that can occur only once as a child.</div>
</blockquote>
<div>
<hr size="1">
<pre>XmlType xgetFoo()
void xsetFoo(XmlType newValue)</pre>
</div>
<blockquote>
<div>Returns or sets the value of Foo as an XMLBean simple type. These methods
are generated if Foo's type is defined in schema as a simpleType.</div>
</blockquote>
<div>
<hr size="1">
<pre>boolean isNilFoo()
void setNilFoo()</pre>
</div>
<blockquote>
<div>Determines or specifies whether the Foo element is nil (in other words,
&quot;null&quot; in schema terms), meaning it can be empty. A nil element
looks something like this:</div>
<div>
<pre>&lt;foo/&gt;</pre>
</div>
<div>These methods are only generated when an element type is declared as
nillable in schema &#8212; it has a nillable=&quot;true&quot; attribute.</div>
</blockquote>
<div>
<hr size="1">
<pre>XmlType addNewFoo()</pre>
</div>
<blockquote>
<div>Adds a new Foo as an XMLBean simple to the document, or returns Foo's
value if one exists already.</div>
</blockquote>
<div>
<hr size="1">
<pre>boolean isSetFoo()
void unSetFoo()</pre>
</div>
<blockquote>
<div>Determines whether the Foo element or attribute exists in the document;
removes Foo. These methods are generated for elements and attributes that
are optional. In schema, and optional element has an <span class="langinline">minOccurs</span>
attribute set to &quot;0&quot;; an optional attribute has a <span class="langinline">use</span>
attribute set to &quot;optional&quot;.</div>
</blockquote>
<div>
<hr size="1">
<h3>Multiple Occurrence Methods</h3>
<p>Methods generated for elements that allow multiple occurrences. </p>
<p>An element may occur multiple times if it has a <span class="langinline">maxOccurs</span>
attribute set to &quot;unbounded&quot; or greater than 1. Attributes can't
occur multiple times.</p>
<pre>Type[] getFooArray()
void setFooArray(Type[] newValue) </pre>
</div>
<blockquote>
<div>Returns or sets all of the Foo elements. </div>
<div>
<pre>
// Get an array of the all of the purchase-order elements item children.
Item[] items = myPO.getItemArray();
</pre>
</div>
</blockquote>
<div>
<hr size="1">
<pre>Type getFooArray(int index)
void setFooArray(Type newValue, int index)</pre>
</div>
<blockquote>
<div>Returns or sets the Foo child element at the specified index.</div>
<div>
<pre>// Sets the value of the third item child element.
myPO.setItem(newItem, 2);</pre>
</div>
</blockquote>
<div>
<hr size="1">
<pre>int sizeOfFooArray()</pre>
</div>
<blockquote>
<div>Returns the number of Foo child elements.</div>
<div>
<pre>// Returns the number of item child elements.
int itemCount = myPO.sizeOfItemArray();</pre>
</div>
</blockquote>
<div>
<hr size="1">
<pre>void removeFoo(int index)</pre>
</div>
<blockquote>
<div>Removes the Foo child element at the specified index.</div>
</blockquote>
<div>
<hr size="1">
<pre>XmlType[] xgetFooArray()
void xsetFooArray(XmlType[] arrayOfNewValues)</pre>
</div>
<blockquote>
<div>Returns or sets all of the Foo elements as XMLBeans simple types. Generated
only when the Foo element is defined as a simple type.</div>
<div>
<pre>/*
* Returns values of all the phone child elements of an employee element,
* where the phone element has been defined as xs:string.
*/
XmlString[] empPhones = currentEmployee.xGetPhoneArray();
</pre>
</div>
</blockquote>
<div>
<hr size="1">
<pre>XmlType xgetFooArray(int index)
void xsetFooArray(int index, XmlType newValue)</pre>
</div>
<blockquote>
<div>Returns or sets the Foo element at the specified index, using an XMLBeans
simple type value. Generated for an element defined as a simple type in
schema.</div>
</blockquote>
<div>
<hr size="1">
<pre>void insertFoo(int index, FooType newValue)</pre>
</div>
<blockquote>
<div>Inserts the specified Foo child element at the specified index.</div>
</blockquote>
<div>
<hr size="1">
<pre>void addFoo(FooType newValue)</pre>
</div>
<blockquote>
<div>Adds the specified Foo to the end of the list of Foo child elements.</div>
</blockquote>
<div>
<hr size="1">
<pre>XmlType insertNewFoo(int index)</pre>
</div>
<blockquote>
<div>Inserts a new Foo at the specified index, returning an XMLBeans simple
type representing the new element; returns the existing Foo if there's already
one at index.</div>
</blockquote>
<div>
<hr size="1">
<pre>XmlType addNewFoo()</pre>
</div>
<blockquote>
<div>Adds a new Foo element to the end of the list of Foo child elements,
returning an XMLBeans simple type representing the newly added element.</div>
</blockquote>
<div>
<hr size="1">
<pre>boolean isNilFooArray(int index)
void setNilFooArray(int index)</pre>
</div>
<blockquote>
<div>Determines or specifies whether the Foo element at the specified index
is nil.</div>
</blockquote>
<div>
<hr size="1">
</div>
<div id="topictext"></div>
<p class=relatedtopics>Related Topics</p>
<p><a href="conJavaTypesGeneratedFromUserDerived.html">Java Types Generated
from User-Derived Schema Types</a></p>
</div>
<!-- InstanceEndEditable -->
<script language="JavaScript">
</script>
</body>
</html>

View File

@@ -0,0 +1,222 @@
<!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>Navigating XML with Cursors</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> Navigating XML with Cursors </h1>
<div id="topictext">
<p>XML cursors are a way to navigate through an XML instance document. Once
you load an XML document, you can create a cursor to represent a specific
place in the XML. Because you can use a cursor with or without a schema corresponding
to the XML, cursors are an ideal way to handle XML without a schema.</p>
<p>With an XML cursor, you can:</p>
</div>
<UL>
<li>
<div><a href="conUnderstandingXMLTokens.html">Use the token model</a> to move
through XML in small increments, or in a manner similar to using a DOM-based
model.</div>
<LI>
<DIV>Get and set values within the XML.</DIV>
<LI>
<DIV><a href="#adding_elements_attributes">Change the structure</a> of an
XML document by inserting, removing, and moving elements and attributes.</DIV>
<LI>
<DIV><a href="conSelectingXMLwithXQueryPathXPath.html">Execute XQuery expressions</a>
against the XML represented by the cursor.</DIV>
<LI>
<DIV><a href="conUsingBookmarksToAnnotateXML.html">Insert bookmarks</a> to
mark locations in XML.</DIV>
</UL>
<P>When you're finished using a cursor, your code should call its <span class="langinline">dispose</span>
method.</P>
<h2>Creating and Moving a Cursor</h2>
<P>With an XML instance document bound to <span class="langinline"><a href="../reference/org/apache/xmlbeans/XmlObject.html">XmlObject</a></span>
(or a type inheriting from it), you create a new cursor by calling the <span class="langinline">newCursor</span>
method. The <span class="langinline"><a href="../reference/org/apache/xmlbeans/XmlCursor.html">XmlCursor</a></span>
interface represents a cursor. From a cursor standpoint, an XML document is
a collection of <EM>tokens</EM> that represent the kinds of things that can
appear in XML. These include&nbsp;attributes, the start and end of elements,
comments, and so on.&nbsp;Each piece of information in XML is represented by
a <em>token type</em>.</P>
<P class="notepara"><strong>Note:</strong> For a more complete description of
XML tokens, see <a href="conUnderstandingXMLTokens.html">Understanding XML Tokens</a>.</P>
<P>For example, the following code loads the&nbsp;XML instance described above
from a <span class="langinline">File</span> object, then creates a new cursor.
The <span class="langinline">toFirstChild</span> takes the cursor to the start
tag of the <span class="langinline">batchWidgetOrder</span> document element.
The code then prints the type for the token at the cursor's location, along
with the XML the cursor represents—in other words, <span class="filepath">Token
type: START /</span> and the <span class="filepath">batchWidgetOrderElement</span>
and its contents.</P>
<pre>public static void insertCursor(File orderFile) throws Exception
{
BatchWidgetOrderDocument xmlDoc = BatchWidgetOrderDocument.Factory.parse(orderFile);
XmlCursor orderCursor = xmlDoc.newCursor();
orderCursor.toFirstChild();
System.out.println("Token type: " + orderCursor.currentTokenType() +
" / " + orderCursor.xmlText());
}
</pre>
<p class="notepara"><STRONG>Note</STRONG>: The <span class="langinline">XmlCursor</span>
interface provides many methods you can use to put a cursor where you want it.
For a list of those methods, see <a href="../reference/org/apache/xmlbeans/XmlCursor.html">XmlCursor
Interface</a>.</p>
<h2><a name="adding_elements_attributes" id="adding_elements_attributes"></a>Adding
Elements and Attributes</h2>
<p>The <span class="langinline">XmlCursor</span> interface provides several methods
you can use to add elements and attributes to XML. </p>
<p>One way to add new XML is with the <span class="langinline">beginElement</span>
method. This method is designed to insert a new element at the cursor's location,
and do it so the cursor ends up between the new element's START and END tokens.
From this position, you can insert attributes (they're automatically placed
in the start tag, where they belong) and insert a value. Here's an example:</p>
<pre>
// Create a new chunk of XML.
XmlObject newXml = XmlObject.Factory.newInstance();
/*
* Insert a new cursor and move it to the first START token (where the
* XML actually begins.
*/
XmlCursor cursor = newXml.newCursor();
cursor.toNextToken();
// Begin a new item element whose namespace URI is "http://openuri.org".
cursor.beginElement(&quot;item&quot;, &quot;http://openuri.org/&quot;);
// Insert an ID attribute on the item element, along with an attribute value.
cursor.insertAttributeWithValue(&quot;id&quot;, &quot;4056404&quot;);
// Insert "bicycle" as an element value.
cursor.insertChars(&quot;bicycle&quot;);
cursor.dispose();
</pre>
<p>This example results in something like the following:</p>
<pre>&lt;ns1:item id=&quot;4056404&quot; xmlns:ns1=&quot;http://openuri.org/&quot;&gt;bicycle&lt;/ns1:item&gt;
</pre>
<h2> Using Stored Cursor Locations with push() and pop()</h2>
<div id="topictext">
<p>When you want to move a cursor around, but want to keep track of a former
location, you can use the <span class="langinline">XmlCursor</span> interface's
<span class="langinline">push</span> and <span class="langinline">pop</span>
methods. The <span class="langinline">push</span> method pushes the cursor's
current location onto a stack of locations maintained for that particular
cursor; the <span class="langinline">pop</span> method removes the location
from the top of the stack and moves the cursor to that location.</p>
<p>For example, consider the following &lt;employee&gt; element, used in the
example below.</p>
<pre>
&lt;employee&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;name&gt;Gladys Kravitz&lt;/name&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;address location=&quot;home&quot;&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;street&gt;1313 Mockingbird Lane&lt;/street&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;city&gt;Seattle&lt;/city&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;state&gt;WA&lt;/state&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;zip&gt;98115&lt;/zip&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;/address&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;address location=&quot;work&quot;&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;street&gt;2011 152nd Avenue NE&lt;/street&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;city&gt;Redmond&lt;/city&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;state&gt;WA&lt;/state&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;zip&gt;98052&lt;/zip&gt;
&nbsp;&nbsp; &nbsp;&lt;/address&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;phone location=&quot;work&quot;&gt;(425) 555-6897&lt;/phone&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;phone location=&quot;home&quot;&gt;(206) 555-6594&lt;/phone&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;phone location=&quot;mobile&quot;&gt;(206) 555-7894&lt;/phone&gt;
&lt;/employee&gt;
</pre>
<p>The following Java code illustrates how you can use <span class="langinline">push</span>
and <span class="langinline">pop</span> to put the cursor back to a saved
location after a bit of traveling.</p>
<pre>
/**
* Pass to the trySelectPath method an XmlObject instance that contains
* the XML above.
*/
public void trySelectPath(XmlObject xml)
{
/*
* Inserts the cursor at the STARTDOC token (the very beginning,
* before any elements).
*/
XmlCursor cursor = xml.newCursor();
// Moves the cursor to just before &lt;employee&gt;
cursor.toFirstChild();
// Pushes the cursor's current location onto the stack.
cursor.push();
// Moves the cursor to just before the &quot;work&quot; &lt;phone&gt; element.
cursor.toChild(2);
// Moves the cursor to just before the &quot;home&quot; &lt;phone&gt; element.
cursor.toNextSibling();
// Moves the cursor back to just before &lt;employee&gt;
cursor.pop();
}
</pre>
<p>Of course, you can call <span class="langinline">push</span> and <span class="langinline">pop</span>
multiple times. Each new call to the <span class="langinline">push</span>
method pushes the current location onto the stack. As you call the <span class="langinline">pop</span>
method, you're always getting what's on top of the stack. So if you called
<span class="langinline">push</span> three times before calling <span class="langinline">pop</span>
&#8212; 1, 2, 3 &#8212; calling <span class="langinline">pop</span> three
times would get those locations in reverse order &#8212; 3, 2, 1.</p>
<p>The <span class="langinline">push</span> and <span class="langinline">pop</span>
methods can be handy as an alternative to creating new cursors that are designed
simply to mark a particular location while you move another cursor around.
The resources required to maintain a location stack through <span class="langinline">push</span>
and <span class="langinline">pop</span> are far less than those needed by
cursors. </p>
<H1>Disposing of a Cursor</H1>
<p>When you're through with a cursor, your code should call its <span class="langinline">dispose</span>
method to indicate that it's no longer needed.</p>
<p class="relatedtopics">Related Topics</p>
<p><a href="conUnderstandingXMLTokens.html">Understanding XML Tokens</a></p>
<p><a href="conGettingStartedwithXMLBeans.html">Getting Started with XMLBeans</a></p>
</div>
<!-- InstanceEndEditable -->
<script language="JavaScript">
</script>
</body>
</html>

View File

@@ -0,0 +1,340 @@
<!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>Selecting XML with XQuery and XPath</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> Selecting XML with XQuery and XPath</h1>
<div id="topictext">
<p>You can use XPath and XQuery to retrieve specific pieces of XML as you might
retrieve data from a database. XQuery and XPath provide a syntax for specifying
which elements and attributes you're interested in. The XMLBeans API provides
two methods for executing XQuery and XPath expressions, and two ways to use them. The methods are <span class="langinline">selectPath</span>
for XPath and <span class="langinline">execQuery</span> for XQuery. </p>
<p>You can call them from and <a href="../reference/org/apache/xmlbeans/XmlObject.html"><span class="langinline"> XmlObject</span></a> instance (or a generated type inheriting from it) or an <a href="../reference/org/apache/xmlbeans/XmlCursor.html"><span class="langinline">XmlCursor</span></a> instance.
As noted below, each of the four methods works slightly differently; be sure to keep these differences in mind when choosing your approach.</p>
<p class="notepara"><strong>Note:</strong> Both XQuery and complex XPath expressions require additional classes on the class path, as noted in the sections that follow. Also, be sure to see the XMLBeans <a href="../../../documentation/conInstallGuide.html">installation instructions</a>. </p>
<h2><a name="xpath_selectpath"></a>Using XPath with the selectPath Method</h2>
</div>
<div>
<p>You can execute XPath expressions use the <span class="langinline">selectPath</span> method. When you use XPath with the <span class="langinline">selectPath</span>
method, the value returned is view of values from the <em>current document</em> &#8212; not a copy of those values. In other words, changes your code makes to XML returned by the selectPath method change the XML in the document queried against. In contrast, with XQuery executed using the <span class="langinline">execQuery</span> method, the value returned is a <em>copy of values in the XML queried against</em>.</p>
<p> Note that XPath itself does not provide syntax for declaring prefix to URI bindings. For user convenience, we allow XQuery syntax to be used for such purposes. You can consult the latest XQuery draft when using syntax for declaring namespaces.</p>
<blockquote>
<p><strong>Note:</strong> By default, XMLBeans supports only very simple XPath expressions. To execute complex expressions &#8212; such as those with predicates, function calls, and the like &#8212; you will need xbean_xpath.jar and the Saxon jars (see <a href="#saxon_jars">below</a>) on your class path. xbean_xpath.jar is among those created when you build XMLBeans from source. You may need to download the Saxon jars yourself.</p>
</blockquote>
<h3>Calling XmlObject.selectPath</h3>
<p>When called from <span class="langinline">XmlObject</span> (or a type that
inherits from it), the <code>selectPath</code> method returns an array of objects. If the expression
is executed against types generated from schema, then the type for the returned
array is one of the Java types corresponding to the schema, and you can cast it accordingly. </p>
<p>For example, imagine you have the following XML containing employee information.
You've compiled the schema describing this XML and the types generated from
schema are available to your code.</p>
<pre>
&lt;xq:employees xmlns:xq=&quot;http://xmlbeans.apache.org/samples/xquery/employees&quot;&gt;
&lt;xq:employee&gt;
&lt;xq:name&gt;Fred Jones&lt;/xq:name&gt;
&lt;xq:address location=&quot;home&quot;&gt;
&lt;xq:street&gt;900 Aurora Ave.&lt;/xq:street&gt;
&lt;xq:city&gt;Seattle&lt;/xq:city&gt;
&lt;xq:state&gt;WA&lt;/xq:state&gt;
&lt;xq:zip&gt;98115&lt;/xq:zip&gt;
&lt;/xq:address&gt;
&lt;xq:address location=&quot;work&quot;&gt;
&lt;xq:street&gt;2011 152nd Avenue NE&lt;/xq:street&gt;
&lt;xq:city&gt;Redmond&lt;/xq:city&gt;
&lt;xq:state&gt;WA&lt;/xq:state&gt;
&lt;xq:zip&gt;98052&lt;/xq:zip&gt;
&lt;/xq:address&gt;
&lt;xq:phone location=&quot;work&quot;&gt;(425)555-5665&lt;/xq:phone&gt;
&lt;xq:phone location=&quot;home&quot;&gt;(206)555-5555&lt;/xq:phone&gt;
&lt;xq:phone location=&quot;mobile&quot;&gt;(206)555-4321&lt;/xq:phone&gt;
&lt;/xq:employee&gt;
&lt;/xq:employees&gt;
</pre>
If you wanted to find the phone numbers whose area code was 206, you could capture
the XPath expression in this way:
<pre>
String queryExpression =
&quot;declare namespace xq='http://xmlbeans.apache.org/samples/xquery/employees';&quot; +
&quot;$this/xq:employees/xq:employee/xq:phone[contains(., '(206)')]&quot;;
</pre>
<p>Notice in the query expression that the variable <span class="langinline">$this</span>
represents the current context node (the <span class="langinline">XmlObject</span>
that you are querying from). In this example you are querying from the document
level <span class="langinline">XmlObject</span>.</p>
<p>You could then print the results with code such as the following:</p>
<pre>// Retrieve the matching phone elements and assign the results to the corresponding
// generated type.
PhoneType[] phones = (PhoneType[])empDoc.selectPath(queryExpression);
// Loop through the results, printing the value of the phone element.
for (int i = 0; i < phones.length; i++)
{
System.out.println(phones[i].stringValue());
}</pre>
<h3>Calling XmlCursor.selectPath</h3>
<p>When called from an <span class="langinline">XmlCursor</span> instance, the
<span class="langinline">selectPath</span> method retrieves a list of <em>selections</em>,
or locations in the XML. The selections are remembered by the cursor instance.
You can use methods such as <span class="langinline">toNextSelection</span>
to navigate among them.</p>
<div>
<p>The <span class="langinline">selectPath</span> method takes an XPath expression.
If the expression returns any results, each of those results is added as
a selection to the cursor's list of selections. You can move through these
selections in the way you might use <span class="langinline">java.util.Iterator</span>
methods to move through a collection.</p>
<p> For example, for a path such as <span class="langinline">$this/employees/employee</span>,
the cursor instance from which you called <code>selectPath</code> would include a selection for each employee element found by
the expression. Note that the variable <span class="langinline">$this</span>
is always bound to the current context node, which in this example is the
document. After calling the <span class="langinline">selectPath</span> method,
you would use various &quot;selection&quot;-related methods to work with
the results. These methods include:</p>
</div>
<ul>
<li>
<div><span class="langinline">getSelectionCount() </span>to retrieve the
number of selections resulting from the query.</div>
</li>
<li>
<div> <span class="langinline">toNextSelection()</span> to move the cursor
to the next selection in the list (such as to the one pointing at the
next employee element found).</div>
</li>
<li>
<div> <span class="langinline">toSelection(int)</span> to move the cursor
to the selection at the specified index (such as to the third employee
element in the selection).</div>
</li>
<li>
<div> <span class="langinline">hasNextSelection()</span> to find out if
there are more selections after the cursor's current position.</div>
</li>
<li>
<div><span class="langinline"> clearSelections()</span> clears the selections
from the current cursor. This doesn't modify the document (in other words,
it doesn't delete the selected XML); it merely clears the selection list
so that the cursor is no longer keeping track of those positions.</div>
</li>
</ul>
<div>
<p>The following example shows how you might use <span class="langinline">selectPath</span>,
in combination with the <span class="langinline">push</span> and <span class="langinline">pop</span>
methods, to maneuver through XML, retrieving specific values. </p>
<pre>
public void printZipsAndWorkPhones(XmlObject xml)
{
// Declare the namespace that will be used.
String xqNamespace =
&quot;declare namespace xq='http://xmlbeans.apache.org/samples/xquery/employees';&quot;;
// Insert a cursor and move it to the first element.
XmlCursor cursor = xml.newCursor();
cursor.toFirstChild();
// Save the cursor's current location by pushing it
// onto a stack of saved locations.
cursor.push();
// Query for zip elements.
cursor.selectPath(xqNamespace + &quot;$this//xq:zip&quot;);
// Loop through the list of selections, getting the value of
// each element.
while (cursor.toNextSelection())
{
System.out.println(cursor.getTextValue());
}
// Pop the saved location off the stack.
cursor.pop();
// Query again from the top, this time for work phone numbers.
cursor.selectPath(xqNamespace + &quot;$this//xq:phone[@location='work']&quot;);
// Move the cursor to the first selection, then print that element's
// value.
cursor.toNextSelection();
System.out.println(cursor.getTextValue());
// Dispose of the cursor.
cursor.dispose();
}
</pre>
<p>Using selections is somewhat like tracking the locations of multiple cursors
with a single cursor. This becomes especially clear when you remove the
XML associated with a selection. When you do so the selection itself remains
at the location where the removed XML was, but now the selection's location
is immediately before the XML that was after the XML you removed. In other
words, removing XML created a kind of vacuum that was filled by the XML
after it, which shifted up into the space &#8212; up into position immediately
after the selection location. This is exactly the same as if the selection
had been another cursor.</p>
<p>Finally, when using selections keep in mind that the list of selections
is in a sense &quot;live&quot;. The cursor you're working with is keeping
track of the selections in the list. In other words, be sure to call the
<span class="langinline">clearSelections</span> method when you're finished
with the selections, just as you should call the <span class="langinline">XmlCursor.dispose()</span>
method when you're finished using the cursor.</p>
</div>
<h2><a name="xquery_execquery"></a>Using XQuery with the execQuery Method</h2>
<p>You use the <span class="langinline">execQuery</span> method to execute XQuery
expressions. With XQuery expressions, XML returned is a copy of XML in the document queried against. In other words, changes your code makes to the values returned by <code>execQuery</code> are not reflected in the document queried against.</p>
<blockquote>
<p><a name="saxon_jars"></a><strong>Note:</strong> To execute XQuery expressions, you must have the SaxonB 8.6.1 versions of the saxon8.jar and saxon8-dom.jar files on your classpath. These are two of the jars from inside the zip file saxonb8-6-1.zip
which can be downloaded from the <a href="http://sourceforge.net/project/showfiles.php?group_id=29872&package_id=21888">Saxon web site</a>.
If you build XMLBeans from source then the saxonb8-6-1.zip file and the two Saxon jar files are available in the external/lib directory.</p>
</blockquote>
<h3>Calling XmlObject.execQuery</h3>
<p>As with <span class="langinline">selectPath</span>, calling <span class="langinline">execQuery</span>
from an <span class="langinline">XmlObject</span> instance will return an
<span class="langinline">XmlObject</span> array.</p>
<p> The following example retrieves work <code>&lt;zip&gt;</code> elements from the incoming XML, adding the elements as children to a new <code>&lt;zip-list&gt;</code> element.</p>
<pre>public boolean collectZips(XmlObject empDoc)
{
String namespaceDeclaration =
"declare namespace xq='http://xmlbeans.apache.org/samples/xquery/employees';";
// The query is designed to return results, so return
// true if it does.
boolean hasResults = false;
// The expression: Get the &lt;zip> elements and return them as children
// of a new &lt;zip-list> element.
String queryExpression =
"let $e := $this/xq:employees " +
"return " +
"&lt;zip-list> " +
"{for $z in $e/xq:employee/xq:address/xq:zip " +
"return $z} " +
"&lt;/zip-list>";
// Execute the query. Results will be copies of the XML queried against,
// stored as members of an XmlObject array.
XmlObject[] results =
empDoc.execQuery(namespaceDeclaration + queryExpression);
// Print the results.
if (results.length > 0)
{
hasResults = true;
System.out.println("The query results: \n");
System.out.println(results[0].toString() + "\n");
}
return hasResults;
}</pre>
<h3>Calling XmlCursor.execQuery</h3>
</div>
<div>
<p>Unlike the <code>selectPath</code> method called from a cursor, the <span class="langinline">execQuery</span> method doesn't return <code>void</code>. Instead it returns an <span class="langinline">XmlCursor</span> instance positioned at the beginning of a new XML document representing
the query results. Rather than accessing results as selections, you use the cursor to move through the results in typical cursor fashion (for more information, see <a href="conNavigatingXMLwithCursors.html">Navigating
XML with Cursors</a>). The models are very different.</p>
<p>As always, you can cast the results to a type generated from schema if you know that the results conform to that type.</p>
<p>The following example retrieves work <code>&lt;phone&gt;</code> elements from the incoming XML, then changes the number in the results.</p>
<pre>public boolean updateWorkPhone(XmlObject empDoc)
{
boolean hasResults = false;
// A cursor instance to query with.
XmlCursor empCursor = empDoc.newCursor();
empCursor.toNextToken();
// The expression: Get the <employee> elements with <state> elements whose
// value is "WA".
String queryExpression =
"for $e in $this/xq:employees/xq:employee " +
"let $s := $e/xq:address/xq:state " +
"where $s = 'WA' " +
"return $e//xq:phone[@location='work']";
// Execute the query. Results, if any, will be available at
// the position of the resultCursor in a new XML document.
XmlCursor resultCursor =
empCursor.execQuery(namespaceDeclaration + queryExpression);
System.out.println("The query results, element copies made " +
"from the received document: \n");
System.out.println(resultCursor.getObject().toString() + "\n");
// If there are results, the results will be children of the fragment root
// where the new cursor is positioned. This statement tests for children
// and moves the cursor if to the first if it exists.
if (resultCursor.toFirstChild())
{
hasResults = true;
// Use the cursor to loop through the results, printing each sibling
// <employee>element returned by the query.
int i = 0;
do
{
// Change the phone numbers.
XmlCursor editCursor = resultCursor.newCursor();
editCursor.toLastAttribute();
editCursor.toNextToken();
editCursor.removeXml();
editCursor.insertChars("(206)555-1234");
} while (resultCursor.toNextSibling());
resultCursor.toStartDoc();
System.out.println("The query results after changes: \n");
System.out.println(resultCursor.getObject().toString() + "\n");
System.out.println("The received document -- note that it is unchanged. " +
"Changes were made to the copy created by the execQuery method. \n");
System.out.println(empDoc + "\n");
}
return hasResults;
}</pre>
<h2>Related Topics</h2>
</div>
<p><a href="conGettingStartedwithXMLBeans.html">Getting Started with XMLBeans</a></p>
<!-- InstanceEndEditable -->
<script language="JavaScript">
</script>
</body>
</html>

View File

@@ -0,0 +1,189 @@
<!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>Understanding XML Tokens</title>
<!-- InstanceEndEditable -->
<!--(Meta)==========================================================-->
<meta http-equiv=Content-Type content="text/html; charset=$CHARSET;">
<!-- InstanceBeginEditable name="metatags" -->
<meta name="component" content="">
<!-- In the description metatag, please provide a BRIEF description of the topic contents. -->
<meta name="description" content="">
<!-- In the component metatag, please list keywords that will help a user search for this topic. -->
<meta name="keywords" content="">
<!-- InstanceEndEditable -->
<!--(Links)=========================================================-->
<!-- InstanceBeginEditable name="head" -->
<!-- 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" -->
<div id=topictitle>
<p class=Title>Understanding XML Tokens</p>
</div>
<div id=topictext>
<p>An XML cursor (an instance of the <a href="../reference/org/apache/xmlbeans/XmlCursor.html"><span class="langinline">XmlCursor</span></a>
interface) moves from token to token as your code moves the cursor. When you
move a cursor using a method such as <span class="langinline">toParent</span>,
<span class="langinline">toFirstAttribute</span>, <span class="langinline">toPrevSibling</span>,
and so on, the cursor moves to the token fitting the description. If there
is no appropriate token to move to, the cursor remains where it is, and <span class="langinline">false</span>
is returned to indicate that it didn't move. For example, if the cursor is
at the ENDDOC token (the last tag in the document), a call to the <span class="langinline">toNextSibling</span>
method will not move the cursor and will return <span class="langinline">false</span>
to indicate that the move was unsuccessful.</p>
<p>Note that while you can call the <span class="langinline">XmlCursor.currentTokenType</span>
method to find out which token type the cursor is at, you might find it more
convenient to use a method such as <span class="langinline">isEnddoc</span>.
The <span class="langinline">XmlCursor</span> interface provides several methods
that make it easy to discover whether the cursor you're moving is at the token
you're looking for. These methods, such as <span class="langinline">isStart</span>,
<span class="langinline">isAttr</span>, <span class="langinline">isText</span>,
and so on, return a <span class="langinline">boolean</span> value that indicates
whether the cursor is at the token type in question.</p>
<P>Tokens are represented by constants in the <span class="langinline"><a href="../reference/org/apache/xmlbeans/XmlCursor.TokenType.html">TokenType</a></span>
class, an inner class of the <span class="langinline">XmlCursor</span> interface.
Each has a constant you can use in switch statements to perform by-token actions.
The following table lists the token types:</P>
<TABLE id="Table1">
<TR>
<TD><STRONG>Token Type</STRONG></TD>
<TD><STRONG>Switch Constant</STRONG></TD>
<TD><STRONG>Description</STRONG></TD>
</TR>
<TR>
<TD>STARTDOC</TD>
<TD>INT_STARTDOC</TD>
<TD>Represents the start of the XML. Always the first token. The document
element itself is represented by a START token, not the STARTDOC token.</TD>
</TR>
<TR>
<TD>ENDDOC </TD>
<TD>INT_ENDDOC</TD>
<TD>Represents the end of the XML. Always the last token.</TD>
</TR>
<TR>
<TD>START </TD>
<TD>INT_START</TD>
<TD>Represents the start of an element.</TD>
</TR>
<TR>
<TD>END </TD>
<TD>INT_END</TD>
<TD>Represents the end of an element. The END token has no value, but marks
the element's end.</TD>
</TR>
<TR>
<TD>TEXT</TD>
<TD>INT_TEXT</TD>
<TD>Represents text.</TD>
</TR>
<TR>
<TD>ATTR </TD>
<TD>INT_ATTR</TD>
<TD>Represents an attribute. ATTR tokens are allowed to appear after a STARTDOC
or START token.</TD>
</TR>
<TR>
<TD>NAMESPACE</TD>
<TD>INT_NAMESPACE</TD>
<TD>Represents a namespace (xmlns) attribute. Also only allowed after START
or STARTDOC tokens.</TD>
</TR>
<TR>
<TD>COMMENT </TD>
<TD>INT_COMMENT</TD>
<TD>Represents a comment.</TD>
</TR>
<TR>
<TD>PROCINST </TD>
<TD>INT_PROCINST</TD>
<TD>Represents a processing instruction.</TD>
</TR>
</TABLE>
<P>As you use a cursor to navigate through XML, you can use one of the convenience
methods described above to discover whether you're at the token you're looking
for, or use the <span class="langinline">XmlCursor.currentTokenType</span>&nbsp;method
to discover the current token's type. The following figure illustrates example
locations for token types:</P>
<P><IMG src="../images/conCursorTokenLocations.gif" width="727" height="532">
<h2>Switching to Test for Token Types</h2>
<p>Here's a bit of code illustrating how you might use a Java <span class="langinline">switch</span>
statement to test for the START token type.</p>
<pre>
// Take an incoming XmlObject and insert a cursor.
XmlCursor documentCursor = xmlDoc.newCursor();
/*
* Loop through the document, passing the cursor when it stops at each token
* to a function designed to discover the token type. Continue the loop
* as long at the cursor is at a token (until it reaches the end).
*/
while (!documentCursor.toNextToken().isNone())
{
/*
* Use the intValue method to return the int corresponding to the
* current token type. If it is the value for INT_START,
* then you have a match.
*/
switch (cursor.currentTokenType().intValue())
{
case TokenType.INT_START:
// Print out the token type and a message.
System.out.println(cursor.currentTokenType() +
"; cursor is at the start of an element.");
break;
}
}
// Be sure to dispose of a cursor when you're finished.
documentCursor.dispose();
</pre>
<p>The scope of an XML cursor is the XML document in which it is created. For
example, you can create a cursor at the orderItem element in the example earlier
in this topic. If you then use that <span class="langinline">XmlCursor</span>
instance's <span class="langinline">toNextToken</span> method to move the
cursor until it won't move any further, you'll have reached the ENDDOC token.
In this example, that's at the <span class="langinline">&lt;/batchWidgetOrder&gt;</span>
tag. In other words, the cursor's scope is not limited to the element at which
it was created.</p>
<p class=relatedtopics>Related Topics</p>
<p><a href="../reference/org/apache/xmlbeans/XmlCursor.TokenType.html">XmlCursor.TokenType
Class</a></p>
<p><a href="conNavigatingXMLwithCursors.html">Navigating XML with Cursors</a></p>
</div>
<!-- InstanceEndEditable -->
<script language="JavaScript">
</script>
</body>
</html>

View File

@@ -0,0 +1,97 @@
<!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>Using Bookmarks to Annotate XML</title>
<!-- InstanceEndEditable -->
<!--(Meta)==========================================================-->
<meta http-equiv=Content-Type content="text/html; charset=$CHARSET;">
<!-- InstanceBeginEditable name="metatags" -->
<meta name="component" content="">
<!-- In the description metatag, please provide a BRIEF description of the topic contents. -->
<meta name="description" content="">
<!-- In the component metatag, please list keywords that will help a user search for this topic. -->
<meta name="keywords" content="">
<!-- InstanceEndEditable -->
<!--(Links)=========================================================-->
<!-- InstanceBeginEditable name="head" -->
<!-- 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" -->
<div id=topictitle>
<p class=Title>Using Bookmarks to Annotate XML</p>
</div>
<div id=topictext>
<p>You can use a cursor to insert bookmarks that annotate XML with markers containing
information you design. These bookmarks aren't written into the XML itself,
but in a sense "hang" from the location where it was inserted. In this way
you can associate arbitrary pieces of information with specific parts of the
XML.</p>
<P>You design your own bookmark classes by extending <span class="langinline"><a href="../reference/org/apache/xmlbeans/XmlCursor.XmlBookmark.html">XmlBookmark</a></span>,
a nested class of <span class="langinline"><a href="../reference/org/apache/xmlbeans/XmlCursor.html">XmlCursor</a></span>.
You can design your bookmark class to contain information specific to your
needs. </P>
<P>In the following example, <span class="langinline">OrderBookmark</span> is
an inner class that extends <span class="langinline">XmlCursor.XmlBookmark</span>.
It merely stores a piece of text.</P>
<PRE>
/*
* The OrderBookmark class includes a constructor through which you will
* insert your bookmark's content. It also includes get and set methods
* you can use to retrieve and change the content.
*/
static class OrderBookmark extends XmlCursor.XmlBookmark {
public OrderBookmark (String text) { TEXT = text; }
public String TEXT;
public String getText() { return TEXT; }
public void setText(String newText) { TEXT = newText; }
}
</PRE>
<p>You can use instances of this class to store bookmarks at places in your
XML. The following excerpt of code creates a cursor and an instance of the
<span class="langinline">OrderBookmark</span> class. Then it uses the cursor
to insert the bookmark at the cursor's current location.</p>
<pre>
XmlCursor orderCursor = xmlDoc.newCursor();
OrderBookmark thisBookmark = new OrderBookmark("foo");
orderCursor.setBookmark(thisAnnotation);
</pre>
<p class=relatedtopics>Related Topics</p>
<p><a href="conNavigatingXMLwithCursors.html">Navigating XML with Cursors</a></p>
</div>
<!-- InstanceEndEditable -->
<script language="JavaScript">
</script>
</body>
</html>

View File

@@ -0,0 +1,138 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!-- 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 xmlns="http://www.w3.org/1999/xhtml">
<head>
<!-- InstanceBeginEditable name="doctitle" -->
<title>XMLBeans Tools</title>
<!-- InstanceEndEditable -->
<!--(Meta)==========================================================-->
<meta http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<!-- InstanceBeginEditable name="metatags" -->
<meta name="author" content="your name" />
<meta name="Description" content="A description of the topic contents." />
<meta name="Keywords" content="keywords to help in searches" />
<meta name="date last modified" content="10/25/02" />
<!-- InstanceEndEditable -->
<!--(Links)=========================================================-->
<!-- InstanceBeginEditable name="head" -->
<link href="../xmlbeans.css" rel="stylesheet" type="text/css" />
<!-- InstanceEndEditable -->
<link href="../xmlbeans.css" rel="stylesheet" type="text/css">
<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> Validation with XMLBeans </h1>
<p>An essential part of schema-related work is validating instances based on the schema. XMLBeans provides a number of ways for you to ensure your instances are valid, both at the command line and programmatically at run time. </p>
<h2>Validation, XMLBeans-Style</h2>
<p>XMLBeans' schema-oriented approach to handling XML makes validation an important part of its work. However, XMLBeans has a specific approach to validation that's helpful to keep in mind when you're working.</p>
<p>Validation features include the following: </p>
<ul>
<li>Generally, XMLBeans validates when you ask it to. It <a href="#no_parsing_validation">doesn't validate while parsing</a> -- nor, by default, while your code is updating the bound instance along the way through, say, set* methods (although you can change this behavior).</li>
<li>You can <a href="#validation_apis">validate programmatically</a> or by using one of the <a href="#command_line_validation">command-line tools</a> provided by XMLBeans. </li>
<li>The <code>validate</code> methods return <code>true</code> or <code>false</code> to indicate whether the instance is valid. You can also <a href="#retrieving_error_messages">capture error information</a> if you want to when validating programmatically. To do this, you specify an error listener.</li>
<li>You can tell XMLBeans at parse time that it <a href="#validation_as_you_go">should validate during calls to set* methods</a>. Note that this means validation <em>after</em> parsing, not during, and that it can slow performance. Also note validation would not occur as changes are made by a cursor.</li>
<li>XMLBeans does validate <em>schema</em> when compiling the schema through scomp or the xmlbean Ant task. (When you're compiling schema programmatically, you can disable validation with the <code>XmlOptions.setCompileNoValidation</code> method.)</li>
</ul>
<h2>XMLBeans Validates Only When You Ask It To &#8212; Generally</h2>
<p>Given XMLBeans' focus on schema-oriented work, it's natural to assume that it might check up on you as your code is making changes to an instance &#8212; that it might prevent your code from doing something that would render the instance invalid along the way. But, by default, it doesn't. The design of XMLBeans assumes that an XML instance might go through multiple invalid states before changes are complete. As a result, generally speaking, XMLBeans keeps quiet while changes are occurring.</p>
<blockquote>
<p><span class="notepara"><strong>Note:</strong> The exception to this rule is that XMLBeans validates your schema when you're compiling it using scomp or the xmlbean Ant task.</span></p>
</blockquote>
<h3><a name="no_parsing_validation" id="no_parsing_validation"></a>XMLBeans Does Not Validate an Instance While Parsing It</h3>
<p>But it's not hard to get the impression that it does. For example, imagine that you're parsing an XML instance using a statement such as the following:</p>
<blockquote>
<pre>MyXmlSchemaType myXmlBean = MyXmlSchemaType.Factory.parse(myXml);</pre>
</blockquote>
<p>If the namespace declared in the myXml instance doesn't match the target namespace of the schema from which MyXmlSchemaType was generated, parsing will fail with an error message. Likewise, you'll get messages for other mismatches between the shape of myXml and the XML shape described by the schema.</p>
<p>But these failures and messages don't result from validation. Instead, all XMLBeans is doing is a not-very-deep check to see if the instance <em>shouldn't be bound</em> to the XMLBeans type generated from schema. In other words, the checking done at the parsing stage is simply a &quot;low bar&quot; effort to avoid trouble down the road.</p>
<p>Validation, on the other hand, is designed to verify that the instance conforms completely to the schema.</p>
<p>So you can validate in any of three ways:</p>
<ul>
<li>On request, using a validate method.</li>
<li>On the fly, using the &quot;validate on set&quot; option.</li>
<li>Using one of the command-line tools. </li>
</ul>
<h2>Tools for Validating</h2>
<p>XMLBeans tools for validation include command-line tools and APIs. </p>
<h3><a name="command_line_validation" id="command_line_validation"></a>Command-line Tools for Validation </h3>
<p>Among the many <a href="tools.html">command-line tools</a> XMLBeans provides, you'll find two that are specifically for validation. </p>
<ul>
<li><a href="tools.html#validate">validate</a> tool &#8212; A validation command-line tool
in which you specify the instance to validate and the schema to validate it against.
<p>You'll find the <code>validate</code> tool in the bin directory of your XMLBeans installation. </p>
</li>
<li><a href="tools.html#svalidate">svalidate</a> tool &#8212; Identical to the validate tool, except that svalidate uses a streaming model that supports validation against much larger schemas.
<p>You'll find the <code>svalidate</code> tool in the bin directory of your XMLBeans installation. </p>
</li>
</ul>
<h3><a name="validation_apis" id="validation_apis"></a>APIs for Validation </h3>
<p>XMLBeans APIs provide ways for you to <a href="#validation_when_you_ask">validate on request</a> &#8212; say, after your code has finished editing an instance and before it passes the instance elsewhere. You can also specify that your calls to set* methods should <a href="#validation_as_you_go">validate on-the-fly</a> the instance that is being edited; you do this as an option when your code creates the XMLBeans schema type instance.</p>
<h4><a name="validation_when_you_ask" id="validation_when_you_ask"></a>Validation When You Ask for It</h4>
<p>Both the <code>validate</code> methods described here are available from any XMLBeans type generated from schema during schema compilation (because all such types inherit from <code>XmlObject</code>). Both methods are designed to validate the instance that is bound to the type from which the method is called. For example, if your schema defines a <code>&lt;purchase-order&gt;</code> element with <code>&lt;item&gt;</code> children, calling the <code>myItem.validate()</code> method will validate the <code>&lt;item&gt;</code> instance bound to <code>Item</code>. This includes the <code>&lt;item&gt;</code> element's children, but not the <code>&lt;purchase-order&gt;</code> element or the <code>&lt;item&gt;</code> element's siblings.</p>
<p>Both methods return a <code>boolean</code> to indicate validity, and one of the methods lets you specify options for validation, such as capturing messages about why an invalid instance is invalid.</p>
<ul>
<li><code>XmlObject.validate()</code> &#8212; Returns <code>true</code> if the instance is valid.</li>
<li><code>XmlObject.validate(XmlOptions)</code> &#8212; Returns <code>true</code> if the instance is valid, using the specified <code>XmlOptions</code> instance to customize validation.
<p>In particular, you can use the <code>XmlOptions.setErrorListener</code> method to specify a <code>Collection</code> instance with which to capture messages pertaining to invalid instances. For an example, see the Javadoc for this method. </p>
<p>Through the <code>XmlOptions</code> class, you can specify options to use during validation. The options include the following: </p>
</li>
<li>XmlOptions.setErrorListener -- Specifies a Collection instance that XMLBeans should use to store errors that occur during validation (or, in other contexts, during parsing and compilation). </li>
<li>XmlOptions.setValidateTreatLaxAsSkip -- Tells XMLBeans that it should skip elements matching an particle with contentModel=&quot;lax&quot; during validation. </li>
</ul>
<p>Also, see the <a href="#validation_as_you_go">section on validating as you go</a> for information about using the <code>XmlOptions.setValidateOnSet</code> method.</p>
<h3><a name="retrieving_error_messages" id="retrieving_error_messages"></a>Retrieving Error Messages About Invalid XML</h3>
<p>When you'll be validating with one of the <code>validate</code> methods, you can specify a <code>java.util.Collection</code> implementation as an error listener. As validation occurs, errors are added to the listener. After validation (and if the instance is found to be invalid) you can examine the errors. Here's an example:</p>
<pre>// Set up the validation error listener.
ArrayList validationErrors = new ArrayList();
XmlOptions validationOptions = new XmlOptions();
validationOptions.setErrorListener(validationErrors);
MyDocument myDoc = MyDocument.Factory.parse(pathToXml);
// Do some editing to myDoc.
// During validation, errors are added to the ArrayList for
// retrieval and printing by the printErrors method.
boolean isValid = myDoc.validate(validationOptions);
// Print the errors if the XML is invalid.
if (!isValid)
{
Iterator iter = validationErrors.iterator();
while (iter.hasNext())
{
System.out.println(">> " + iter.next() + "\n");
}
}</pre>
<h3><a name="validation_as_you_go" id="validation_as_you_go"></a>Validation As You Go</h3>
<p>By default, an XML instance will not be validated at run time as your code makes changes. However, you can change this behavior for limited on-the-fly validation. To do this, you specify the &quot;validate on set&quot; option when you create the XMLBeans type instance &#8212; you do this with the <code>XmlOptions.setValidateOnSet</code> method. </p>
<p>When you specify this option, XMLBeans with throw an exception when your code invalidates the XML through a set* method. Note that you can't specify an error listener for use in conjunction with this means of validating. Also, with &quot;validate on set,&quot; only simple schema types will be validated. Schema types not validated by this approach include, for example, those defining elements with attributes or elements with children.</p>
<p>Because its functionality is limited to simple schema types and it validates for set* method calls, you should regard this validation approach as a debugging tool, rather than an alternative to using a <code>validate</code> method. For example, you might use it to determine which errant bit of code is creating an invalid chunk of XML.</p>
<p class="notepara"><strong>Note:</strong> This sort of validation is not supported during changes you make using an <code>XmlCursor</code> instance.</p>
<p>Among the methods you can use to create an XMLBeans instance &#8212; the <code>parse</code> methods and the <code>newInstance</code> method &#8212; you'll find versions that take an <code>XmlOptions</code> instance as a parameter. Specifying this option would look something like the following: </p>
<pre>XmlOptions validateOptions = new XmlOptions();
// Tell XMLBeans you want to validate on the fly.
validateOptions.setValidateOnSet();
// Create the new instance, specifying the option.
PurchaseOrder newPo = PurchaseOrder.Factory.newInstance(validateOptions);
// ... Code to edit the instance via get and set methods ... </pre>
<div>
<p class="relatedtopics"> Related Topics </p>
<p> <a href="conGettingStartedwithXMLBeans.html">Getting Started with XMLBeans</a> </p>
</div>
<!-- InstanceEndEditable -->
<script language="JavaScript">
</script>
</body>
</html>

View File

@@ -0,0 +1,343 @@
<!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>Java Types for XML Schema</title>
<!-- InstanceEndEditable -->
<!--(Meta)==========================================================-->
<meta http-equiv=Content-Type content="text/html; charset=$CHARSET;">
<!-- InstanceBeginEditable name="metatags" -->
<meta name="author" content="your name">
<meta name="description" content="A description of the topic contents.">
<meta name="keywords" content="keywords to help in searches">
<meta name="date last modified" content="10/25/02">
<!-- 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> XMLBeans Support for Built-In Schema Types</h1>
<p>Just as with types in XML schema, the XMLBeans types based on schema are arranged
in a hierarchy. In general, the hierarchy of XMLBean types mirrors the hierarchy
of the schema types themselves. XML schema types all inherit from <span class="langinline">xs:anyType</span>
(which is at the root of the hierarchy); XMLBeans types inherit from <span class="langinline">XmlObject</span>.</p>
<p>In XML schema, <span class="langinline">xs:anyType</span> is the root type
for two type categories: built-in and user-derived. Built-in schema types are
common types defined by the XML schema specification. User-derived types are
those you define in your schema. This topic lists the built-in types provided
with XMLBeans. For information about user-derived types and the Java types generated
from them, see <a href="conJavaTypesGeneratedFromUserDerived.html">Java Types Generated
from User-Derived Schema Types</a>.</p>
<p>The following figure illustrates the hierarchy of types, showing both built-in
schema types and their XMLBeans parallels. Notice, too, that nearly all of the
built-in types are also available as natural Java types.</p>
<p><img src="../images/conXMLTypeHierarchy.gif" width="865" height="887"> </p>
<h1>Java Types Representing Built-In Schema Types</h1>
<p>As you can see from the figure above, all 46 built-in schema types are represented
by an XMLBean type provided with XMLBeans. When using built-in XMLBean types,
keep in mind that:</p>
<ul>
<li> Since <span class="langinline">XmlObject</span> corresponds to the <span class="langinline">xs:anyType</span>,
all Java XMLBean types inherit from <span class="langinline">XmlObject</span>.
Therefore all XMLBean types share the <span class="langinline">XmlObject</span>
interfaces ability to create an <span class="langinline">XmlCursor</span>
at the position of the object. They can also render the XML as strings or
streams.
<li>
<div>Where there is a corresponding natural Java type, the XMLBeans type provides
a way to get the underlying XML's value as the natural type. See the table
in this topic for information on how natural Java types map to XMLBeans
types. </div>
<li> Values assigned to built-in XMLBeans types are validated in keeping with
the rules of the schema type they represent. So, for example, an attempt to
assign a negative integer value to an <span class="langinline">XmlPositiveInteger</span>
will throw an <span class="langinline">XmlValueOutOfRange</span> exception.</li>
</ul>
<div>
<p>The following table lists the built-in schema types, along with their XMLBeans
and natural Java parallels. Unless otherwise noted, natural Java types are
in the <span class="langinline">java.lang</span> package; XMLBean types are
in the <span class="langinline">org.apache.xmlbeans</span> package.</p>
</div>
<div id="topictext">
<table>
<tr>
<td width="30%"><strong>Built-In Schema Type</strong></td>
<td width="31%"><strong>XMLBean Type</strong></td>
<td width="39%"><strong>Natural Java Type</strong></td>
</tr>
<tr>
<td>xs:anyType</td>
<td><a href="../reference/org/apache/xmlbeans/XmlObject.html">XmlObject</a></td>
<td> <a href="../reference/org/apache/xmlbeans/XmlObject.html">org.apache.xmlbeans.XmlObject</a></td>
</tr>
<tr>
<td><a href="http://www.w3.org/TR/xmlschema-2/#dt-anySimpleType" target="_blank">xs:anySimpleType</a></td>
<td><a href="../reference/org/apache/xmlbeans/XmlAnySimpleType.html">XmlAnySimpleType</a></td>
<td> <a href="http://java.sun.com/j2se/1.4.1/docs/api/java/lang/String.html" target="_blank">String</a></td>
</tr>
<tr>
<td><a href="http://www.w3.org/TR/xmlschema-2/#anyURI" target="_blank">xs:anyURI</a></td>
<td><a href="../reference/org/apache/xmlbeans/XmlAnyURI.html">XmlAnyURI</a></td>
<td><a href="http://java.sun.com/j2se/1.4.1/docs/api/java/lang/String.html" target="_blank">String</a></td>
</tr>
<tr>
<td><a href="http://www.w3.org/TR/xmlschema-2/#base64Binary" target="_blank">xs:base64Binary</a></td>
<td><a href="../reference/org/apache/xmlbeans/XmlBase64Binary.html">XmlBase64Binary</a></td>
<td>byte[]</td>
</tr>
<tr>
<td><a href="http://www.w3.org/TR/xmlschema-2/#boolean" target="_blank">xs:boolean</a></td>
<td><a href="../reference/org/apache/xmlbeans/XmlBoolean.html">XmlBoolean</a></td>
<td>boolean</td>
</tr>
<tr>
<td><a href="http://www.w3.org/TR/xmlschema-2/#byte" target="_blank">xs:byte</a></td>
<td><a href="../reference/org/apache/xmlbeans/XmlByte.html">XmlByte</a></td>
<td>byte</td>
</tr>
<tr>
<td height="17"><a href="http://www.w3.org/TR/xmlschema-2/#date" target="_blank">xs:date</a></td>
<td><a href="../reference/org/apache/xmlbeans/XmlDate.html">XmlDate</a></td>
<td><a href="http://java.sun.com/j2se/1.4.2/docs/api/java/util/Calendar.html" target="_blank">java.util.Calendar</a></td>
</tr>
<tr>
<td><a href="http://www.w3.org/TR/xmlschema-2/#dateTime" target="_blank">xs:dateTime</a></td>
<td><a href="../reference/org/apache/xmlbeans/XmlDateTime.html">XmlDateTime</a></td>
<td><a href="http://java.sun.com/j2se/1.4.2/docs/api/java/util/Calendar.html" target="_blank">java.util.Calendar</a></td>
</tr>
<tr>
<td><a href="http://www.w3.org/TR/xmlschema-2/#decimal" target="_blank">xs:decimal</a></td>
<td><a href="../reference/org/apache/xmlbeans/XmlDecimal.html">XmlDecimal</a></td>
<td><a href="http://java.sun.com/j2se/1.4.2/docs/api/java/math/BigDecimal.html" target="_blank">java.math.BigDecimal</a></td>
</tr>
<tr>
<td><a href="http://www.w3.org/TR/xmlschema-2/#double" target="_blank">xs:double</a></td>
<td><a href="../reference/org/apache/xmlbeans/XmlDouble.html">XmlDouble</a></td>
<td>double</td>
</tr>
<tr>
<td><a href="http://www.w3.org/TR/xmlschema-2/#duration" target="_blank">xs:duration</a></td>
<td><a href="../reference/org/apache/xmlbeans/XmlDuration.html">XmlDuration</a></td>
<td><a href="../reference/org/apache/xmlbeans/GDuration.html">org.apache.xmlbeans.GDuration</a></td>
</tr>
<tr>
<td><a href="http://www.w3.org/TR/xmlschema-2/#ENTITIES" target="_blank">xs:ENTITIES</a></td>
<td><a href="../reference/org/apache/xmlbeans/XmlENTITIES.html">XmlENTITIES</a></td>
<td><a href="http://java.sun.com/j2se/1.4.1/docs/api/java/lang/String.html" target="_blank">String</a></td>
</tr>
<tr>
<td><a href="http://www.w3.org/TR/xmlschema-2/#ENTITY" target="_blank">xs:ENTITY</a></td>
<td><a href="../reference/org/apache/xmlbeans/XmlENTITY.html">XmlENTITY</a></td>
<td><a href="http://java.sun.com/j2se/1.4.1/docs/api/java/lang/String.html" target="_blank">String</a></td>
</tr>
<tr>
<td><a href="http://www.w3.org/TR/xmlschema-2/#float" target="_blank">xs:float</a></td>
<td><a href="../reference/org/apache/xmlbeans/XmlFloat.html">XmlFloat</a></td>
<td>float</td>
</tr>
<tr>
<td><a href="http://www.w3.org/TR/xmlschema-2/#gDay" target="_blank">xs:gDay</a></td>
<td><p><a href="../reference/org/apache/xmlbeans/XmlGDay.html">XmlGDay</a></p></td>
<td><a href="http://java.sun.com/j2se/1.4.2/docs/api/java/util/Calendar.html" target="_blank">java.util.Calendar</a></td>
</tr>
<tr>
<td><a href="http://www.w3.org/TR/xmlschema-2/#gMonth" target="_blank">xs:gMonth</a></td>
<td><a href="../reference/org/apache/xmlbeans/XmlGMonth.html">XmlGMonth</a></td>
<td><a href="http://java.sun.com/j2se/1.4.2/docs/api/java/util/Calendar.html" target="_blank">java.util.Calendar</a></td>
</tr>
<tr>
<td><a href="http://www.w3.org/TR/xmlschema-2/#gMonthDay" target="_blank">xs:gMonthDay</a></td>
<td><a href="../reference/org/apache/xmlbeans/XmlGMonthDay.html">XmlGMonthDay</a></td>
<td><a href="http://java.sun.com/j2se/1.4.2/docs/api/java/util/Calendar.html" target="_blank">java.util.Calendar</a></td>
</tr>
<tr>
<td><a href="http://www.w3.org/TR/xmlschema-2/#gYear" target="_blank">xs:gYear</a></td>
<td><a href="../reference/org/apache/xmlbeans/XmlGYear.html">XmlGYear</a></td>
<td><a href="http://java.sun.com/j2se/1.4.2/docs/api/java/util/Calendar.html" target="_blank">java.util.Calendar</a></td>
</tr>
<tr>
<td><a href="http://www.w3.org/TR/xmlschema-2/#gYearMonth" target="_blank">xs:gYearMonth</a></td>
<td><a href="../reference/org/apache/xmlbeans/XmlGYearMonth.html">XmlGYearMonth</a></td>
<td><a href="http://java.sun.com/j2se/1.4.2/docs/api/java/util/Calendar.html" target="_blank">java.util.Calendar</a></td>
</tr>
<tr>
<td><a href="http://www.w3.org/TR/xmlschema-2/#hexBinary" target="_blank">xs:hexBinary</a></td>
<td><a href="../reference/org/apache/xmlbeans/XmlHexBinary.html">XmlHexBinary</a></td>
<td>byte[]</td>
</tr>
<tr>
<td><a href="http://www.w3.org/TR/xmlschema-2/#ID" target="_blank">xs:ID</a></td>
<td><a href="../reference/org/apache/xmlbeans/XmlID.html">XmlID</a></td>
<td><a href="http://java.sun.com/j2se/1.4.1/docs/api/java/lang/String.html" target="_blank">String</a></td>
</tr>
<tr>
<td><a href="http://www.w3.org/TR/xmlschema-2/#IDREF" target="_blank">xs:IDREF</a></td>
<td><a href="../reference/org/apache/xmlbeans/XmlIDREF.html">XmlIDREF</a></td>
<td><a href="http://java.sun.com/j2se/1.4.1/docs/api/java/lang/String.html" target="_blank">String</a></td>
</tr>
<tr>
<td><a href="http://www.w3.org/TR/xmlschema-2/#IDREFS" target="_blank">xs:IDREFS</a></td>
<td><a href="../reference/org/apache/xmlbeans/XmlIDREFS.html">XmlIDREFS</a></td>
<td><a href="http://java.sun.com/j2se/1.4.1/docs/api/java/lang/String.html" target="_blank">String</a></td>
</tr>
<tr>
<td><a href="http://www.w3.org/TR/xmlschema-2/#int" target="_blank">xs:int</a></td>
<td><a href="../reference/org/apache/xmlbeans/XmlInt.html">XmlInt</a></td>
<td>int</td>
</tr>
<tr>
<td><a href="http://www.w3.org/TR/xmlschema-2/#integer" target="_blank">xs:integer</a></td>
<td><a href="../reference/org/apache/xmlbeans/XmlInteger.html">XmlInteger</a></td>
<td><a href="http://java.sun.com/j2se/1.4.2/docs/api/java/math/BigInteger.html" target="_blank">java.math.BigInteger</a></td>
</tr>
<tr>
<td><a href="http://www.w3.org/TR/xmlschema-2/#language" target="_blank">xs:language</a></td>
<td><a href="../reference/org/apache/xmlbeans/XmlLanguage.html">XmlLanguage</a></td>
<td><a href="http://java.sun.com/j2se/1.4.1/docs/api/java/lang/String.html" target="_blank">String</a></td>
</tr>
<tr>
<td><a href="http://www.w3.org/TR/xmlschema-2/#long" target="_blank">xs:long</a></td>
<td><a href="../reference/org/apache/xmlbeans/XmlLong.html">XmlLong</a></td>
<td>long</td>
</tr>
<tr>
<td><a href="http://www.w3.org/TR/xmlschema-2/#Name" target="_blank">xs:Name</a></td>
<td><a href="../reference/org/apache/xmlbeans/XmlName.html">XmlName</a></td>
<td><a href="http://java.sun.com/j2se/1.4.1/docs/api/java/lang/String.html" target="_blank">String</a></td>
</tr>
<tr>
<td><a href="http://www.w3.org/TR/xmlschema-2/#NCName" target="_blank">xs:NCName</a></td>
<td><a href="../reference/org/apache/xmlbeans/XmlNCName.html">XmlNCNAME</a></td>
<td><a href="http://java.sun.com/j2se/1.4.1/docs/api/java/lang/String.html" target="_blank">String</a></td>
</tr>
<tr>
<td><a href="http://www.w3.org/TR/xmlschema-2/#negativeInteger" target="_blank">xs:negativeInteger</a></td>
<td><a href="../reference/org/apache/xmlbeans/XmlNegativeInteger.html">XmlNegativeInteger</a></td>
<td><a href="http://java.sun.com/j2se/1.4.2/docs/api/java/math/BigInteger.html" target="_blank">java.math.BigInteger</a></td>
</tr>
<tr>
<td><a href="http://www.w3.org/TR/xmlschema-2/#NMTOKEN" target="_blank">xs:NMTOKEN</a></td>
<td><a href="../reference/org/apache/xmlbeans/XmlNMTOKEN.html">XmlNMTOKEN</a></td>
<td><a href="http://java.sun.com/j2se/1.4.1/docs/api/java/lang/String.html" target="_blank">String</a></td>
</tr>
<tr>
<td><a href="http://www.w3.org/TR/xmlschema-2/#NMTOKENS" target="_blank">xs:NMTOKENS</a></td>
<td><a href="../reference/org/apache/xmlbeans/XmlNMTOKENS.html">XmlNMTOKENS</a></td>
<td><a href="http://java.sun.com/j2se/1.4.1/docs/api/java/lang/String.html" target="_blank">String</a></td>
</tr>
<tr>
<td><a href="http://www.w3.org/TR/xmlschema-2/#nonNegativeInteger" target="_blank">xs:nonNegativeInteger</a></td>
<td><a href="../reference/org/apache/xmlbeans/XmlNonNegativeInteger.html">XmlNonNegativeInteger</a></td>
<td><a href="http://java.sun.com/j2se/1.4.2/docs/api/java/math/BigInteger.html" target="_blank">java.math.BigInteger</a></td>
</tr>
<tr>
<td><a href="http://www.w3.org/TR/xmlschema-2/#nonPositiveInteger" target="_blank">xs:nonPositiveInteger</a></td>
<td><a href="../reference/org/apache/xmlbeans/XmlNonPositiveInteger.html">XmlNonPositiveInteger</a></td>
<td><a href="http://java.sun.com/j2se/1.4.2/docs/api/java/math/BigInteger.html" target="_blank">java.math.BigInteger</a></td>
</tr>
<tr>
<td><a href="http://www.w3.org/TR/xmlschema-2/#normalizedString" target="_blank">xs:normalizedString</a></td>
<td><a href="../reference/org/apache/xmlbeans/XmlNormalizedString.html">XmlNormalizedString</a></td>
<td><a href="http://java.sun.com/j2se/1.4.1/docs/api/java/lang/String.html" target="_blank">String</a></td>
</tr>
<tr>
<td><a href="http://www.w3.org/TR/xmlschema-2/#NOTATION" target="_blank">xs:NOTATION</a></td>
<td><a href="../reference/org/apache/xmlbeans/XmlNOTATION.html">XmlNOTATION</a></td>
<td> Not supported</td>
</tr>
<tr>
<td><a href="http://www.w3.org/TR/xmlschema-2/#positiveInteger" target="_blank">xs:positiveInteger</a></td>
<td><a href="../reference/org/apache/xmlbeans/XmlPositiveInteger.html">XmlPositiveInteger</a></td>
<td><a href="http://java.sun.com/j2se/1.4.2/docs/api/java/math/BigInteger.html" target="_blank">java.math.BigInteger</a></td>
</tr>
<tr>
<td><a href="http://www.w3.org/TR/xmlschema-2/#QName" target="_blank">xs:QName</a></td>
<td><a href="../reference/org/apache/xmlbeans/XmlQName.html">XmlQName</a></td>
<td><a href="http://java.sun.com/j2ee/1.4/docs/api/javax/xml/namespace/QName.html" target="_blank">javax.xml.namespace.QName</a></td>
</tr>
<tr>
<td><a href="http://www.w3.org/TR/xmlschema-2/#short" target="_blank">xs:short</a></td>
<td><a href="../reference/org/apache/xmlbeans/XmlShort.html">XmlShort</a></td>
<td>short</td>
</tr>
<tr>
<td><a href="http://www.w3.org/TR/xmlschema-2/#string" target="_blank">xs:string</a></td>
<td><a href="../reference/org/apache/xmlbeans/XmlString.html">XmlString</a></td>
<td><a href="http://java.sun.com/j2se/1.4.1/docs/api/java/lang/String.html" target="_blank">String</a></td>
</tr>
<tr>
<td><a href="http://www.w3.org/TR/xmlschema-2/#time" target="_blank">xs:time</a></td>
<td><a href="../reference/org/apache/xmlbeans/XmlTime.html">XmlTime</a></td>
<td><a href="http://java.sun.com/j2se/1.4.2/docs/api/java/util/Calendar.html" target="_blank">java.util.Calendar</a></td>
</tr>
<tr>
<td><a href="http://www.w3.org/TR/xmlschema-2/#token" target="_blank">xs:token</a></td>
<td><a href="../reference/org/apache/xmlbeans/XmlToken.html">XmlToken</a></td>
<td><a href="http://java.sun.com/j2se/1.4.1/docs/api/java/lang/String.html" target="_blank">String</a></td>
</tr>
<tr>
<td><a href="http://www.w3.org/TR/xmlschema-2/#unsignedByte" target="_blank">xs:unsignedByte</a></td>
<td><a href="../reference/org/apache/xmlbeans/XmlUnsignedByte.html">XmlUnsignedByte</a></td>
<td>short</td>
</tr>
<tr>
<td><a href="http://www.w3.org/TR/xmlschema-2/#unsignedInt" target="_blank">xs:unsignedInt</a></td>
<td><a href="../reference/org/apache/xmlbeans/XmlUnsignedInt.html">XmlUnsignedInt</a></td>
<td>long</td>
</tr>
<tr>
<td><a href="http://www.w3.org/TR/xmlschema-2/#unsignedLong" target="_blank">xs:unsignedLong</a></td>
<td><a href="../reference/org/apache/xmlbeans/XmlUnsignedLong.html">XmlUnsignedLong</a></td>
<td><a href="http://java.sun.com/j2se/1.4.2/docs/api/java/math/BigInteger.html" target="_blank">java.math.BigInteger</a></td>
</tr>
<tr>
<td><a href="http://www.w3.org/TR/xmlschema-2/#unsignedShort" target="_blank">xs:unsignedShort</a></td>
<td><a href="../reference/org/apache/xmlbeans/XmlUnsignedShort.html">XmlUnsignedShort</a></td>
<td>int</td>
</tr>
</table>
</div>
<div>
<p class="relatedtopics">Related Topics</p>
<p><a href="conGettingStartedwithXMLBeans.html">Getting Started with XMLBeans</a></p>
</div>
<!-- InstanceEndEditable -->
<script language="JavaScript">
</script>
</body>
</html>

View File

@@ -0,0 +1,542 @@
<!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>
XMLBeans Tools
</title>
<!-- InstanceEndEditable --> <!--(Meta)==========================================================-->
<meta http-equiv=Content-Type content="text/html; charset=$CHARSET;">
<!-- InstanceBeginEditable name="metatags" -->
<meta name="author" content="your name">
<meta name="description" content="A description of the topic contents.">
<meta name="keywords" content="keywords to help in searches">
<meta name="date last modified" content="10/25/02">
<!-- InstanceEndEditable --> <!--(Links)=========================================================--> <!-- InstanceBeginEditable name="head" --> <link href="../xmlbeans.css" rel="stylesheet" type="text/css"> <!-- InstanceEndEditable --> <link href="../xmlbeans.css" rel="stylesheet" type="text/css">
<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> XMLBeans Tools </h1>
<p> XMLBeans includes several command-line tools you might find handy as shortcuts
for common tasks. You'll find these tools in the bin directory of the XMLBeans
installation or source tree.</p>
<dl>
<dt> <a href="#dumpxsb">dumpxsb (XSB File Dumper)</a> </dt>
<dd> Prints the contents of an XSB file in human-readable form. </dd>
<dt>&nbsp; </dt>
<dt> <a href="#inst2xsd">inst2xsd (Instance to Schema Tool)</a> </dt>
<dd> Generates XML schema from XML instance files. </dd>
<dt>&nbsp; </dt>
<dt> <a href="#scomp">scomp (Schema Compiler)</a> </dt>
<dd> Compiles a schema into XMLBeans classes and metadata. </dd>
<dt>&nbsp; </dt>
<dt> <a href="#scopy">scopy (Schema Copier)</a> </dt>
<dd> Copies the XML schema at the specified URL to the specified file. </dd>
<dt>&nbsp; </dt>
<dt> <a href="#sdownload">sdownload (Schema Downloader)</a> </dt>
<dd> Maintains &quot;xsdownload.xml,&quot; an index of locally downloaded XSD
files. URLs that are specified are downloaded if they aren't already cached.
If no files or URLs are specified, all indexed files are relevant. </dd>
<dt>&nbsp; </dt>
<dt> <a href="#sfactor">sfactor (Schema Factoring Tool)</a> </dt>
<dd> Factors redundant definitions out of a set of schemas and uses imports
instead. </dd>
<dt>&nbsp; </dt>
<dt> <a href="#svalidate">svalidate (Streaming Instance Validator)</a> </dt>
<dd> Validates a schema definition and instances within the schema. </dd>
<dt>&nbsp; </dt>
<dt> <a href="#validate">validate (Instance Validator)</a> </dt>
<dd> Validates an instance against a schema. </dd>
<dt>&nbsp; </dt>
<dt> <a href="#xpretty">xpretty (XML Pretty Printer)</a> </dt>
<dd> Pretty prints the specified XML to the console. </dd>
<dt>&nbsp; </dt>
<dt> <a href="#xsd2inst">xsd2inst (Schema to Instance Tool)</a> </dt>
<dd> Prints an XML instance from the specified global element using the specified
schema. </dd>
<dt>&nbsp; </dt>
<dt> <a href="#xsdtree">xsdtree (Schema Type Hierarchy Printer)</a> </dt>
<dd> Prints an inheritance hierarchy of the types defined in a schema. </dd>
<dt>&nbsp; </dt>
<dt> <a href="antXmlbean.html">xmlbean Ant task</a> </dt>
<dd> Compiles a set of XSD and/or WSDL files into XMLBeans types. </dd>
</dl>
<h2> <a name="dumpxsb"></a>dumpxsb (XSB File Dumper) </h2>
<p> Prints the contents of an XSB file in human-readable form. An XSB file contains
schema meta information needed to perform tasks such as binding and validation.
&quot;XSB&quot; stands for XML Schema Binary.</p>
<h3> Syntax </h3>
<pre><strong>dumpxsb </strong><em>myfile.xsb</em></pre>
<h4> Options </h4>
<dl>
<dt> <em>myfile.xsb</em> </dt>
<dd> The name of an XSB file. </dd>
</dl>
<h3> Example </h3>
<p> The following command and output example use an XSB file generated by compiling
the schema (in EasyPo.xsd) that accompanies the SubstitutionGroup sample. </p>
<pre>dumpxsb PurchaseOrderDocument.xsb</pre>
<p> Output: </p>
<pre>PurchaseOrderDocument.xsb
Magic cookie: da7ababe
Major version: 2
Minor version: 22
Release number: 0
Filetype: FILETYPE_SCHEMAPOINTER
String pool (2):
1 = &quot;schema.system.s633ECC92E6CC0ACA137B11B7B38CA3A8&quot;
Type system: schema.system.s633ECC92E6CC0ACA137B11B7B38CA3A8</pre>
<h2> <a name="inst2xsd"></a>inst2xsd (Instance to Schema Tool) </h2>
<p> Generates XML schema from XML instance files. </p>
<h3> Syntax </h3>
<pre><strong>inst2xsd </strong>[<em>options</em>] <em>instance.xml</em>*</pre>
<h4> Options </h4>
<dl>
<dt> <strong>-design </strong>[<strong>rd </strong>|<strong> ss </strong>|<strong>
vb</strong>] </dt>
<dd> The XML schema design type to use for the generated schema. </dd>
<dd> <strong>rd</strong> &#8212; Use russian doll design; local elements and
local types. </dd>
<dd> <strong>ss</strong> &#8212; Use salami slice design; global elements and
local types. </dd>
<dd> <strong>vb</strong> (default) &#8212; Use venetian blind design; local
elements and global complex types. </dd>
</dl>
<dt> <strong>-simple-content-types</strong> [<strong>smart</strong> | <strong>string</strong>]
</dt>
<dd> The manner for detecting content types (leaf text) </dd>
<dd> <strong>smart</strong> (default) &#8212; Use a likely type, such as xs:byte
for a value of &quot;123&quot;. </dd>
<dd> <strong>string</strong> &#8212; Use xs:string as the type. </dd>
<dt>&nbsp; </dt>
<dt> <strong>-enumerations</strong> [<strong>never</strong> | <em>number</em>]
</dt>
<dd> Whether to use enumerations. </dd>
<dd> <strong>never</strong> &#8212; Never use enumerations. </dd>
<dd> <em>number</em> (default: 10) &#8212; Use <em>number</em> as the threshold
for enumerations. Specifying &quot;2&quot; will create enumerations for elements
with no more than two different values. </dd>
<dt>&nbsp; </dt>
<dt> <strong>-outDir</strong> [<em>dir</em>] </dt>
<dd> The directory for output files. </dd>
<dd> <em>dir</em> &#8212; Directory path. Default is '.' (the current directory).
</dd>
<dt>&nbsp; </dt>
<dt> <strong>-outPrefix</strong> [<em>file_name_prefix</em>] </dt>
<dd> The prefix for output file names. </dd>
<dd> <em>file_name_prefix</em> &#8212; Prefix to use. Default is &quot;schema&quot;.
</dd>
<dt>&nbsp; </dt>
<dt> <strong>-validate</strong> </dt>
<dd> Validate input instances against generated schemas. </dd>
<dt>&nbsp; </dt>
<dt> <strong>-verbose</strong> </dt>
<dd> Print more informational messages. </dd>
<dt>&nbsp; </dt>
<dt> <strong>-license</strong> </dt>
<dd> Print license information. </dd>
<dt>&nbsp; </dt>
<dt> <strong>-help</strong> </dt>
<dd> Print help information. </dd>
<h3> Example </h3>
<p> The following example generates schema0.xsd from Purchase-Order.xml, with
salami slice schema design, simple content types detected where possible, and
enumerations limited to elements with four different values. </p>
<pre>inst2xsd -design ss -simple-content-types smart -enumerations 4 Purchase-Order.xml</pre>
<h2> <a name="scomp"></a>scomp (Schema Compiler) </h2>
<p> Compiles schema into Java XMLBeans classes and metadata. Schema-related work
with XMLBeans begins by compiling schema to generated Java types. You can use
scomp to compile schema from the command line. XMLBeans also provides an Ant
task, <a href="antXmlbean.html">xmlbeans</a>, which you can use to compile schemas.
For run-time schema compilation that doesn't generate files, see the org.apache.xmlbeans.XmlBeans.compileXsd
methods.</p>
<p>For more information about the types resulting from compiling schema, see <a href="conJavaTypesGeneratedFromUserDerived.html">Java
Types Generated from User-Derived Schema Types</a>, <a href="conXMLBeansSupportBuiltInSchemaTypes.html">XMLBeans
Support for Built-In Schema Types</a>, and <a href="conMethodsForGeneratedJavaTypes.html">Methods
for Types Generated From Schema</a>. </p>
<p>For more information on getting started with XMLBeans, see <a href="conGettingStartedwithXMLBeans.html">Getting
Started with XMLBeans</a>.</p>
<h3> Syntax </h3>
<pre><strong>scomp</strong> [<em>options</em>] [<em>dirs</em>]* [<em>schemaFile.xsd</em>]* [<em>service.wsdl</em>]* [<em>config.xsdconfig</em>]*</pre>
<h4> Options </h4>
<dl>
<dt> <strong>-cp</strong> [<em>pathA;pathB;pathC</em>] </dt>
<dd> Classpath specifying classes to include during compilation. </dd>
<dd> <em>pathA;pathB;pathC</em> &#8212; Class search path of directories and
JAR files. </dd>
<dt>&nbsp; </dt>
<dt> <strong>-d</strong> [<em>dir</em>] </dt>
<dd> Target directory for CLASS and XSB files. </dd>
<dd> <em>dir</em> &#8212; The directory path. </dd>
<dt>&nbsp; </dt>
<dt> <strong>-src</strong> [<em>dir</em>] </dt>
<dd> Target directory for generated JAVA files. </dd>
<dd> <em>dir</em> &#8212; The directory path. </dd>
<dt>&nbsp; </dt>
<dt> <strong>-srconly</strong> </dt>
<dd> Do not compile JAVA files or jar the output. </dd>
<dt>&nbsp; </dt>
<dd> Note that XSB files are needed in order for CLASS files compiled from the
sources to be useful as XMLBeans classes. To get <em>only JAVA files</em>,
use -src to specify a directory for the JAVA files. To get <em>JAVA and XSB
files in the same directory</em>, use -d to specify a directory that will
include both. To get <em>JAVA and XSB files in separate directories</em>,
use -src for the JAVA file destination and -d for the XSB file destination.
</dd>
<dt>&nbsp; </dt>
<dt> <strong>-out</strong> [<em>jarFileName</em>] </dt>
<dd> The name of the output JAR that will contain the result of compilation.
The default is &quot;xmltypes.jar&quot;. </dd>
<dd> <em>jarFileName</em> &#8212; The name for the JAR containing generated
files. </dd>
<dt>&nbsp; </dt>
<dt> <strong>-dl</strong> </dt>
<dd> Permit network downloads for imports and includes (this permission is off
by default). </dd>
<dt>&nbsp; </dt>
<dt> <strong>-noupa</strong> </dt>
<dd> Do not enforce the unique particle attribution rule. </dd>
<dt>&nbsp; </dt>
<dt> <strong>-nopvr</strong> </dt>
<dd> Do not enforce the particle valid (restriction) rule. </dd>
<dt>&nbsp; </dt>
<dt> <strong>-noann</strong> </dt>
<dd> Ignore annotations. </dd>
<dt>&nbsp; </dt>
<dt> <strong>-novdoc</strong> </dt>
<dd> Do not validate contents of &lt;documentation&gt; elements. </dd>
<dt>&nbsp; </dt>
<dt> <strong>-compiler</strong> </dt>
<dd> Path to external Java compiler. </dd>
<dt>&nbsp; </dt>
<dt> <strong>-javasource</strong> [<em>version</em>] </dt>
<dd> Generate Java source compatible for the specified Java version (1.4 or
1.5). </dd>
<dt>&nbsp; </dt>
<dt> <strong>-ms</strong> </dt>
<dd> Initial memory for external Java compiler; the default is &quot;8m&quot;.
</dd>
<dt>&nbsp; </dt>
<dt> <strong>-mx</strong> </dt>
<dd> Maximum memory for external Java compiler; the default is &quot;256m&quot;.
</dd>
<dt>&nbsp; </dt>
<dt> <strong>-debug</strong> </dt>
<dd> Compile with debug symbols. </dd>
<dt>&nbsp; </dt>
<dt> <strong>-quiet</strong> </dt>
<dd> Print fewer informational messages. </dd>
<dt>&nbsp; </dt>
<dt> <strong>-verbose</strong> </dt>
<dd> Print more informational messages. </dd>
<dt>&nbsp; </dt>
<dt> <strong>-version</strong> </dt>
<dd> Print version information. </dd>
<dt>&nbsp; </dt>
<dt> <strong>-license</strong> </dt>
<dd> Print license information. </dd>
<dt>&nbsp; </dt>
<dt> <strong>-allowmdef</strong> &quot;[<em>namespace</em>] [<em>namespace</em>]
[<em>namespace</em>]&quot; </dt>
<dd> Ignore multiple defs in given namespaces. Use <code> ##local </code> to
specify the no-namespace in that list. </dd>
<dt>&nbsp; </dt>
<dt> <strong>-catalog</strong> [<em>fileName</em>] </dt>
<dd> Catalog file to use for resolving external entities. With this option,
scomp uses <code> org.apache.xml.resolver.tools.CatalogResolver </code> for
resolving. Note that to use this option, your classpath must include resolver.jar
from http://xml.apache.org/commons/components/resolver/index.html). Copy resolver.jar
to the XMLBEANS_HOME/lib directory, so that the script can pick it up from
there. You can use the <a href="#sdownload">sdownload</a> tool to ensure that
required schemas are present for compilation. </dd>
<dd> <em>fileName &#8212; </em>A path to the catalog file. </dd>
<dt>&nbsp; </dt>
<dt> <em>dirs</em> </dt>
<dd> Directories containing XSD (and possibly XSDCONFIG) files that should be
compiled. </dd>
<dt>&nbsp; </dt>
<dt> <em>schemaFile.xsd</em> </dt>
<dd> The names of XSD files that should be compiled. </dd>
<dt>&nbsp; </dt>
<dt> <em>service.wsdl</em> </dt>
<dd> A WSDL file for which types should be generated. </dd>
<dt>&nbsp; </dt>
<dt> <em>config.xsdconfig</em> </dt>
<dd> The name of an XSDCONFIG file. Use an XSDCONFIG file to guide the naming
of generated classes and packages. Without an XSDCONFIG file, scomp uses the
schema's type names and URI for classes and packages. </dd>
</dl>
<h3> Example </h3>
<p> In the following example, scomp compiles EasyPO.xsd, guiding type naming with
po.xsdconfig. scomp puts generated CLASS and XSB files into a classes directory
one level up, and JAVA source files into a src directory one level up. Source
files will be compatible with Java version 1.5. </p>
<pre>scomp -d ..\classes -src ..\src -javasource 1.5 EasyPO.xsd po.xsdconfig</pre>
<p> Here, scomp compiles all of the contents of the schemas directory and puts
the generated files into poschema.jar one level up. </p>
<pre>scomp -out ..\poschema.jar schemas</pre>
<p> The following example generates JAVA source and XSB files from the schema
in EasyPO.xsd. No CLASS files are generated, and the JAVA and XSB files are
put into src and xsb directories, respectively. </p>
<pre>scomp -srconly -src ..\src -d ..\xsb EasyPO.xsd</pre>
<p> When the schema features imports or includes and you want to use a catalog,
you can tell scomp to use the default catalog resolver (<code>org.apache.xml.resolver.tools.CatalogResolver</code>);
you specify a catalog file with the -catalog option, as in the example below.
(Note that this requires resolver.jar, as noted above for the -catalog option.)
In this example, scomp compiles schemaThatUsesRequiredSchema.xsd into myschemas.jar,
resolving imports from requiredSchema.xsd through xsdownload.xml. The <a href="#sdownload">sdownload</a>
tool is executed first &#8212; this ensures that requiredSchema.xsd is present
for compilation, but does not actually download requiredSchema.xsd unless the
URL at which it's found isn't already cached. This is more efficient than using
scomp's -dl option, which attempts to download every time.</p>
<pre>sdownload "http://some.org/requiredSchema.xsd"
scomp -out ..\myschemas.jar -catalog xsdownload.xml schemaThatUsesRequiredSchema.xsd</pre>
<p> When a schema features multiple element declarations of the same qname, such
as multiple &lt;xs:any&gt; particles, you might want to disable to &quot;unique
particle validation&quot; rule, which would ordinarily invalidate the schema.
To do this, use the -noupa option, as in the following example. </p>
<pre>scomp -out ..\myschemas.jar -noupa schemas</pre>
<h2> <a name="scopy"></a>scopy (Schema Copier) </h2>
<p> Copies the XML schema at the specified URL to the specified file. </p>
<h3> Syntax </h3>
<pre><strong>schemacopy</strong> <em>sourceurl</em> [<em>targetfile</em>]</pre>
<h4> Options </h4>
<dl>
<dt> <strong>sourceurl</strong> </dt>
<dd> The URL at which the schema is located. </dd>
<dt>&nbsp; </dt>
<dt> <em>targetfile</em> </dt>
<dd> The file to which the schema should be copied. </dd>
</dl>
<h2> <a name="sdownload"></a>sdownload (Schema Downloader) </h2>
<p> Maintains &quot;xsdownload.xml,&quot; an index of locally downloaded XSD files.
URLs that are specified are downloaded if they aren't already cached. If no
files or URLs are specified, all indexed files are relevant. </p>
<p> You can use this tool when using <a href="#scomp">scomp</a>, in conjunction
with scomp's -catalog option, to ensure the presence of schemas that are required
for compilation because they're imported or included. This is an alternative
to using scomp's -dl option, which would hit the Internet on every invocation
of scomp. When you use sdownload with -catalog, the download occurs only if
the URL is not already cached. See the scomp section for an example.</p>
<h3> Syntax </h3>
<pre><strong>sdownload</strong> [<strong>-dir</strong> <em>directory</em>] [<strong>-refresh</strong>] [<strong>-recurse</strong>] [<strong>-sync</strong>] [<em>url/file</em>]</pre>
<h4> Options </h4>
<dl>
<dt> <strong>-dir </strong><em>directory</em> </dt>
<dd> The directory for the xsdownload.xml file (the default is &quot;.&quot;).
</dd>
<dd> <em>directory</em> &#8212; The directory path. </dd>
<dt>&nbsp; </dt>
<dt> <strong>-sync</strong> </dt>
<dd> Synchronize the index to any local XSD files in the tree. </dd>
<dt>&nbsp; </dt>
<dt> <strong>-recurse</strong> </dt>
<dd> Recursively download imported and included XSD files. </dd>
<dt>&nbsp; </dt>
<dt> <strong>-refresh</strong> </dt>
<dd> Re-download all indexed XSD files. </dd>
</dl>
<h2> <a name="sfactor"></a>sfactor (Schema Factoring Tool) </h2>
<p> Factors redundant definitions out of a set of schemas and uses imports instead.
</p>
<h3> Syntax </h3>
<pre><strong>sfactor</strong> [<strong>-import</strong> <em>common.xsd</em>] [<strong>-out</strong> <em>outputdir</em>] <em>inputdir [-license]</em></pre>
<h4> Options </h4>
<dl>
<dt> <strong>-import</strong> </dt>
<dd> The XSD file to contain redundant definitions for importing. </dd>
<dd> <em>common.xsd</em> &#8212; A path to the file. </dd>
<dt> <strong>-out</strong> <em>outputdir</em> </dt>
<dd> The directory into which to place XSD files resulting from refactoring,
plus a commonly imported common.xsd. </dd>
<dt> inputdir </dt>
<dd> The directory containing the XSD files with redundant definitions. </dd>
<dt> -license </dt>
<dd> Print license information. </dd>
</dl>
<h2> <a name="svalidate"></a>svalidate (Streaming Instance Validator) </h2>
<p> Validates the specified instance against the specified schema. Unlike the
<a href="#validate">validate</a> tool, svalidate uses a streaming model through
which you can validate much larger instances with less memory (if the schema
permits it).</p>
<h3> Syntax </h3>
<pre><strong>svalidate</strong> [<em>options</em>] <em>schema.xsd</em> <em>instance.xml</em></pre>
<h4> Options </h4>
<dl>
<dt> <strong>-dl</strong> </dt>
<dd> Enable network downloads for imports and includes. </dd>
<dt>&nbsp; </dt>
<dt> <strong>-nopvr</strong> </dt>
<dd> Disable particle valid (restriction) rule. </dd>
<dt>&nbsp; </dt>
<dt> <strong>-noupa</strong> </dt>
<dd> Disable unique particle attribution rule. </dd>
<dt>&nbsp; </dt>
<dt> <strong>-license</strong> </dt>
<dd> Print license information. </dd>
<dt>&nbsp; </dt>
<dt> <em>schema.xsd</em> </dt>
<dd> The schema against which to validate. </dd>
<dt>&nbsp; </dt>
<dt> <em>instance.xm</em>l </dt>
<dd> The instance to validate. </dd>
</dl>
<h2> <a name="validate" id="validate"></a>validate (Instance Validator) </h2>
<p> Validates a the specified instance against the specified schema. Compare this
tool with the <a href="#svalidate">svalidate</a> tool, which is useful for validating
very large documents. </p>
<h3> Syntax </h3>
<pre><strong>validate</strong> [<em>options</em>] <em>schema.xsd</em> <em>instance.xml</em></pre>
<h4> Options </h4>
<dl>
<dt> <strong>-dl</strong> </dt>
<dd> Enable network downloads for imports and includes. </dd>
<dt>&nbsp; </dt>
<dt> <strong>-nopvr</strong> </dt>
<dd> Disable particle valid (restriction) rule. </dd>
<dt>&nbsp; </dt>
<dt> <strong>-noupa</strong> </dt>
<dd> Disable unique particle attribution rule. </dd>
<dt>&nbsp; </dt>
<dt> <strong>-license</strong> </dt>
<dd> Print license information. </dd>
<dt>&nbsp; </dt>
<dt> <em>schema.xsd</em> </dt>
<dd> The schema against which to validate. </dd>
<dt>&nbsp; </dt>
<dt> <em>instance.xml</em> </dt>
<dd> The instance to validate. </dd>
</dl>
<h3> Example </h3>
<p> The following simple example validates PurchaseOrder.xml against EasyPO.xsd.
</p>
<pre>validate ..\schemas\EasyPO.xsd PurchaseOrder.xml</pre>
<p> In this example, MySchema imports types from another schema and also includes
multiple particles defined as &lt;xsd:any&gt; types. The validate command here
locates the external schemas for importing (providing there is network access
to the schemas) and ignores the validation rule whereby multiple particles of
the same qname render the schema invalid. </p>
<pre>validate -dl -noupa ..\schemas\MySchema.xsd AnInstance.xml</pre>
<h2> <a name="xpretty"></a>xpretty (XML Pretty Printer) </h2>
<p> Pretty prints the specified XML to the console. </p>
<h3> Syntax </h3>
<pre><strong>xpretty</strong> [<em>options</em>] <em>file.xml</em></pre>
<h4> Options </h4>
<dl>
<dt> <strong>-indent</strong> <em>numberOfSpaces</em> </dt>
<dd> Indent the specified number of spaces. </dd>
<dd> <em>numberOfSpaces</em> &#8212; The number of spaces to indent. </dd>
<dt>&nbsp; </dt>
<dt> <strong>-license</strong> </dt>
<dd> Print license information. </dd>
</dl>
<h2> <a name="xsd2inst"></a>xsd2inst (Schema to Instance Tool) </h2>
<p> Prints an XML instance from the specified global element using the specified
schema. </p>
<h3> Syntax </h3>
<pre><strong>xsd2inst</strong> <em>schemafile.xsd</em> <strong>-name</strong> <em>globalElementName</em></pre>
<h4> Options </h4>
<dl>
<dt> <em>schemafile.xsd</em> </dt>
<dd> The schema file defining the element to print. </dd>
<dt>&nbsp; </dt>
<dt> <strong>-name</strong> </dt>
<dd> The name of the global element </dd>
<dd> <em>globalElementName </em>&#8212; The local name of the global element
to use as the root of the printed instance. </dd>
</dl>
<h3> Example </h3>
<p> The following command and output use the schema that accompanies the SubstitutionGroup
sample. </p>
<pre>xsd2inst easypo.xsd -name invoice-header</pre>
<p> Output </p>
<pre>&lt;eas:invoice-header xmlns:eas=&quot;http://xmlbeans.apache.org/samples/substitutiongroup/easypo&quot;&gt;
&lt;eas:ship-to&gt;
&lt;eas:name&gt;string&lt;/eas:name&gt;
&lt;eas:address&gt;string&lt;/eas:address&gt;
&lt;/eas:ship-to&gt;
&lt;eas:bill-to&gt;
&lt;eas:name&gt;string&lt;/eas:name&gt;
&lt;eas:address&gt;string&lt;/eas:address&gt;
&lt;/eas:bill-to&gt;
&lt;!--Optional:--&gt;
&lt;eas:product id=&quot;3&quot;/&gt;
&lt;!--Optional:--&gt;
&lt;eas:comment&gt;string&lt;/eas:comment&gt;
&lt;/eas:invoice-header&gt;</pre>
<h2> <a name="xsdtree"></a>xsdtree (Schema Type Hierarchy Printer) </h2>
<p> Prints inheritance hierarchy of types defined in a schema. </p>
<h3> Syntax </h3>
<pre><strong>xsdtree</strong> [<strong>-noanon</strong>] [<strong>-nopvr</strong>] [<strong>-noupa</strong>] [<strong>-partial</strong>] [<strong>-license</strong>] <em>schemafile.xsd*</em></pre>
<h4> Options </h4>
<dl>
<dt> <strong>-noanon</strong> </dt>
<dd> Don't include anonymous types in the tree. </dd>
<dt>&nbsp; </dt>
<dt> <strong>-nopvr</strong> </dt>
<dd> Disable particle valid (restriction) rule. </dd>
<dt>&nbsp; </dt>
<dt> <strong>-noupa</strong> </dt>
<dd> Disable unique particle attribution rule. </dd>
<dt>&nbsp; </dt>
<dt> <strong>-partial</strong> </dt>
<dd> Print only part of the hierarchy. </dd>
<dt>&nbsp; </dt>
<dt> <strong>-license</strong> </dt>
<dd> Print license information. </dd>
<dt>&nbsp; </dt>
<dt> <em>schemafile.xsd</em> </dt>
<dd> The file containing the schema whose hierarchy should be printed. </dd>
</dl>
<h3> Example </h3>
<p> The following command and output use the schema that accompanies the SubstitutionGroup
sample. </p>
<pre>xsdtree easypo.xsd</pre>
<p> Output: </p>
<pre>xmlns:xs=&quot;http://www.w3.org/2001/XMLSchema&quot;
xmlns:eas=&quot;http://xmlbeans.apache.org/samples/substitutiongroup/easypo&quot;
+-xs:anyType (builtin)
+-xs:anySimpleType (builtin)
| +-xs:string (builtin)
| +-xs:normalizedString (builtin)
| +-xs:token (builtin)
| +-type of color element in eas:clothing-type (enumeration)
+-type of element eas:invoice-header
+-type of element eas:purchase-order
+-eas:product-type
| +-eas:clothing-type
| +-eas:book-type
+-eas:name-address</pre>
<h2> <a name="xmlbeans_ant"></a>xmlbean Ant task </h2>
<p> Compiles a set of XSD and/or WSDL files into XMLBeans types. See <a href="antXmlbean.html">xmlbean
Ant Task</a> for more complete documentation on the task. </p>
<div>
<p class="relatedtopics"> Related Topics </p>
<p> <a href="conGettingStartedwithXMLBeans.html">Getting Started with XMLBeans</a>
</p>
</div>
<!-- InstanceEndEditable -->
<script language="JavaScript">
</script>
</body>
</html>