PDA

View Full Version : XML Search?


mikenye
04-15-2009, 07:57 PM
Hi all,

Im new to the forum so please forgive me if a do somthing wrong :)

Ok im fairly new to Javascript and Ajax but im in the middle of building a CD based application running through html etc. I have a large xml file that is used to populate different fields in a form....

such as a Country area.....when users select a Country it hides and shows different towns.......then when a town is selected different areas show as PDF links.

Ive now been asked to add search functionality to the whole thing...so I need to build a search form that will search for either a 4 letter identifier <icao>egff</icao> or the area name either in whole or part of such as <area>heathrow</area> then display the relevant pdfs associated within that tag?

Is it possible to search the XML like that? is it possible to search part names etc and get the full tag?

I have this as a live website using PHP and SQL.....so it had a lot more functionality the CD is a lite version for those with no internet access.

Any help or suggestions extremely welcome!

cheers
Mike

rnd me
04-16-2009, 12:09 AM
yes it's possible. XPATH would probably be the fastest way to do this. I know for strict XML documents, XPATH is supported in all major browsers, as well as PHP.

something like:

//icao[contains( . , "eg")]

or
//area[contains( . , "hea")]

should work if my xpath memory is correct.

check out w3schools for examples on how to use xpath.

mikenye
04-16-2009, 05:35 PM
Thanks!

Ive had a look at the W3 site and I cant work out exatly how that code will fit in / work?

can you explain a bit more please?

thanks
Mike

jasonone
04-17-2009, 05:05 AM
XPath, the XML Path Language, is a query language for selecting nodes from an XML document. In addition, XPath may be used to compute values (e.g., strings, numbers, or Boolean values) from the content of an XML document. XPath was defined by the World Wide Web Consortium (W3C).

There are currently two versions in use.

XPath 1.0 became a Recommendation on 16 November 1999 and is widely implemented and used, either on its own (called via an API from languages such as Java, C# or JavaScript), or embedded in languages such as XSLT or XForms.

The current version of the language is XPath 2.0, which became a Recommendation on 23 January 2007. A number of implementations exist but are not as widely used as XPath 1.0. The XPath 2.0 language specification is much larger than XPath 1.0 and changes some of the fundamental concepts of the language such as the type system; the language specification is described in a separate article.

The most notable change is that XPath 2.0 has a much richer type system;[2] Every value is now a sequence (a single atomic value or node is regarded as a sequence of length one). XPath 1.0 node-sets are replaced by node sequences, which may be in any order.

To support richer type sets, XPath 2.0 offers a greatly expanded set of functions and operators.

XPath 2.0 is in fact a subset of XQuery 1.0. It offers a for expression which is cut-down version of the "FLWOR" expressions in XQuery. It is possible to describe the language by listing the parts of XQuery that it leaves out: the main examples are the query prolog, element and attribute constructors, the remainder of the "FLWOR" syntax, and the typeswitch expression.

See also:

* XPath 1.0 (http://en.wikipedia.org/wiki/XPath_1.0)
* XPath 2.0 (http://en.wikipedia.org/wiki/XPath_2.0)

mikenye
04-23-2009, 04:36 PM
Thanks all for the help.....im getting there now :)


Mike