views:

55

answers:

2

Hi,

I have some xml data and I am trying to keyword search data. For example, if I search "some" for the following data it returns me the <id> and <title>.

<resource>
  <id>101</id>
  <title>Test Environment</title>
  <description><b>Some</b> description. </description>
  <type>classroom</type>
</resource>
<resource>
  <id>102</id>
  <title>ABC Test Environment</title>
  <description><b>Some</b> another description. </description>
  <type>classroom</type>
</resource>
...

I had a look on on xpath e.g. $xml->xpath('//title') but looks for elements only.

Basically what I need to do is to create a functionality where users can keyword search within the above data set which I receive from third party api in the above format. Any ideas how I can achieve this? using PHP/ Javascript etc.

Thanks.

+1  A: 

Xpath does let you search by the contents of the elements. A quick google search reveals this link: http://www.exampledepot.com/egs/org.w3c.dom/xpath_GetElemByText.html which will get you right as rain in no time.

Erik
just did a quick test as per instructions on the page and looks like the answer. will give it another go and lt you know later. lso there is a comment on that page - In IE 8 this method of using path is not working?? I'll see.Thanks
A: 

XPath does support this functionality, and it can be done on most browsers (I assume this is a web application). However, are you sure this is what you would like to do? How much data will you be sending to the client?

Garett