The purpose of views  Chapter 5: Locating the Java documentation

Chapter 4: Using Views

An example of using a view

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


        public static void main(String[] args) throws Exception


        System.out.println( "\n...Processing [" + args[0] + "]..."    );

         // Create the request view document, and set the input          XML as the main document.

                   Recipe recipe = new Recipe(new FileInputStream(         args[0]), true);

IngView ingView = new IngView(new FileInputStream( args[0]), true);

                   IngView ingView = new IngView();

        ingView.setMainDocument( recipe );

                 int ingCount = ingView.getSize();

                  // Print list of all ingredient names that contain a           Food item of "egg".

        System.out.println( "Recipe [" +         recipe.getHeader().getRecipeName().getData() + "] has         the following ingredients with eggs:" );

                  for(int i=0; i<ingCount; i++ )


                  String content = ingView.getIngredient(i).getFood().          getData();

                   if( content.startsWith("egg") || content.          endsWith("eggs") )


         System.out.println( content );





Copyright © 2005. Sybase Inc. All rights reserved. Chapter 5: Locating the Java documentation