Developer(s) | Apache Software Foundation |
---|---|
Stable release | 5.1.1 / August 29, 2022 |
Written in | Java |
Operating system | Cross-platform |
Type | XML binding |
License | Apache License 2.0 |
Website | xmlbeans |
XMLBeans is a Java-to-XML binding framework which is part of the Apache Software Foundation XML project.
XMLBeans is a tool that allows access to the full power of XML in a Java friendly way. The idea is to take advantage of the richness and features of XML and XML Schema and have these features mapped as naturally as possible to the equivalent Java language and typing constructs. XMLBeans uses XML Schema to compile Java interfaces and classes that can then be used to access and modify XML instance data. Using XMLBeans is similar to using any other Java interface/class: with methods like getFoo or setFoo, just as when working with Java. While a major use of XMLBeans is to access XML instance data with strongly typed Java classes there are also APIs that allow access to the full XML infoset (XMLBeans keeps XML Infoset fidelity) as well as to allow reflection into the XML schema itself through an XML Schema Object model.
Large XML Schema support: XMLBeans fully supports XML Schema and the corresponding java classes provide constructs for all of the major functionality of XML Schema. This is critical since often one has no control over the features of XML Schema needed to work with in Java. Also, XML Schema oriented applications can take full advantage of the power of XML Schema and not have to restrict themselves to a subset.
Large XML Infoset support: When unmarshalling an XML instance the full XML infoset is kept and is available to the developer. This is critical because that subset of XML is not easily represented in Java. For example, order of the elements or comments might be needed in a particular application.
A major objective of XMLBeans has been its applicability in all non-streaming (in memory) XML programming situations. The developer should be able to compile their XML Schema into a set of Java classes and know that they will be able to:
To accomplish the above objectives, XMLBeans provides three major APIs:
XmlObject: The java classes that are generated from an XML Schema are all derived from XmlObject. These provide strongly typed getters and setters for each of the elements within the defined XML. Complex types are in turn XmlObjects. For example, getCustomer might return a CustomerType (which is an XmlObject). Simple types turn into simple getters and setters with the correct java type. For example, getName might return a String.
XmlCursor: From any XmlObject the developer can get an XmlCursor. This provides efficient, low level access to the XML Infoset. A cursor represents a position in the XML instance. The cursor can be moved around the XML instance at any level of granularity needed from individual characters to Tokens.
SchemaType: XMLBeans provides a full XML Schema object model that can be used to reflect on the underlying schema meta information. For example, the developer might generate a sample XML instance for an XML schema or perhaps find the enumerations for an element so that they may be displayed.
An example of a simple XML Schema Definition to describe a country is given below.
<?xml version="1.0" encoding="UTF-8"?><xs:schematargetNamespace="http://www.openuri.org/domain/country/v1"xmlns:tns="http://www.openuri.org/domain/country/v1"xmlns:xs="http://www.w3.org/2001/XMLSchema"elementFormDefault="qualified"attributeFormDefault="unqualified"version="1.0"><xs:elementname="Country"type="tns:Country"/><xs:complexTypename="Country"><xs:sequence><xs:elementname="Name"type="xs:string"/><xs:elementname="Population"type="xs:int"/><xs:elementname="Iso"type="tns:Iso"/></xs:sequence></xs:complexType><xs:complexTypename="Iso"><xs:annotation><xs:documentation>ISO3166</xs:documentation></xs:annotation><xs:sequence><xs:elementname="Alpha2"type="tns:IsoAlpha2"/><xs:elementname="Alpha3"type="tns:IsoAlpha3"/><xs:elementname="CountryCode"type="tns:IsoCountryCode"/></xs:sequence></xs:complexType><xs:simpleTypename="IsoCountryCode"><xs:restrictionbase="xs:int"><xs:totalDigitsvalue="3"/></xs:restriction></xs:simpleType><xs:simpleTypename="IsoAlpha2"><xs:restrictionbase="xs:string"><xs:patternvalue="[A-Z]{2}"/><xs:whiteSpacevalue="collapse"/></xs:restriction></xs:simpleType><xs:simpleTypename="IsoAlpha3"><xs:restrictionbase="xs:string"><xs:patternvalue="[A-Z]{3}"/><xs:whiteSpacevalue="collapse"/></xs:restriction></xs:simpleType></xs:schema>
When the schema is compiled into XMLBean classes (e.g., using Ant), it is very easy to create and manipulate XML data that conforms to the schema definition. The following Java code is a simple example that illustrates how an XML document can be created and validated.
importorg.openuri.domain.country.v1.Country;importorg.openuri.domain.country.v1.Iso;publicclassCountrySample{publicstaticvoidmain(String[]args){Countrycountry=Country.Factory.newInstance();country.setName("Denmark");country.setPopulation(5450661);// from Wikipedia :-)// print out country XMLBean as XMLSystem.out.println(country.xmlText());// check if document is valid - will print "Document is invalid"// because required Iso child element in not in the objectSystem.out.println("Document is "+(country.validate()?"valid":"invalid"));// add child with complex type Iso to make the document validIsoiso=country.addNewIso();iso.setAlpha2("DK");iso.setAlpha3("DNK");iso.setCountryCode(208);// print out country XMLBean as XMLSystem.out.println(country.xmlText());// check if document is valid - will print "Document is valid"System.out.println("Document is "+(country.validate()?"valid":"invalid"));}}
David Bau was the chief designer for the XMLBeans 1.0 project while he was working for BEA. XMLBeans started on the grounds of XMLMaps, an XML binding tool included in previous BEA WebLogic products. XMLBeans was originally developed as part of the proprietary BEA WebLogic Workshop Framework, but it was obvious from interviews conducted when it was first announced on January 27, 2003, that BEA wanted it to become an open standard. At that time it was not decided which organization BEA wanted to involve in the standardization effort. Later that year it was donated to the Apache Software Foundation. The original team included Cezar Cristian Andrei and Eric Vasilik, later the team added Cliff Schmidt and Radu Preotiuc-Pietro, Jacob Danner, Kevin Krouse and Wing Yew Poon. XMLBeans is now being developed by Apache POI.
A document type definition (DTD) is a specification file that contains set of markup declarations that define a document type for an SGML-family markup language. The DTD specification file can be used to validate documents.
The Standard Generalized Markup Language is a standard for defining generalized markup languages for documents. ISO 8879 Annex A.1 states that generalized markup is "based on two postulates":
Extensible Markup Language (XML) is a markup language and file format for storing, transmitting, and reconstructing arbitrary data. It defines a set of rules for encoding documents in a format that is both human-readable and machine-readable. The World Wide Web Consortium's XML 1.0 Specification of 1998 and several other related specifications—all of them free open standards—define XML.
XSD, a recommendation of the World Wide Web Consortium (W3C), specifies how to formally describe the elements in an Extensible Markup Language (XML) document. It can be used by programmers to verify each piece of item content in a document, to assure it adheres to the description of the element it is placed in.
The Geography Markup Language (GML) is the XML grammar defined by the Open Geospatial Consortium (OGC) to express geographical features. GML serves as a modeling language for geographic systems as well as an open interchange format for geographic transactions on the Internet. Key to GML's utility is its ability to integrate all forms of geographic information, including not only conventional "vector" or discrete objects, but coverages and sensor data.
In computing, RELAX NG is a schema language for XML—a RELAX NG schema specifies a pattern for the structure and content of an XML document. A RELAX NG schema is itself an XML document but RELAX NG also offers a popular compact, non-XML syntax. Compared to other XML schema languages RELAX NG is considered relatively simple.
Jakarta XML Binding is a software framework that allows Java EE developers to map Java classes to XML representations. JAXB provides two main features: the ability to marshal Java objects into XML and the inverse, i.e. to unmarshal XML back into Java objects. In other words, JAXB allows storing and retrieving data in memory in any XML format, without the need to implement a specific set of XML loading and saving routines for the program's class structure. It is similar to xsd.exe
and XmlSerializer
in the .NET Framework.
An XML schema is a description of a type of XML document, typically expressed in terms of constraints on the structure and content of documents of that type, above and beyond the basic syntactical constraints imposed by XML itself. These constraints are generally expressed using some combination of grammatical rules governing the order of elements, Boolean predicates that the content must satisfy, data types governing the content of elements and attributes, and more specialized rules such as uniqueness and referential integrity constraints.
JSON is an open standard file format and data interchange format that uses human-readable text to store and transmit data objects consisting of attribute–value pairs and arrays. It is a common data format with diverse uses in electronic data interchange, including that of web applications with servers.
Fast Infoset is an international standard that specifies a binary encoding format for the XML Information Set as an alternative to the XML document format. It aims to provide more efficient serialization than the text-based XML format.
XML Information Set is a W3C specification describing an abstract data model of an XML document in terms of a set of information items. The definitions in the XML Information Set specification are meant to be used in other specifications that need to refer to the information in a well-formed XML document.
Streaming API for XML (StAX) is an application programming interface (API) to read and write XML documents, originating from the Java programming language community.
Catalogue Service for the Web (CSW), sometimes seen as Catalogue Service - Web, is a standard for exposing a catalogue of geospatial records in XML on the Internet. The catalogue is made up of records that describe geospatial data, geospatial services, and related resources.
The Web Application Description Language (WADL) is a machine-readable XML description of HTTP-based web services. WADL models the resources provided by a service and the relationships between them. WADL is intended to simplify the reuse of web services that are based on the existing HTTP architecture of the Web. It is platform and language independent and aims to promote reuse of applications beyond the basic use in a web browser. WADL was submitted to the World Wide Web Consortium by Sun Microsystems on 31 August 2009, but the consortium has no current plans to standardize it. WADL is the REST equivalent of SOAP's Web Services Description Language (WSDL), which can also be used to describe REST web services.
xmlbeansxx is a software framework for C++ to XML binding. It is open-source software licensed under Apache License 2.0.
The Web Services Description Language is an XML-based interface description language that is used for describing the functionality offered by a web service. The acronym is also used for any specific WSDL description of a web service, which provides a machine-readable description of how the service can be called, what parameters it expects, and what data structures it returns. Therefore, its purpose is roughly similar to that of a type signature in a programming language.
Data Format Description Language, published as an Open Grid Forum Recommendation in February 2021, is a modeling language for describing general text and binary data in a standard way. A DFDL model or schema allows any text or binary data to be read from its native format and to be presented as an instance of an information set.. The same DFDL schema also allows data to be taken from an instance of an information set and written out to its native format.
XQuery API for Java (XQJ) refers to the common Java API for the W3C XQuery 1.0 specification.
Fuzzy Markup Language (FML) is a specific purpose markup language based on XML, used for describing the structure and behavior of a fuzzy system independently of the hardware architecture devoted to host and run it.
Castor is a data binding framework for Java with some features like Java to Java-to-XML binding, Java-to-SQL persistence, paths between Java objects, XML documents, relational tables, etc. Castor is one of the oldest data binding projects.