Jump to content

How to search on XML document ?


nobitavn94

Recommended Posts

Hi all ,Suppose I have an xml file having the struct as follow :<?xml ver="1.0" encoding...><MQA><QAs level="A"> <QA id="1"> <Q> --content of a question---</Q> <O> <a>option 1 </a> <a>option 2 </a> <a>option 3 </a> <a>option 4 </a> </O> <A> option 1</A> </QA> <QA id="2"> .... </QA>...<QAs level="B">...</QAs></MQA>With a given key word ,I want to find out what what QA tag has this key word.This mean that I want to search on xml document.Thank you so much !

Link to comment
Share on other sites

If you want case sencetive search, you can just use the contains() function in an XPath expression like this:

//QA[contains(.,$keyword)]

where $keyword is of course the word to search for.The way with which you initiate this search would depend of your environment. In PHP for example, see the DOM functions.If you want case incencetive search, the deal is almost the same, but you'll have to translate() both of the arguments into one case.

Link to comment
Share on other sites

  • 4 weeks later...

You know what I was thinking about with a search...you recently told me that it's not possible to "highlight" text when you do an XML search. But I think I believe otherwise.I haven't tested it but I'm pretty sure it will work...Using tokenize function... tokenize("$keyword", "\s+")and so on...Does that make sense?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...