Apache XMLBeans
≈ 3 min read
Names in other languages
No names in other languages are held for this entry yet.
Article bodies are English and are not machine-translated. A name in another language is not a translation of the article.
XMLBeans is a Java-to-XML binding framework which is part of the Apache Software Foundation XML project.
XMLBeans is a Java-to-XML binding framework which is part of the Apache Software Foundation XML project. ==Description== 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. ===Characteristics of XMLBeans=== Large XML Schema support. Large XML Infoset support. 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. ===Objective=== 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: use XMLBeans for all of the schemas they encounter. access the XML at whatever level is necessary without other tools. ISO 3166 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. import org.openuri.domain.country.v1.Country; import org.openuri.domain.country.v1.Iso; public class CountrySample { public static void main(String[] args) { Country country = Country.Factory.newInstance(); country.setName("Denmark"); country.setPopulation(5450661); // from Wikipedia :-) // print out country XMLBean as XML System.out.println(country.xmlText()); // check if document is valid - will print "Document is invalid" // because required Iso child element in not in the object System.out.println ("Document is " + (country.validate() ? "valid" : "invalid")); // add child with complex type Iso to make the document valid Iso iso = country.addNewIso(); iso.setAlpha2("DK"); iso.setAlpha3("DNK"); iso.setCountryCode(208); // print out country XMLBean as XML System.out.println(country.xmlText()); // check if document is valid - will print "Document is valid" System.out.println ("Document is " + (country.validate() ? "valid" : "invalid")); } } ==References==
Text derived from https://en.wikipedia.org/w/index.php?oldid=1356814548 under CC BY-SA 4.0; modifications have been made.