16.10.2015 Views

Getting Started with DB2 Express-C

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

286 <strong>Getting</strong> <strong>Started</strong> <strong>with</strong> <strong>DB2</strong> <strong>Express</strong>-C<br />

AS sql VARCHAR(40)<br />

Listing 15.30 - An index on element name<br />

The statement in Listing 15.31 creates an index on all elements name<br />

CREATE INDEX idx3 ON customer(info)<br />

GENERATE KEY USING<br />

xmlpattern '//name'<br />

AS sql VARCHAR(40);<br />

Listing 15.31 - An index on all elements name<br />

The statement in Listing 15.32 creates an index on all text nodes (all values). This is not<br />

recommended, as it would be too expensive to maintain the index for update, delete and<br />

insert operations, and the index would be too large.<br />

CREATE INDEX idx4 ON customer(info)<br />

GENERATE KEY USING<br />

xmlpattern '//text()'<br />

AS sql VARCHAR(40);<br />

Listing 15.32 - An index on all text nodes (Not recommended)<br />

15.4 Working <strong>with</strong> XML Schemas<br />

<strong>DB2</strong> allows you to insert an XML document into the database if it is well-formed. If it's not,<br />

you will receive an error at insertion time. On the other hand, <strong>DB2</strong> does not force you to<br />

validate a XML document. If you wish to have an XML document validated, you have<br />

several alternatives as we will discuss in this section.<br />

15.4.1 Registering your XML Schemas<br />

XML Schemas are stored in the <strong>DB2</strong> databases in what is called an XML Schema<br />

repository. To add an XML Schema to a repository, you use the REGISTER XMLSCHEMA<br />

command.<br />

For example, let's say you have an XML document stored in file order.xml as shown in<br />

Figure 15.10

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!