bea.com | products | dev2dev | support | askBEA
 Download Docs   Site Map   Glossary 
Search

Building Queries and Data Views

 Previous Next Contents Index View as PDF  

Understanding XML Namespaces

XML namespaces are a mechanism to ensure there are no name conflicts when combining XML documents. Liquid Data supports XML namespaces and includes namespaces in the XQuery queries generated in Data View Builder. This section includes the following topics:

XML Namespace Overview

XML Namespaces appear in queries as a string followed by a colon. For example, the xs:integer data type uses the XML namespace xs.

XML namespaces ensure that names do not collide when combining data from heterogeneous XML documents. For example, if there is an element named <tires> from an automobile tire manufacturer in one document and an element named <tires> from a bicycle tire manufacturer, it might not be appropriate to combine those elements, as they are very different things. XML namespaces can prevent such name collisions by referring to the elements as <automobile:tires> and <bicycle:tires>.

Predefined Namespaces in XQuery

The following table shows predefined namespaces used in XQuery:

Table 1-1 Predefined Namespaces in XQuery  

Namespace Prefix

Description

Examples

xf

The prefix for XQuery functions.

xf:data

xf:sum

xf:substring

xfext

The prefix for Liquid Data-specific extensions to the standard set of XQuery functions.

xfext:match

xfext:trim

xs

The prefix for XML schema types.

xs:element

xs:string

xsext

The prefix for Liquid Data-specific extensions to the standard set of XML schema types.

xsext:myownstringtype

Other XML Namespace References

The following are some internet links to more information on XML namespaces:

XML Namespaces in Liquid Data Queries

If you are using the Data View Builder to generate queries, it automatically generates the correct namespace declarations when it generates the query. If you are hand-coding your queries, you must include the necessary namespace declaration(s). For a list of data sources that require namespace declarations, see Data Sources that Require Namespace Declarations," on page 1-20.

Namespace Declarations in XQuery Prolog

The beginning portion of an XQuery is known as the prolog. For Liquid Data queries, the namespace declarations appear in the XQuery prolog. There can be zero or more namespace declarations in a query prolog. Each namespace has the following form:

namespace <logical_name> = "<URI>"

where <logical_name> is a string used as a prefix in the query and <URI> is a uniform resource indicator.

Consider the following simple query:

namespace view = "urn:views"

<CustomerOrderID>
{
for $view:MY_VIEW.order_2 in
                 view:MY_VIEW()/results/result/broadband/order
return
<ORDER_ID>{ xf:data($view:MY_VIEW.order_2/ORDER_ID) }
</ORDER_ID>
}
</CustomerOrderID>

The line in the prolog:

namespace view = "urn:views"

is the namespace declaration in this query. Each time the object (in this case, a view) is referenced in the query, the object name is prefixed with the logical name view.

You must define all namespaces in the XQuery prolog to use them in a query (except for the predefined namespaces described in Predefined Namespaces in XQuery," on page 1-18). If you do not define namespaces in the XQuery prolog, the query will fail with a compilation error.

Namespaces in Target Schema Definitions

When you use the Data View Builder to create or modify target schemas, you can specify a namespace for an element or an attribute. If you specify a namespace, it is added to the XML markup in the query (and therefore to the query results). For example, if you add the view namespace to an element of the target schema named milano as follows:


 

The query results for this target schema definition are of a form similar to the following:

<view:milano xmlns:view="urn:views">100.0</view:milano>

Data Sources that Require Namespace Declarations

All data sources except relational databases and XML files require the namespace declaration in the XQuery prolog. Queries involving the following data sources therefore require namespace declarations in the XQuery prolog:

Migrating Liquid Data 1.0 Queries

Liquid Data 1.0 did not support XML namespaces, and any queries used in Liquid Data  1.0 must be migrated to work in Liquid Data 1.1. If you have queries that are generated in a Data View Builder project file, you can open the project file in Data View Builder 1.1. When you click the test tab, the Data View Builder automatically generates the new query with the proper namespace declarations in the query prolog.

If you have stored queries and data views, you must use the queryMigrate tool to migrate the queries so they work properly in Liquid Data  1.1. For information on the queryMigrate tool, see Migrating Queries and Data Views in the Installation and Migration Guide.

 

Back to Top Previous Next