Innovations and Standards for XML Processing in Java XML Beans and XQuery Deb Ayers Principal

Preview:

Citation preview

Innovations and Standards for XML Processing in Java

XML Beans and XQuery

Deb AyersPrincipal

• • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • •

First ... A Quote...

• • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • •

Fall 2000....XML in Server-side Architecture

• External Interface– Request/Response XML

• Service brokering– Select service

• Content brokering– Broker content by

service

• Business Layer – Business Components

• Enterprise Java Beans• JDO

• Data Layer

ServiceContentBroker

Data Layer

XML Content

XML ServiceWeb Services

orXML over HTTP

ServiceBroker

Business Component Layer

• • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • •

Server-side XML Patterns

Retail client

Retail ClientIGR Accounting

Retail DB

Transaction Progress

Exporting OrderStatus toWeddingNetwork..

The Internet

Retail Partners

Securely synchronize Orders, ProductCatalogs, and Registry with IGR WeddingNetwork

Open, standardized interface for integrationinto existing business processes.

Gateway provides components to handleproprietary and ShopML (IGR standardXML)

WeddingNetwork IREG Enterprise server-side Java component

technology. Business logic written to standard

ShopML Servlets manage HTML interface.

www.weddingnetwork.com

Wedding NetworkWebsite!

Retail DB

The Internet

Web ApplicationServer

Products

OrdersRegistry

I nternet Retailer Enterprise Gateway

ShopMLservicehandler

Business Logic (EJB)

Order Retailer

Product Registry

Java App Server

Retail Client

ShopMLRequest

ShopMLResponse

ShopMLFilter

RMI

Recieve OrderReceive Registry

OrderRegistry

Gateway ServiceInterface

Order Status

Receive Orders

Product Catalog

Sync Registry

Corba / IIOP

Servlet

Servlet

BusinessLogic

ClientData

Copyright © 2000 All rights reserved. Deb Ayers and Tom Marrs

•XML Bridge•Service Broker

•Content Broker•XML Parser Factory

• • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • •

Content Broker: Architecture Pattern

Content Broker

• • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • •

Content Broker (cont’d)

+addToContent(in tagName : String, in fieldValues : BaseDictionary)+getProperties() : Enumeration

«interface»IShopMLContentHandler

+getContent() : Element

«interface»IContent

OrderShopMLContentHandler QueryShopMLContentHandler

QueryOrderShopMLContentHandler

«uses» «uses»

+makeShopMLContentHandler(in serviceType : String) : IShopMLContentHandler-contentHandlersTable : Hashtable

ShopMLContentHandlerFactory

1

+creates*«utility»

Hashtable

1

1

• • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • •

Fast Forward....XML Processing 2003

• • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • •

What is XML Beans

• Java/XML Binding– Use XML Schema to get

Java Classes/Interfaces– Simple Getter/Setter “java

bean-like” model

• Direct XML level access• Schema/type reflection

and validation

Three major APIs1. XmlObject2. XmlCursor3. Schema Type System

A simple, comprehensive, fast tool for accessing XML from Java.

• • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • •

XML Beans and BEA

• BEA Donated to Open Source in July 2003– xmlbeans-user@xml.apache.org

• Independent of other BEA Technologies– Download stand-alone XML Dev Kit

http://dev2dev.bea.com/technologies/xmlbeans/overview.jsp

– Can use within any Java application

• Used by Bea’s Weblogic 8.1 Platform products– Needed strong Java/Xml development tool– Had good xml -> java development experience

• • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • •

What Are the Alternatives ?

• DOM (Document Object Model) or JDOM– Tedious to program

– Typically need to wrapper with Java Classes to Hide Complexity

• SAX (Simple API for XML)– Simple to program with a loss of control – rigid

• Castor– Requires marshalling/unmarshalling

– Lose access to original XML document

• JAXB– Very similar to XMLBeans and will evolve to be inclusive

