Re: XPath Search
Brought to you by:
bs_php,
nigelswinson
From: Tod M. <tod...@gm...> - 2006-02-06 18:34:21
|
Can someone help me out? I can't seem to get the match working... I'm using: $components=3D$xPath->match("//component[contains(feature,'string')]"); which returns nothing in the array, even though "string" is in the file when I use : $components=3D$xPath->match("//*[contains(.,'string')]"); however, it works. This isn't exactly ideal though as I just want to return the component node itself that contains the "string" within the feature, not the actual feature. Nigel, your solution of $components=3D$xPath->match("//*[contains(feature,'string')]"); doesn't wor= k either. It seems whenever I put the actual node name in the contains function it doesn't work. Brad On 1/28/06, Nigel Swinson <nig...@us...> wrote: > > 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 ----- > *From:* Tod McIntyre <tod...@gm...> > *To:* php...@li... > *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: > > <?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> > <feature>Door has perforated inside wall for hanging hooks for tools > etc</feature> > <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> > <component id=3D"component2"> > ... > </component> > </product> > > I have added keywords to enhance the search functionality. What I want t= o > 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. > > 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 p= hp > programmer > . > Thanks very much, > > Brad > > |