Chapter 12. Searching and Filtering

Introduction

XPath is a popular way to select nodes from an XML document. If you are working with a single XML document or a series of XML documents in an XML Database— such as Apache Xindice—XPath is used to query, address, and filter XML content. Jakarta Commons JXPath allows you to use an XPath query to address objects in a collection or properties of a bean. JXPath is an unconventional application of an XML standard to Java objects, which allows you to quickly select objects from a Collection without the need for an Iterator and a comparison. For example, if you had a List of Person objects with an age property, you could select all of the people older than 10 by passing the expression /person[@age > 10] to a JXPathContext. JXPath implements a large subset of the XPath specification, and JXPath expressions can be applied to a wide array of objects, beans, Document Object Model (DOM) Documents, collections, and maps. This chapter shows you how to use Commons JXPath to search and filter objects in a collection.

A system will frequently need to search for and identify occurrences of text in a large set of documents. To accomplish this, you will use a tool, such as Jakarta Lucene, to create a searchable index of terms. For example, if you’ve used an IDE, such as Eclipse, you may find yourself searching for all of the occurrences of the text “testVariable” in your workspace. Eclipse can quickly perform any number of complex searches, and when it ...

Get Jakarta Commons Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.