Re: XPath Search
Brought to you by:
bs_php,
nigelswinson
From: Nigel S. <nig...@us...> - 2006-01-29 03:11:57
|
Try stuff like this: // Find all nodes that have a feature element that contains the word = cabinet, case insensitively $aMatches =3D = $Object->match("//*[contains(x-tolower(feature),'cabinet')]"); // Cycle through the nodes we find foreach ($aMatches as $Match) { // $Match will be something like /Product[1]/Component[3] echo $Object->getAttributes($Match.'/image', 'src'); echo $Object->wholeText($Match.'/title'); } Sorry it took so long to respond, I was hoping someone else on the list = would beat me to it. Nigel ----- Original Message -----=20 From: Tod McIntyre=20 To: php...@li...=20 Sent: Saturday, January 14, 2006 7:55 PM Subject: XPath Search I just found this class and it seems to offer exactly what I want. = I'm new to it & xpath though so I'm slowly learning how to do things. I = want to perform a search on my XML database for a string entered by a = user. Say for instance "cabinet". From this I want to search several = XML files of the following structure:=20 <?xml version=3D"1.0"?> <!DOCTYPE product PUBLIC "-//RYE//DTD IMAGEDB 1.0 Strict//EN" = "component.dtd"> <product> <component id=3D"wall_cab"> <title>Wall Cabinet</title> <image src=3D"/images/cabinetry/wall_cab.jpg" /> <link href=3D"/products/cabinetry/wall.html" /> <feature>Sturdy double wall door </feature>=20 <feature>Door has perforated inside wall for hanging hooks for = tools etc</feature>=20 <feature>Solid steel construction 20-Gauge (.036") thick </feature> = <feature>One shelf included 24" x 10" x 0.6" </feature> <keywords>tools sports sporting </keywords> </component>=20 <component id=3D"component2"> ... </component> =20 </product> I have added keywords to enhance the search functionality. What I = want to do is extract the title, image, and link of any product that = contains, in any tag, the string entered by the user. I'm not exactly sure how to do this.=20 Can someone point me in the right direction? I know it's asking a = lot, but even a quick pointer would help me out. I'm not a very = experienced php programmer . Thanks very much, Brad |