– David Bau the chief architect of XmlBeans is a committer on Apache XmlBeans will be on the JAXB 2.0 Expert group (JSR 222)

• • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • •

XMLBeans API Approach

XML APIs“100% XML”

DOM, SAX, Xerces,XPath…:

Robust but Clumsy

XML Translators“Typed APIs”

MindElectric, Breeze,MS .NET, JAXB:

Easy but Fragile

XMLBeansBoth

Typed Java PLUS100% XML and Schema

Easy and Robust

• • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • •

XML Beans Goals

• Ease of use• Target 100% support for XML Schema• High Performance• Non-lossy approach: NO underlying XML lost• Ability to work at different levels:

– Java bound– Xml cursor– Validation/Schema level

• • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • •

100% Schema support

• Namespaces• All types • Inheritance (by restriction, by list, by union, by

extension)• All content models• Includes/imports• Key/KeyRef

• • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • •

XMLBeans Data Model

Complete XML Token Stream

Convenient Typed JavaBean Tree

High speed parser High speed saver

Lightweight cursor access Streamed XQuery

Full XML infoset

Strongly typed methods Class casts, Inheritance

Natural Java types Validation

Syn

chro

nize

dCursor Access

Object Access

Typed Java data

Using XML Beans

• • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • •

XmlTypes.jar

Compiling Schema

XML Schema(s)Imported/IncludedXML Schema(s)

XML BeansSchema

Compiler

Java Interfaces

Java Classes

XML SchemaBinary Files (.xsb)

(Put on classpath to access

generated classes)

(Schemas are loaded as XML Beans using

schema for schema)

Simple Demo

• • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • •

Schema to Interface/Class generation

• Namespace to Package Name– General JAXB type naming rules– Can override using .xsdconfig file

• Schema Names to Java Names– General JAXB type naming rules– Can override using .xsdconfig file

• Named Types– become standalone interfaces/classes

• Global Elements – Synthesized type at the top level: e.g., FooDocument

• Local Elements (Complex) – Inner classes of their parent

• • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • •

Schema to Interface/Class generation (Example)<xs:schema targetNamespace="http://openuri.org/easypo" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:po="http://openuri.org/easypo" elementFormDefault="qualified"> <xs:element name="purchase-order"> <xs:complexType> <xs:sequence> <xs:element name="customer" type="po:customer"/> <xs:element name="date" type="xs:dateTime" /> <xs:element name="line-item" type="po:line-item" minOccurs="0" maxOccurs="unbounded"/> <xs:element name="shipper" type="po:shipper" minOccurs="0"/> </xs:sequence> </xs:complexType> </xs:element> <xs:complexType name="customer"> <xs:sequence> <xs:element name="name" type="xs:string"/> <xs:element name="address" type="xs:string"/> </xs:sequence> </xs:complexType> <xs:complexType name="line-item"> <xs:sequence> <xs:element name="description" type="xs:string"/> <xs:element name="per-unit-ounces" type="xs:decimal"/> <xs:element name="price" type="xs:double"/> <xs:element name="quantity" type="xs:int"/> </xs:sequence> </xs:complexType> <xs:complexType name="shipper"> <xs:sequence> <xs:element name="name" type="xs:string"/> <xs:element name="per-ounce-rate" type="xs:decimal"/> </xs:sequence></xs:complexType></xs:schema>

target namespace -> java package: openuri.org.easypo

global element:PurchaseOrderDocument class

PurchaseOrderDocument.PurchaseOrder inner class

named type:Customer classLineItem classShipper class

• • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • •

XML Beans Interfaces

• All descend from XmlObject• getters and setters similar to java beans• Two ways to construct both using Factory:

1. FooDocument doc = FooDocument.Factory.newInstance()

2. FooDocument doc = FooDocument.Factory.parse()

• • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • •

Creating an XML Bean from an existing source (Factory.parse)

PurchaseOrderDocument doc = PurchaseOrderDocument.Factory.parse()

