XML extraction form

Hi ...I have used XPath to extract data relevant to a particular country,from my XML file..see below..
//country[@name = 'Albania']

<country id="cid-cia-Albania" continent="Europe" name="Albania" datacode="AL" total_area="28750" population="3249136" population_growth="1.34" infant_mortality="49.2" gdp_agri="55" inflation="16" gdp_total="4100" indep_date="28 11 1912" government="emerging democracy" capital="Tirane">
<ethnicgroups name="Greeks">3</ethnicgroups>
<ethnicgroups name="Albanian">95</ethnicgroups>
<religions name="Muslim">70</religions>
<religions name="Roman Catholic">10</religions>
<religions name="Albanian Orthodox">20</religions>
<borders country="cid-cia-Greece">282</borders>
<borders country="cid-cia-Macedonia">151</borders>
<borders country="cid-cia-Serbia-and-Montenegro">287</borders>
<coasts>Adriatic Sea</coasts>
<coasts>Ionian Sea</coasts>
<coasts>Serbia</coasts>
<coasts>Montenegro</coasts>
</country>

this works well, however I need to make an interactive form for users to type in any country, and have the relevant data returned in the same html form. Something like this


<form action="">
<input type="text" id="searchme" />
<input type="submit" onclick="searchIndex(); return false;" />
</form>
<div id="resultshere">
</div>
</body>
</html>

My problem is how to associate the "searchme" id, with the country in question..can I substitute the name of the country like this
//country[@name = 'searchme'] , do I also have to use the get method...also this only has to work on my local machine....

thanks for your help
Jack210



Answer this question

XML extraction form

  • Robert Green

    Thank you very much!!!!
    Jack210

  • Rogger

    Hi Martin,

    Your example works fine, I am getting to grips with the code as some of it is certainly beyond my beginner level. One question though, my sample data only included one country...I thought by simply renaming and swapping my larger file to your naming convention i.e test2006123001.xml, it would detect all the other countries...unfortunatley it still only detects Albania...am I missing some other reference to the original file..

    Your assistance has been invaluable...

    Thank you

    Jack210


  • Daikoku

    Assuming it only has to work with IE 6 or later you could use an XSLT stylesheet to transform the country XML data to HTML.

    Here is an example doing that, using your sample XML data for Albania. The example works fine for me here with IE 6 on Windows XP. Note that the XSLT stylesheet is just an example, you can change or at least fine tune how the stylesheet outputs all the data. Currently everything ends up in tables, that seemed to be one way to deal with the rather incoherent data available for a country.



  • XML extraction form