XMLBeans  <ul><li>- Accessing XML by binding it to Java types. </li></ul>
XMLBeans <ul><li>Introduction </li></ul><ul><li>XMLBeans Architecture </li></ul><ul><li>Compiling XML Schema </li></ul><ul...
Introduction to XMLBeans <ul><li>Utilizes the  full  power of XML in Java </li></ul><ul><li>Maps the features of XML Schem...
Advantages of XMLBeans <ul><li>Full XML Schema Support </li></ul><ul><li>Full XML Infoset Access </li></ul><ul><li>Open te...
Important APIs of XMLBeans <ul><li>XmlObject </li></ul><ul><ul><li>Super-most type of the generated interfaces/ classes </...
XMLBeans Architecture XML Schema Schema  compilation extends XML Schema Binaries Generated classes Application XmlBeans ja...
XMLBeans Architecture (contd.) XML  Doc XML Store Validation Parse & Load Reads/ Updates SchemaType XMLObject XML API XMLC...
Schema Compilation XML Schema  Schema Validation Schema Object Model Generated  Interfaces/Classes Schema Binaries (.xsb) ...
XMLBeans Generated Classes <ul><li>Schema’s targetNamespace becomes package name </li></ul><ul><li>Global elements and typ...
XML To Java Conversions <ul><li>A Document Interface represents the XML </li></ul><ul><li>Use its Factory to parse the XML...
Java To XML Conversions <ul><li>Create a new instance of the Document using its Factory. </li></ul><ul><li>From the Docume...
XML Cursor <ul><li>A different way to work with XML </li></ul><ul><ul><li>A location in an XML Instance not a Node </li></...
XML Tokens <ul><li>STARTDOC </li></ul><ul><li>ENDDOC </li></ul><ul><li>START </li></ul><ul><li>END </li></ul><ul><li>TEXT ...
Uses of XmlCursor <ul><li>XmlToken’s newCursor() gives an XmlCursor </li></ul><ul><li>Navigation </li></ul><ul><ul><li>Man...
Uses of XmlCursor (contd.) <ul><li>To add new elements </li></ul><ul><ul><li>Use toNextToken() to go past the STARTDOC tok...
XMLBeans Tools  <ul><li>inst2xsd (Instance to Schema Tool)   </li></ul><ul><ul><li>Generates XML schema from XML instance ...
Competing Technologies <ul><li>JAXB </li></ul><ul><li>Betwixt </li></ul><ul><li>Castor </li></ul><ul><li>Zeus </li></ul><u...
Resources <ul><li>http://dev2dev.bea.com/pub/a/2004/05/ryan_xml.html  By  Scott Ryan </li></ul><ul><li>http://xmlbeans.apa...
Sample Code
Questions
Upcoming SlideShare
Loading in …5
×

DOSUG XML Beans overview by Om Sivanesian

3,134 views

Published on

A quick introduction to XML Beans at the Denver Open Source Users Group by Om Sivanesian

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
3,134
On SlideShare
0
From Embeds
0
Number of Embeds
31
Actions
Shares
0
Downloads
43
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