• File• InputStream• Node• Reader• String• URL• XMLInputStream

PurchaseOrderDocument doc = PurchaseOrderDocument.Factory.parse(…));PurchaseOrderDocument.PurchaseOrder po = doc.getPurchaseOrder();Customer c = po.getCustomer();String custName = c.getName();

• • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • •

Parsing an XML DocumentBehind the scenes

XmlTokenSource

Picollo

<purchase-order xmlns="http://openuri.org/easypo">

<customer>

<name>Gladys Kravitz</name>

<address>Anytown, PA</address>

</customer>

<date>2001-12-17T09:30:47-05:00</date>

<shipper>

<name>UPS</name>

<per-ounce-rate>0.74</per-ounce-rate>

</shipper>

</purchase-order>

XML

<purchase-order xmlns=“…”>\n

Char B

uffer

XmlStore

XmlLoader

PurchaseOrderDocument.Factory.parse()

<customer>\n

<name>

splay tree<address>

<date>\n

XmlObject

<shipper>\n<name>

<per-ounce-rate>

XmlObject PurchaseOrderDocument

1. Consolidate QNames

2. Build XmlStore

3. Create Root XmlObject

• • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • •

Creating an XML Bean From Scratch (Factory.newInstance())

Use Factory.newInstance() to create new empty XML Bean

PurchaseOrderDocument doc = PurchaseOrderDocument.Factory.newInstance();

Use .addNewXXX to add a new complex types

• Local element inner class, named type standalone class

PurchaseOrderDocument.PurchaseOrder po = doc.addNewPurchaseOrder();

Customer c = po.addNewCustomer();

Simple types/content have direct setters

c.setAddress("123 Main St");

c.setName("Dave Remy");

Demo

• • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • •

Reading an XML Bean

Use Factory.parse() to get Document and then read using typical java techniques:

getter for complex types

(objects)

getter for simple types

getter for repeating element

(array)

File f = new File("c:\text.xml");

PurchaseOrderDocument doc = PurchaseOrderDocument.Factory.parse(f);

PurchaseOrderDocument.PurchaseOrder po = doc.getPurchaseOrder();

Customer c = po.getCustomer();

String address = c.getAddress();

String name = c.getName();

LineItem[] liArray = po.getLineItemArray();

for (int i = 0; i < liArray.length; i++) {

....

}

• • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • •

Reading an XML BeanBehind the scenes

Customer c = myPurchaseOrder.getCustomer();Lazy instantiation:

Complex Type: (Customer)

1. If Object already in store return it2. Otherwise create object and

retrieve info from XML Store

Simple Type: (Name)

1. get from the parent object (Customer) directly

Object Store XML Store

String name = c.getName();

Customer-name

-address

…<customer> <name> Fred </name> <address> 123 main </address></customer> …

Customer-name

-address

• • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • •

Updating/Setting Xml Beans

setter for simple types

setter for complex type

PurchaseOrderDocument doc = PurchaseOrderDocument.Factory.newInstance();

PurchaseOrderDocument.PurchaseOrder po = doc.addNewPurchaseOrder();

Customer c = po.addNewCustomer();

c.setName(“Dave Remy”);

Address mailingAddress = c.addNewAddress();

mailingAddress.setType = “mailing”;

mailingAddress.setStreet1 = “123 Main St”;

mailingAddress.setCity = “Kirkland”;

mailingAddress.setState = “WA”;

mailingAddress.setPostal = “98040”;

Address billingAddress = c.addNewAddress();

billingAddress.set(mailingAddress);

billingAddress.setType = “billing”;

• • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • •

Updating XML BeansBehind the scenes

setCustomer(myCustomer);

c.setName(“Dave”);

Object Store

Customer-name

-address

XML Store

…<customer> <name> Fred </name> <address> 123 main </address></customer> …

*invalid*

