Ive heard about Xpath a couple of times. Can someone explain me in detail what Xpath is?

XML Path Language (XPath), one of the most successful XML technologies, is a syntax and data model for addressing parts of an XML document. XPath includes over 100 built-in functions. There are functions for string values, numeric values, date and time comparison, node and QName manipulation, sequence manipulation, Boolean values, and more. XPath was designed to be used by XSLT, XPointer and other XML parsing software.

I have to work on XSLT. Do I have to know about XPath first for that?

XPath is a major element in the XSLT standard. Without XPath knowledge you will not be able to create XSLT documents.

I am working with DB2 database and want to learn Xquery. I have some experience with XPath. Will it be helpful in learning Xquery?

XQuery 1.0 and XPath 2.0 share the same data model and support the same functions and operators. If you have already studied XPath you will have no problems with understanding XQuery.

How do I return an XML value by evaluating XPath expression?

What are general DB2's XPath syntaxes?

These are W3 supported XPath syntaxes.

i) / = Represents the
XML root element.
ii) /tag1 = Represents the
element tag1 under root.
iii) /tag1/tag2/.../tagn = Represents an element with the
name tagn as the child of the descending chain from root, tag1, tag2,
through tagn-1.
iv) //tagn Represents any
element with the name tagn, where the double slashes denote zero or more
arbitrary tags.
v) /tag1//tagn Represents any element with
the name tagn, a child of an element with name
tag1 under root, where double slashes denote zero or more arbitrary tags.

vi) /tag1/tag2[tag3="5"] Represents an
element with the name tag3 has the value 5. tag3 is a child of an element
with name tag2 under tag1 and root.

vii) /tag1/tag2/@attr1 Represents the attribute attr1 of
an element tag2, which is a child of element tag1 under root.

viii) /tag1/tag2[@attr1="5"] Represents an element with the name tag2
whose attribute attr1 has the value 5. tag2 is a child of an element with
name tag1 under root.

ix)/tag1/tag2[@attr1="5"]/.../tagn Represents an element with the
name tagn, which is a child of the descending chain from root, tag1, tag2,
through tag n-1, where the attribute attr1 of tag2 has the value 5.

MTK can be downloaded at
http://www-306.ibm.com/software/data/db2/migration/mtk/. More information can be found at

How to create XPath expressions. Is there any easy way to create XPath

You can use the XPath expression wizard to create XPath expressions. XPath
expressions can be used to search through XML documents, extracting
information from the nodes (such as an element or attribute).

You can


I plan to design an XML Based Search Engine in Java. Will DB2 help me in
this regard?

Building a search engine that can be deployed over a parallel processing

SQL query optimizers can parallelize operations, SQL engines can exploit
parallel architectures and use multiple processors for query evaluation and
execution. Clearly we want XML processing to be able to
exploit massively parallel processing, clusters, and other parallel

SQL is set-oriented so it's possible to partition data across (processing)
nodes, partition queries, and combine results.An SQL query doesn't define a
navigation path for getting to data. The query just specifies what's wanted
and a query optimizer determines the most efficient means of execution.

So issue 1 is how to partition document collections for optimal parallel
execution with XPath and XQuery. I've not found any published research on
parallel evaluation or parallel execution with XPath.

The XPath 2.0 requirements document identifies the need for additional
string and aggregate functions, but doesn't define a requirement for being
able to invoke user-defined functions (UDFs). XQuery supports XPath
functions but it also supports UDFs.

If you are using an SQL products such as Oracle 8i and IBM DB2, you can add
UDFs for processing XML data by implementing them in Java, C/C++ and
deploying them as a database plug-in.For example, by implementing FOO() in
Java, I can use SELECT FOO() in SQL queries. It's possible to use FOO() in
parallel queries. DB2, for example, provides an ALLOW PARALLEL option when I
register my function classes with the database. Therefore, SQL queries can
still be "parallelized" if they include my Java, C/C++ UDFs. So issue is how
to express to XPath or XQuery details such as whether to use a single
instance of the Java class per query or allow parallel use of an UDF.

IBM Migration ToolKit (MTK) can be downloaded at
http://www-306.ibm.com/software/data/db2/migration/mtk/. More information can be found at

What are different XPath functions?

The DB2 XPath functions are a subset of the XPath 2.0 and XQuery 1.0
functions and operators

-> fn:abs function (DB2 XPath) = The fn:abs function returns the absolute
value of a numeric value.
-> fn:boolean function (DB2 XPath) = The fn:boolean function returns the
effective boolean value of a sequence.
-> fn:compare function (DB2 XPath) = The fn:compare function compares two
-> fn:concat function (DB2 XPath) = The fn:concat function concatenates two
or more strings into a single string.
-> fn:contains function (DB2 XPath) = The fn:contains function determines
whether a string contains a given substring
-> fn:count function (DB2 XPath) = The fn:count function returns the number
of values in a sequence
-> fn:data function (DB2 XPath) = The fn:data function converts a sequence
of items to a sequence of atomic values
-> fn:normalize-space function (DB2 XPath) = The fn:normalize-space function
strips leading and trailing whitespace characters from a string and replaces
multiple consecutive whitespace characters in the string with a single blank
-> fn:not function (DB2 XPath) = The fn:not function returns false if the
effective boolean value of an item is true, and true if the effective
boolean value of an item is false.
-> fn:round function (DB2 XPath)= The fn:round function returns the integer
that is closest to a numeric value.
-> fn:string function (DB2 XPath) = The fn:string function returns the
string representation of a value.
-> fn:string-length function (DB2 XPath) = The fn:string-length function
returns the length of a string
-> fn:substring function (DB2 XPath) = The fn:substring function returns a
substring of a string.
-> fn:sum function (DB2 XPath) = The fn:sum function returns the sum of the
values in a sequence.

I want to download DB2 XML Extender product. Where can I get it?

How does DB2 index XML columns internally?

XML applications that manage millions of XML documents are not uncommon.
Thus, indexing support for XML data is required to provide high query
performance. DB2 supports path-specific value indexes on XML columns so that
elements and attributes frequently used in predicates and cross-document
joins can be indexed. DB2 also supports XML-aware full-text indexing.

Example: create index idx1 on dept(deptdoc) generate key using xmlpattern
'/dept/employee/name' as sql varchar(35)

The xmlpattern is a path which identifies the XML nodes to be indexed. It is
called xmlpattern and not xpath
because only a subset of the XPath language is allowed in index definitions.
For example, wildcards (//,*) and namespaces are allowed but XPath
predicates such as /a/b[c=5] are not supported. Since we do not require a
single XML schema for all documents in an XML column, DB2 may not know which
data type to use in the index for a given xmlpattern. Thus, the user must
specify the data type explicitly in the "as sql <type>" clause.
The following types can be used:


How is handling XML different in DB2 8.x and DB2 9?

XML support in DB2 Universal Database (UDB) Version 8.x is based on DB2's
relational infrastructure. Previous to the DB2 Viper release, XML data was
either stored intact as a character large object (CLOB) or shredded to
relational tables.

DB2 UDB Version 9.1 has true native support for XML data. XML is now handled
as a new data type, and XML data is stored in a parsed annotated tree that
is separate from the relational data storage. XML indexing based on an XML
pattern has been introduced, along with support for XQuery and SQL/XML as
the languages to query and publish XML data. In order to understand the
impact of these new XML features on migration, it is necessary to compare
the different techniques for storing and querying XML data in the DB2 8.x,
to similar or new XML functionality available in DB2 UDB Version 9.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.