apache > xmlbeans.apache.org
XMLBeans
 

XMLBeans Samples

Getting the Samples

Click the name of a sample listed below to go to a page that describes the sample in more detail. From there, you can view the files that make up the sample. This sample repository is just getting started, so be sure to check back for new additions.

To get started with the samples, follow the instructions on the Installing XMLBeans page first. Then get the sample code in one of the following ways:

  • download all samples (zip tgz)
  • download individual samples below
  • all sample source is available in SVN

If you have a sample that you'd like to share, grab the sample template and donate it to us. We'd be happy to post it!

Samples List

Title Download Date Available
All samples
Get 'em all at once.
zip tgz 2004-10-28
AbstractTypes
This sample illustrates the building and use of abstract XmlSchema types in XmlBeans.
zip tgz 2005-02-07
Any
Illustrates how you can use the XMLBeans API to work with XML based on schema that features xs:any particles
zip tgz 2005-07-08
DateTime
This sample demonstrates how you can work with XML Schema primitive types date, dateTime, time, duration, gDay.
zip tgz 2004-10-28
MixedContent
Work with mixed content XML by combining strong types generated from schema with an XmlCursor instance.
zip tgz 2004-09-15
OrderMatters
This samples gives an quick overview of how to use XmlBeans with both the strongly typed XmlObjects (StatementDocument, Transaction) and with the XmlCursor.
zip tgz 2004-10-28
SchemaEnum
Access XML values that are defined in schema as enumerations.
zip tgz 2004-09-15
SubstitutionGroup
This sample illustrates substitution group elements in an XML document.
zip tgz 2004-10-28
Validation
Illustrates how you can use the XMLBeans API to validate XML instances against schema.
zip tgz 2005-07-08
Velocity XmlBeans
Vxsdb is a XmlBeans sample application which derives a Jakarta Commons SQL data model from an xml schema.
zip tgz 2005-02-07
XmlTree
Illustrates how you can use the XMLBeans API to create a Java tree view of an XML document.
zip tgz 2005-07-08
XQueryXPath
Illustrates how you can use the XMLBeans API to execute XPath and XQuery expressions.
zip tgz 2005-07-08
SampleTemplate
A template for sample authors to get started. Please follow these conventions.
zip tgz 2004-09-15

Examples in XMLBeans Source

Also, some of the code in the XmlBeans tools is a very good example of how to use XmlBeans. In paricular, see:

  • org.apache.xmlbeans.impl.tool.InstanceValidator It is an excellent example of how to load a schema type system dynamically at runtime, load and validate an instance within that type system, and how to obtain lists of and locations for validation errors.
  • org.apache.xmlbeans.impl.xsd2inst.SampleXmlUtil It is a great example of how to combine the XmlCursor and SchemaType APIs to create a full [sub]document that includes required children, default values etc.
  • org.apache.xmlbeans.impl.tool.PrettyPrinter It is a reasonable example of how to load and save out an arbitrary XML document. XmlOptions are used to produce the pretty-printing.