xmlCursor.selectPath(“.//customer”);

refresh

Updates to XML Store work similarly - “invalid bits” used

to synchronize

• • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • •

Validating a Document

Just call validate() on XmlObject …

document.validate();

To capture list of errors pass in collection as an option:

ArrayList errors = new ArrayList();validateOptions.put(XmlOptions.ERROR_LISTENER, errors);boolean isValid = doc.validate(validateOptions);if (!isValid) { Iterator i = errors.iterator(); while (i.hasNext()) { System.out.println("Validation Error: " +

i.next().toString()); }}

• • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • •

Reality Check

Using XML Cursor

• • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • •

XML Cursor

• DOM like access technique• Token oriented• High speed (Uses the Xml Store)• Can get to any part of the XML document (NO Loss)• Untyped• Cursor concept – represents a location in the document

<Foo>

<Bar>some Text</Bar>

</Foo>Cursor at

<Bar> element

• • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • •

Reading an Xml Documentwith XML Cursor

public String discoverTokenTypes(XmlObject xmlDoc) throws Exception

{

XmlCursor documentCursor = xmlDoc.newCursor();

while (documentCursor.hasNextToken()) {

...

documentCursor.toNextToken();

}

documentCursor.dispose();

}

use .newCursor to create cursor

token model

A new Cursor can be created on ANY XmlObject (using xmlObject.newCursor()) – mix Xml Cursor with strongly typed Xml

Objects

• • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • •

Types of Tokens

• Document Start• Document END• Element Start• Element End• Text• Attribute• Comment• Namespace• Processing Instructions

• • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • •

Navigating in Xml Cursor

• hasNextToken(); toNextToken()• toChild(QName)• toFirstChild()• toFirstAttribute()• toNextChild()• toNextSibling()• Etc., etc., etc.

• • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • •

Schema Type System

• You can fully introspect on the schema type system

PurchaseOrderDocument.schemaType();

Possible uses:• Generate Sample XML• Show constraints for a particular field

– Enumerations

– Facets

– Etc

• Other tool type uses …

• • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • •

Whence cometh XQuery

• XQuery is derived from an XML query language called Quilt

• Quilt borrowed features from:– Xpath 1.0– XQL– XML-QL– SQL– OQL

• • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • •

What is XQuery. . .

• XQuery is a query language designed to query XML documents in a simple and concise manner.

• XQuery contains, as a subset, XPath 2.0. A valid XPath query and a valid XQuery query will return the same result.

• • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • •

. . . What is XQuery

• The basic building block of XQuery is an expression.– This is similar to any programming language.

• XQuery is a functional language that allows nesting and iteration.

• XQuery is a strongly typed language supporting– strings, integers, floating point, and boolean.

• • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • •

Selecting Nodes

• XPath uses a virgule delimited path for specifying nodes in a Location Path.

• Specify the Context – from root node

• /

– descendants• //

• • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • •

Root Location Path<bib>

<book year="1922"><title>Ulysses</title><author><last>Joyce</last><first>James</first></author><publisher>Shakespeare and Company</publisher><price>8.24</price>

</book><book year="1925">

<title>The Great Gatsby</title><author><last>Fitzgerald</last><first>F. Scott</first></author><publisher>Scribner</publisher><price>5.25</price>

</book><book year="1978">

<title>The C Programming Language</title><author><last>Kernigan</last><first>Brian</first></author><author><last>Richie</last><first>Dennis</first></author><publisher>Prentice-Hall</publisher><price>9.95</price>

</book></bib>

<bib><book year="1922">

<title>Ulysses</title><author><last>Joyce</last><first>James</first></author><publisher>Shakespeare and Company</publisher><price>8.24</price>

</book><book year="1925">

<title>The Great Gatsby</title><author><last>Fitzgerald</last><first>F. Scott</first></author><publisher>Scribner</publisher><price>5.25</price>

</book><book year="1978">

<title>The C Programming Language</title><author><last>Kernigan</last><first>Brian</first></author><author><last>Richie</last><first>Dennis</first></author><publisher>Prentice-Hall</publisher><price>9.95</price>

</book></bib>

/

• • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • •

Descendent Context—XML Content<bib>

<book year="1922"><title>Ulysses</title><author><last>Joyce</last><first>James</first></author><publisher>Shakespeare and Company</publisher><price>8.24</price>

</book><book year="1925">

<title>The Great Gatsby</title><author><last>Fitzgerald</last><first>F. Scott</first></author><publisher>Scribner</publisher><price>5.25</price>

</book><book year="1978">

<title>The C Programming Language</title><author><last>Kernigan</last><first>Brian</first></author><author><last>Richie</last><first>Dennis</first></author><publisher>Prentice-Hall</publisher><price>9.95</price>

</book></bib>

<bib><book year="1922">

<title>Ulysses</title><author><last>Joyce</last><first>James</first></author><publisher>Shakespeare and Company</publisher><price>8.24</price>

</book><book year="1925">

<title>The Great Gatsby</title><author><last>Fitzgerald</last><first>F. Scott</first></author><publisher>Scribner</publisher><price>5.25</price>

</book><book year="1978">

<title>The C Programming Language</title><author><last>Kernigan</last><first>Brian</first></author><author><last>Richie</last><first>Dennis</first></author><publisher>Prentice-Hall</publisher><price>9.95</price>

</book></bib>

/bib

• • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • •

Selecting Elements<bib>

<book year="1922"><title>Ulysses</title><author><last>Joyce</last><first>James</first></author><publisher>Shakespeare and Company</publisher><price>8.24</price>

</book><book year="1925">

<title>The Great Gatsby</title><author><last>Fitzgerald</last><first>F. Scott</first></author><publisher>Scribner</publisher><price>5.25</price>

</book><book year="1978">

<title>The C Programming Language</title><author><last>Kernigan</last><first>Brian</first></author><author><last>Richie</last><first>Dennis</first></author><publisher>Prentice-Hall</publisher><price>9.95</price>

</book></bib>

<bib><book year="1922">

<title>Ulysses</title><author><last>Joyce</last><first>James</first></author><publisher>Shakespeare and Company</publisher><price>8.24</price>

</book><book year="1925">

<title>The Great Gatsby</title><author><last>Fitzgerald</last><first>F. Scott</first></author><publisher>Scribner</publisher><price>5.25</price>

</book><book year="1978">

<title>The C Programming Language</title><author><last>Kernigan</last><first>Brian</first></author><author><last>Richie</last><first>Dennis</first></author><publisher>Prentice-Hall</publisher><price>9.95</price>

</book></bib>

/bib/book

• • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • •

Selecting Nodes within Nodes<bib>

<book year="1922"><title>Ulysses</title><author><last>Joyce</last><first>James</first></author><publisher>Shakespeare and Company</publisher><price>8.24</price>

</book><book year="1925">

<title>The Great Gatsby</title><author><last>Fitzgerald</last><first>F. Scott</first></author><publisher>Scribner</publisher><price>5.25</price>

</book><book year="1978">

<title>The C Programming Language</title><author><last>Kernigan</last><first>Brian</first></author><author><last>Richie</last><first>Dennis</first></author><publisher>Prentice-Hall</publisher><price>9.95</price>

</book></bib>

<bib><book year="1922">

<title>Ulysses</title><author><last>Joyce</last><first>James</first></author><publisher>Shakespeare and Company</publisher><price>8.24</price>

</book><book year="1925">

<title>The Great Gatsby</title><author><last>Fitzgerald</last><first>F. Scott</first></author><publisher>Scribner</publisher><price>5.25</price>

</book><book year="1978">

<title>The C Programming Language</title><author><last>Kernigan</last><first>Brian</first></author><author><last>Richie</last><first>Dennis</first></author><publisher>Prentice-Hall</publisher><price>9.95</price>

</book></bib>

/bib/book/title

• • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • •

Using Descendent References

<bib><book year="1922">

<title>Ulysses</title><author><last>Joyce</last><first>James</first></author><publisher>Shakespeare and Company</publisher><price>8.24</price>

</book><book year="1925" city="New York">

<title>The Great Gatsby</title><author><last>Fitzgerald</last><first>F. Scott</first></author><publisher>Scribner</publisher><price>5.25</price>

</book><book year="1978">

<title>The C Programming Language</title><author><last>Kernigan</last><first>Brian</first></author><author><last>Richie</last><first>Dennis</first></author><publisher>Prentice-Hall</publisher><price>9.95</price>

</book></bib>

<bib><book year="1922">

<title>Ulysses</title><author><last>Joyce</last><first>James</first></author><publisher>Shakespeare and Company</publisher><price>8.24</price>

</book><book year="1925" city="New York">

<title>The Great Gatsby</title><author><last>Fitzgerald</last><first>F. Scott</first></author><publisher>Scribner</publisher><price>5.25</price>

</book><book year="1978">

<title>The C Programming Language</title><author><last>Kernigan</last><first>Brian</first></author><author><last>Richie</last><first>Dennis</first></author><publisher>Prentice-Hall</publisher><price>9.95</price>

</book></bib>

/bib//last

• • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • •

Obtaining Data in an Indexed Reference

<bib><book year="1922">

<title>Ulysses</title><author><last>Joyce</last><first>James</first></author><publisher>Shakespeare and Company</publisher><price>8.24</price>

</book><book year="1925">

<title>The Great Gatsby</title><author><last>Fitzgerald</last><first>F. Scott</first></author><publisher>Scribner</publisher><price>5.25</price>

</book><book year="1978">

<title>The C Programming Language</title><author><last>Kernigan</last><first>Brian</first></author><author><last>Richie</last><first>Dennis</first></author><publisher>Prentice-Hall</publisher><price>9.95</price>

</book></bib>

<bib><book year="1922">

<title>Ulysses</title><author><last>Joyce</last><first>James</first></author><publisher>Shakespeare and Company</publisher><price>8.24</price>

</book><book year="1925">

<title>The Great Gatsby</title><author><last>Fitzgerald</last><first>F. Scott</first></author><publisher>Scribner</publisher><price>5.25</price>

</book><book year="1978">

<title>The C Programming Language</title><author><last>Kernigan</last><first>Brian</first></author><author><last>Richie</last><first>Dennis</first></author><publisher>Prentice-Hall</publisher><price>9.95</price>

</book></bib>

/bib/book[title/text()=“Ulysses”]

• • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • •

A Simple XQuery Program

<CUSTOMERS> {

for $doc in document ("XM-BB-C")/db/CUSTOMER

let $customer := $doc

where $doc/STATE = "TX"

return $customer

} </CUSTOMERS>

<CUSTOMERS> {

for $doc in document ("XM-BB-C")/db/CUSTOMER

let $customer := $doc

where $doc/STATE = "TX"

return $customer

} </CUSTOMERS>

Determines # of tuples

• • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • •

Joining XML Documents

• One of the powerful features available in XQuery is the ability to do joins of XML documents.

• A join unites two XML documents based on a shared key value and outputs the desired results.

• • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • •

Last But Not Least

• • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • •

XQuery and XPath with XMLBeans

• Can run an XQuery on any XmlObject using

myXmlObject.execQuery(“<Items>{./line-items/*}</Items>”);

Returns array of untyped XmlObjects

• If shape is known (.xsd) then cast using myXmlObject.changeType(FooDocument.type());

• Can run Xpath using

myXmlObject.selectPath(“./line-items/*”);

Returns array of typed XmlObjects

DemoMore XML Beans,

XmlCursor, XQuery

• • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • •

Content Broker : Architecture PatternContent Broker

Case Solved

• • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • •

References

• XML Case Study – When Click Meets Brick• http://dev2dev.bea.com

Q & A

Recommended