- General Community Questions *
- Getting Started
- Where can I download the latest release of XMLBeans?
- What is the latest version of XMLBeans?
- How do I get started coding with XMLBeans?
- How can I get the latest XMLBeans source code in svn?
- How do I build XMLBeans from source?
- Can I view the XMLBeans Source Code online, without having svn on my machine?
- Is the XMLBeans javadoc available online?
- What jars do I need on the classpath to use XMLBeans?
- Running my code that used to work fails with "java.lang.NoClassDefFoundError: javax/xml/namespace/QName" after upgrading to 2.3.0
- The scomp program can't find javac and fails with java.io.IOException on Windows!
- The scomp program gives OutOfMemoryError when compiling my complex Schema!
- The scomp fails with code too large error!
- General XMLBeans Questions
- How can I write the PCDATA in Element which is complexType?
- What Java types are created for a particular schema type?
- Can I change the default package names for the java classes generated from my schema?
- Is there a way to do a deep equals between two Xmlobjects?
- How can I influence the namespace prefix used when saving/printing out my XML?
- How can I instruct XMLBeans to add the xsi:schemaLocation attribute to my documents?
- Is selectPath(...) on XmlObject and XmlCursor working?
- Is execQuery(...) on XmlObject and XmlCursor working?
- How do I modify the generated interfaces?
- How do I control CDATA?
- Why am I getting XmlValueDisconnectedException when I try to change an XmlObject?
- Schema Object Model Questions
- Is there an introduction document on the XMLBeans Schema Type System?
- How do I get the java name for a schema type?
- How do I get to SchemaAnnotation and SchemaIdentityConstraint on elements?
- What is the difference between SchemaProperty and SchemaParticle?
- How do I use substitution groups?
- How do I compile multiple schema files with dependencies?
- XmlCursor API
General Community Questions
What are the different XMLBeans Mailing Lists?
Who are the XMLBeans Committers?
Where do I file a bug for XMLBeans?
XMLBeans uses Jira for bugtracking.
What is the latest version of XMLBeans?
Check the news page for the latest release. The 1.0.4 release is the latest stable maintenance release. You will need JDK 1.4 for the 2.3.0 and 1.0.4 release. For JDK 1.3 users, there is a version of the 1.0.4 release compatible with JDK 1.3. For 2.6.0 release JDK 6 is required.
Where can I download the latest release of XMLBeans?
How do I get started coding with XMLBeans?
You can find lots of documentation on the XMLBeans' website. The Getting Started guide (http://xmlbeans.apache.org/docs/2.0.0/guide/conGettingStartedwithXMLBeans.html) is a good introduction to XMLBeans. Another excellent place to start is the tutorial.
How can I get the latest XMLBeans source code in svn?
XMLBeans Source Code Information. You will need a Subversion (svn) client.
Is the XMLBeans javadoc available online?
What jars do I need on the classpath to use XMLBeans?
- The obvious one is xbean.jar, which contains the XMLBeans code. scomp.cmd includes trailing periods after this on v1.0.4, which may cause problems under Windows XP.
- For XMLBeans V1, this is all you need, but for XMLBeans 2, the JSR173 API jar is also required, since it contains classes that XMLBeans depends on. For XMLBeans 2.0.0, the name of the jar is jsr173_api.jar and for XMLBeans 2.1.0, it's jsr173_1.0_api.jar. In both cases, the jar comes with the XMLBeans binary distribution (for source distributions, the build process will download it and place it in the build/lib directory.
- For JDK 1.4 users, as of XMLBeans 2.3.0 it has become necessary to also include xmlbeans-qname.jar
- If XPath/XQuery support is required, the xbean_xpath.jar contains the XPath "glue" code and needs to be included on the classpath. Then, depending on the version of XMLBeans in use, the following are also required: jaxen.jar for XMLBeans V1 (only supports XPath, no XQuery), saxon8.jar for XMLBeans V2.0.0 and V2.1.0 (the only version supported is Saxon 8.1.1), saxon8.jar and saxon8-dom.jar for XMLBeans built from SVN head (this supports Saxon >= 8.6.1).
Saxon supported version
- In addition to those, compiling Schemas using the scomp script requires tools.jar from the JDK and resolver.jar from Apache xml-commons (the latter one only in case support for OASIS XML catalogs for resolving external entities is needed).
- We make another jar available, xmlpublic.jar, which contains the classes in the "org.apache.xmlbeans" package. If your code can be compiled with xmlpublic.jar on the classpath instead of the full xbean.jar, it means that your code uses only "public", supported APIs and will likely not need any modification if you need to upgrade to a newer XMLBeans version.
Running my code that used to work fails with "java.lang.NoClassDefFoundError: javax/xml/namespace/QName" after upgrading to 2.3.0
See What jars do I need on the classpath to use XMLBeans?. You need to add xmlbeans-qname.jar on you classpath.
The scomp program can't find javac and fails with java.io.IOException on Windows!
On Windows, some users have reported that the scomp program fails when trying to run javac on the generated java source. First, be sure you have a JDK installed. The JRE doesn't have the javac program so you won't be able to compile the generated java source. If you have both a JDK and a JRE installed, the JRE's java is being found before the JDK's java. Since scomp uses the 'java.home' property to find the javac program, but javac is only available in the JDK, finding javac will fail.
The solution is to move the JDK higher up on the PATH in the environment. An alternate solution is to set JAVA_HOME and edit the scomp script to run %JAVA_HOME%\bin\java instead of relying on the PATH. The error you would see looks like:
If that doesn't fix the issue, try specifying relevant paths using Windows 8.3 names. This will get around issues with spaces in folder names.
The scomp program gives OutOfMemoryError when compiling my complex Schema!
The likely problem here is that because of the large number of source files that must be generated sometimes, the javac compilation step fails with insufficient memory. Here's how the problem manifests itself:
If you get this, you need to give javac more memory. But since javac is launched as an external process, tweaking the scomp.bat script and upping the memory that scomp has available will have no effect. The solution is to use the "-mx" parameter to scomp, for example:
The scomp fails with code too large error
This issue has been seen when running scomp xsds from www.niem.gov and www.it.ojp.gov/jxdm. When encountered in the schemas above is caused by a limitation of the JVM. It was discovered and noted by a JIRA issue.
The scomp tool does not currently have a solution for this.
How do I build XMLBeans?
Can I view the XMLBeans source code online, without having svn on my machine?
Yes you can use the CVS/SVNView to browse or link to the XMLBeans source code. Link to XMLBeans main dev trunk
General XMLBeans Questions
What Java types are created for a particular schema type?
- User Derived Schema Types 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 ... Java Types Generated from User-Derived Schema Types Built in Types 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 xs:anyType (which is at the root of the hierarchy); XMLBeans types inherit from XmlObject ... XMLBeans Support for Built-In Schema Types
Can I change the default package names for the java classes generated from my schema?
You can create a file that ends in .xsdconfig to map targetnamespace to packagename. Put the .xsdconfig file in the same directory as the .xsd that you are compiling. Here is an example .xsdconfig:
Notice that you can also map specific element/attribute names to java names.
Note: If schema doesn't include targenamespace then use
to specify package names
Note: XMLBeans doesn’t support using two or more sets of java classes (in different packages) mapped to schema types/elements that have the same names and target namespaces, using all in the same class loader. Depending on the direction you are using for the java classes to schema types mapping, some features might not work correctly. This is because even though the package names for the java classes are different, the schema location for the schema metadata (.xsb files) is the same and contains the corresponding implementing java class, so the JVM will always pick up the first on the classpath. This can be avoided if multiple class loaders are used.
Is there a way to do a deep equals between two XmlObjects?
Dmitri.Colebatch posted some code that will do a deep equals. You can find the code attached to this post http://nagoya.apache.org/eyebrowse/ReadMsg?listNamefirstname.lastname@example.org&msgNo=75
Kevin Krouse also posted some code that will do a deep equals but had some limitations addressed by Dmitri above. You can find the code attached to this post http://nagoya.apache.org/eyebrowse/ReadMsg?listNameemail@example.com&msgNo=69.
How can I influence the namespace prefix used when saving/printing out my XML?
XMLBeans does not keep the prefixes when the original XML is loaded into the underlying XML store. If you need/want a specific prefix to be associated with a namespace you can use the
Here is a code example from this helpful post, http://nagoya.apache.org/eyebrowse/ReadMsg?listNamefirstname.lastname@example.org&msgNo=33 :
How can I instruct XMLBeans to add the xsi:schemaLocation attribute to my documents?
Here's how to do it. Assume that you have a document represented by the doc XmlObject (obtained via TestDocument.Factory.newInstance() or TestDocument.Factory.parse()) and you need an xsi:schemaLocation attribute on it, with value from the location String.
Is selectPath(...) on XmlObject and XmlCursor working?
To use more advanced XPath expressions in 1.0.4, the Jaxen engine can be used if xbean_xpath.jar is on the classpath. The xbean_xpath.jar is available in build\private\lib by running 'ant xbean_xpath.jar'.
Is execQuery(...) on XmlObject and XmlCursor working?
For the 1.0.4 release, there is no open source XQuery integration. However, the XmlBeans included in BEA's Weblogic 8.x executes xqueries using a BEA's proprietary XQuery engine.
How do I modify the generated interfaces?
Use .xsdconfig files. Learn more here - XsdConfigFile.
How do I control CDATA?
Use CDATA options. Learn more here - CdataOptions.
The cause is that the XmlObject is an orphan; i.e., it has become disassociated from the XML store. This can happen if you get a reference to an object (perhaps by fetching the first item in an array), delete the item from the tree (perhaps by calling the array remove method on element 0), and then try to invoke methods on that reference or any of its child elements. You cannot even invoke the toString() method on an orphaned object! If you need to keep a deleted object, make a copy before you delete it. For example:
Schema Object Model Questions
Is there an introduction document on the XMLBeans Schema Type System?
This document is a good starting place to learn about programming against the XMLBeans Schema Type System.
How do I get the java name for a schema type?
- Once you've compiled things and got the JAR...
- Put the JAR on your classpath
com.bea.xml.XmlBeans.getContextTypeLoader()to get the SchemaTypeLoader corresponding to your thread's context classloader.
- you can then use
- and then
- see this post: http://nagoya.apache.org/eyebrowse/ReadMsg?listNameemail@example.com&msgNo=7 @fixme: seems to be a dead link
How do I get to SchemaAnnotation and SchemaIdentityConstraint on elements?
What is the difference between SchemaProperty and SchemaParticle?
In a few words, the difference is that SchemaProperty represents a "flattened", simplified view of the contents of a type, while SchemaParticle represents a "complete" view including all of the model groups, as defined in Schema. To exemplify, consider the following Schema:
As you can see, this content mandates an <a> element in the instance, followed by either one or more <a>s or one or more <b>s (a (a+|b+)). The majority of applications would only be interested in what are the names and types of elements allowed inside the content for type "T" and would not care whether there are nested sequeces/choices and the like. As such, they can use
SchemaType.getProperties() and they will see two entries, one for element "a" (built by collapsing the two occurences of an "a" element in the Schema) and one for element "b".
However, in some cases, more detail is needed about the content of the element. One example would be a Schema validator which needs to know if <a> and <b> are contained by a <choice> or a <sequence>. Another example would be code that is looking for annotations present in the Schema. As it can be seen in this example, there is an annotation on the second occurence of the "a" element, but not the first. Because the SchemaProperty API would collapse the two, it is not suitable for being used in this situation and SchemParticle has to be used instead to isolate each occurence of an "a" element.
This example code illustrate how to get the SchemaProperty'ies and SchemaParticle's on a type:
With helper methods
this is the result of running this code:
As you can see, using the SchemaParticle API we get two occurences for the "a" element and an annotation showing up only on the second of these occurences.
How do I use substitution groups?
See the Substitution Groups FAQ: SubstGroupsFaq
How do I compile multiple schema files with dependencies?
Schema files need to be compiled with its compiled dependencies on the classpath. For example, if s4.xsd and s3.xsd depends on s2.xsd which depends on s1.xsd, compile using the following:
Is there documentation on navigating with XmlCursor?
This document, http://xmlbeans.apache.org/docs/2.0.0/guide/conNavigatingXMLwithCursors.html, discusses using XmlCursor to navigate a document.
How do I use Bookmarks to annotate XML?
This document, http://xmlbeans.apache.org/docs/2.0.0/guide/conUsingBookmarksToAnnotateXML.html, discusses using bookmarks to annotate xml.