Chapter 4: Using Views
You have an XML document and want to receive part of the information for a single large message in a database and part of it in a Java Server Page (JSP). You supply the developers for each group—the database group and the Web group—with their own view of the information that they need to retrieve. This allows each group to concentrate on the information that is pertinent to them, and to use tools to map directly to their view of the schema without dealing with a potentially large message. Later, each resulting view message can be merged back into the original message that will be sent to a target system.
To merge views back into the original message you use the generated class com.sybase.DataBean.util.ViewSet. It takes XML documents that represent views and collects them back into a single XML document. Each of these documents can be added to a ViewSet and then serialized as a single XML document.
In the following example, at design time a developer creates a view on the ingredient element of recipe.dtd. This allows the developer to concentrate on a recipe's ingredient element without needing to understand the entire content model of recipe.dtd.
Without using a view, to find an ingredient you use the following:
Ingredient ing = recipe.getIngredientList().getIngredient();
Using a view to find an ingredient, you use the following:
ingredient ing = ingView.getIngredient(i);
This particular implementation of a view identifies all ingredients of a recipe that contain eggs.
public class IngSample
static void main(String args) throws Exception
"\n...Processing [" + args + "]..." );
the request view document, and set the input XML
as the main document.
recipe = new Recipe(new FileInputStream( args),
IngView ingView = new IngView(new
FileInputStream( args), true);
ingView = new IngView();
ingCount = ingView.getSize();
"Recipe [" + recipe.getHeader().getRecipeName().getData() + "] has the
following ingredients with eggs:" );
i=0; i<ingCount; i++ )
content = ingView.getIngredient(i).getFood().
content.startsWith("egg") || content.
|Copyright © 2005. Sybase Inc. All rights reserved.|