Example: Index namespaces in XML data

The following XML fragment contains the namespace book:title:
<book>
<book:title>Graph Theory</book:title>
<author>Stewart</author>
<date>January 14, 2006</date>
</book>
You can create a bts index with the include_namespaces parameter disabled as in the statement:
CREATE INDEX books_bts ON books(xml_data bts_lvarchar_ops) 
USING bts(all_xmltags="yes",include_namespaces="no",xmlpath_processing="yes") 
IN bts_sbspace;
In that case, the namespace prefix book: is ignored. The index will have the following fields.
/book/title:graph theory
/book/author:stewart
/book/date:january 14, 2006
Also, you can create a bts index with the include_namespaces parameter enabled, as in the statement:
CREATE INDEX books_bts ON books(xml_data bts_lvarchar_ops) 
USING bts(all_xmltags="yes",include_namespaces="yes",xmlpath_processing="yes") 
IN bts_sbspace;
In that case, the tag with the namespace book:title is the first field. The index has the following fields:
/book/book:title:graph theory
/book/author:stewart
/book/date:january 14, 2006
To search the field /book/book:title: for the text theory, use the search predicate:
bts_contains("/book/book\:title:theory")
When you specify tags with the xmltags parameter, you can index the tags with and without namespaces in different combinations using the include_namespaces parameter. For example, given the XML fragments:
<bsns:bookstore>
		<title> Marine Buyers' Guide </title>
		<bns2:title> Boat Catalog </bns2:title>
	</bsns:bookstore>

<bsns:bookstore>
		<bns1:title> Toy Catalog </bns1:title>
		<bns2:title> Wish Book </bns2:title>
	</bsns:bookstore>
To index only the title tag, use the format:
CREATE INDEX bookstore_bts ON bookstores(xml_data bts_lvarchar_ops) 
USING bts(xmltag="(title)",include_namespaces="yes) 
IN bts_sbspace;

Even though the include_namespaces parameter is enabled, the index will contain only one field because the fields bns1:title and bns2:title do not match the specified tag title.

If you want to index a namespace, include the namespace prefix in the specified tags. For example if you use the format:
CREATE INDEX bookstore_bts ON bookstores(xml_data bts_lvarchar_ops) 
USING bts(xmltag="(title,bns1:title)",include_namespaces="yes) 
IN bts_sbspace;
The index will contain the fields:
title: Marine Buyers' Guide
bns1:title: Toy Catalog