Databases Reference
In-Depth Information
$found = $xcs → findAnywhere($keyword, Zend_Db_Xml_XmlUtil::DATA);
To be more specific about case and where exactly in the document to search,
see Example 3-19.
Example 3-19 Detail searching
$search = array('title' => 'Rainbow',
'author' => 'Staple');
$options = array('caseSensitive' => true,
'exactMatch' => false,
'logic' => 'or;
$found = $xcs → find($search,
Zend_Db_Xml_XmlUtil::DATA,
$options);
find() returns an XML iterator, which represents a set of XML documents as
shown in Example 3-20.
Example 3-20 Get XML iterator
foreach($found as $current) {
// get a SimplXML object and do something with it
$sxml = Zend_Db_Xml_XmlUtil::exportToSimpleXML(
$current,
Zend_Db_Xml_XmlUtil::DATA);
// prints the contents of the <title> element
echo $sxml → title;
}
We can also use a simple XPath expression to search as shown in
Example 3-21.
Example 3-21 Search using XPath expression
$xml = $xcs → executeXPathPredicateQuery("/book[date='2004-12-21']",
Zend_Db_Xml_Xml_Util::DATA);
foreach ($xml as $current) {
$sxml = Zend_Db_Xml_XmlUtil::exportToSimpleXML($current,
Zend_Db_Xml_XmlUtil::DATA);
echo '<p>Title: ' . $sxml → title;
}
This will output Mom, Dad, and The Rainbow house .
Search WWH ::




Custom Search