DOSUG XML Beans overview by Om Sivanesian

  1. 1. XMLBeans <ul><li>- Accessing XML by binding it to Java types. </li></ul>
  2. 2. XMLBeans <ul><li>Introduction </li></ul><ul><li>XMLBeans Architecture </li></ul><ul><li>Compiling XML Schema </li></ul><ul><li>Conversions & Validation </li></ul><ul><li>XmlCursor </li></ul><ul><li>Competing Technologies </li></ul><ul><li>Sample Code </li></ul><ul><li>Questions </li></ul>
  3. 3. Introduction to XMLBeans <ul><li>Utilizes the full power of XML in Java </li></ul><ul><li>Maps the features of XML Schema to Java Types. </li></ul><ul><li>Underlying XML Store allows full access to the entire XML infoset when needed </li></ul><ul><li>Generated Java Classes allow Java-friendly access to XML </li></ul><ul><li>David Bau started it in BEA and was donated to Apache. </li></ul>
  4. 4. Advantages of XMLBeans <ul><li>Full XML Schema Support </li></ul><ul><li>Full XML Infoset Access </li></ul><ul><li>Open technology </li></ul><ul><li>Enterprise Standard XML Technology </li></ul><ul><li>Make XML Schema easy to use </li></ul>
  5. 5. Important APIs of XMLBeans <ul><li>XmlObject </li></ul><ul><ul><li>Super-most type of the generated interfaces/ classes </li></ul></ul><ul><li>XmlCursor </li></ul><ul><ul><li>Represents a postion in the XML & provides low-level access to the XML Infoset </li></ul></ul><ul><li>SchemaType </li></ul><ul><ul><li>Provides a full Schema Object Model </li></ul></ul>
  6. 6. XMLBeans Architecture XML Schema Schema compilation extends XML Schema Binaries Generated classes Application XmlBeans jar SchemaType XMLObject XML API XMLCursor
  7. 7. XMLBeans Architecture (contd.) XML Doc XML Store Validation Parse & Load Reads/ Updates SchemaType XMLObject XML API XMLCursor
  8. 8. Schema Compilation XML Schema Schema Validation Schema Object Model Generated Interfaces/Classes Schema Binaries (.xsb) Compiled Interfaces/Classes XML Types jar Built-in Schema Types
  9. 9. XMLBeans Generated Classes <ul><li>Schema’s targetNamespace becomes package name </li></ul><ul><li>Global elements and types become top-level classes </li></ul><ul><li>Anonymous types become inner classes </li></ul><ul><li>Local elements and attributes become properties </li></ul><ul><li>Simple type properties have both Java and XML set/get </li></ul>
  10. 10. XML To Java Conversions <ul><li>A Document Interface represents the XML </li></ul><ul><li>Use its Factory to parse the XML </li></ul><ul><li>From the Document Object get the root object. </li></ul><ul><li>Access other information using the getters. </li></ul><ul><li>Use the validate() method of the Document Object to check for validity. </li></ul>
  11. 11. Java To XML Conversions <ul><li>Create a new instance of the Document using its Factory. </li></ul><ul><li>From the Document create the Root Object. </li></ul><ul><li>Assign values and other objects to it. </li></ul><ul><li>The toString() method of the Document gives the XML. </li></ul><ul><li>Use the validate() method of the Document Object to check for validity. </li></ul>
  12. 12. XML Cursor <ul><li>A different way to work with XML </li></ul><ul><ul><li>A location in an XML Instance not a Node </li></ul></ul><ul><ul><li>Lighter weight than Node based model </li></ul></ul><ul><ul><ul><li>Fewer Objects = Less Memory, Less Garbage Collection </li></ul></ul></ul><ul><li>Access to full XML Infoset (comments, PIs, whitespace) </li></ul><ul><li>Similar to moving a cursor through a text document </li></ul><ul><ul><li><Basket> </li></ul></ul><ul><ul><li><Item> </li></ul></ul><ul><ul><li><Category>First</Category> </li></ul></ul><ul><ul><li></Item> </li></ul></ul><ul><ul><li></Basket> </li></ul></ul><ul><li>XmlCursor’s programming model is token based. </li></ul>
  13. 13. XML Tokens <ul><li>STARTDOC </li></ul><ul><li>ENDDOC </li></ul><ul><li>START </li></ul><ul><li>END </li></ul><ul><li>TEXT </li></ul><ul><li>ATTR </li></ul><ul><li>NAMESPACE </li></ul><ul><li>COMMENT </li></ul><ul><li>PROCINST </li></ul>
  14. 14. Uses of XmlCursor <ul><li>XmlToken’s newCursor() gives an XmlCursor </li></ul><ul><li>Navigation </li></ul><ul><ul><li>Many methods are provided to navigate. </li></ul></ul><ul><ul><ul><li>e.g: </li></ul></ul></ul><ul><ul><ul><li>aCursor.toParent(); </li></ul></ul></ul><ul><ul><ul><li>aCursor.toFirstChild(); </li></ul></ul></ul><ul><ul><ul><li>aCursor.toNextChar(); </li></ul></ul></ul><ul><ul><ul><li>aCursor.toNextAttribute(); </li></ul></ul></ul><ul><ul><ul><li>aCursor.toNextSibling(); </li></ul></ul></ul>
  15. 15. Uses of XmlCursor (contd.) <ul><li>To add new elements </li></ul><ul><ul><li>Use toNextToken() to go past the STARTDOC token. </li></ul></ul><ul><ul><li>Use beginElement(elementName, namespace) to create a new element. </li></ul></ul><ul><ul><li>Use insertChars(“value”) to create a text value. </li></ul></ul><ul><li>Using XPath to obtain data. </li></ul><ul><ul><li>selectPath(aXPath) method returns selections. </li></ul></ul><ul><ul><li>Use toNextSelection() to iterate through the selections. </li></ul></ul>
  16. 16. XMLBeans Tools <ul><li>inst2xsd (Instance to Schema Tool) </li></ul><ul><ul><li>Generates XML schema from XML instance files. </li></ul></ul><ul><li>scomp (Schema Compiler) </li></ul><ul><ul><li>Compiles a schema into XMLBeans classes and metadata. </li></ul></ul><ul><li>scopy (Schema Copier) </li></ul><ul><ul><li>Copies the XML schema at the specified URL to the specified file. </li></ul></ul><ul><li>sdownload (Schema Downloader) </li></ul><ul><ul><li>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. </li></ul></ul><ul><li>sfactor (Schema Factoring Tool) </li></ul><ul><ul><li>Factors redundant definitions out of a set of schemas and uses imports instead. </li></ul></ul><ul><li>svalidate (Streaming Instance Validator ) </li></ul><ul><ul><li>Validates a schema definition and instances within the schema. </li></ul></ul><ul><li>validate (Instance Validator ) </li></ul><ul><ul><li>Validates an instance against a schema. </li></ul></ul><ul><li>xmlbean Ant task </li></ul><ul><ul><li>Compiles a set of XSD and/or WSDL files into XMLBeans types. </li></ul></ul>
  17. 17. Competing Technologies <ul><li>JAXB </li></ul><ul><li>Betwixt </li></ul><ul><li>Castor </li></ul><ul><li>Zeus </li></ul><ul><li>JaxME </li></ul>
  18. 18. Resources <ul><li>http://dev2dev.bea.com/pub/a/2004/05/ryan_xml.html By Scott Ryan </li></ul><ul><li>http://xmlbeans.apache.org/ Documentation & Resources </li></ul>
  19. 19. Sample Code
  20. 20. Questions

×