Searching XML

HTML

<input id='xml_search' type='text' onkeyup='search_xml()' />
<div id='results'></div>
<div style='display:none'>
    <div id='myxml'>
        <?xml version="1.0"?>
        <books>
            <book id="bk101">
                <author>Gambardella, Matthew</author>
                <title>XML Developer's Guide</title>
                <genre>Computer</genre>
                <price>44.95</price>
                <publish_date>2000-10-01</publish_date>
                <description>An in-depth look at creating applications 
                    with XML.</description>
            </book>
            <book id="bk102">
                <author>Ralls, Kim</author>
                <title>Midnight Rain</title>
                <genre>Fantasy</genre>
                <price>5.95</price>
                <publish_date>2000-12-16</publish_date>
                <description>A former architect battles corporate zombies, 
                    an evil sorceress, and her own childhood to become queen 
                    of the world.</description>
            </book>
            <book id="bk103">
                <author>Corets, Eva</author>
                <title>Maeve Ascendant</title>
                <genre>Fantasy</genre>
                <price>5.95</price>
                <publish_date>2000-11-17</publish_date>
                <description>After the collapse of a nanotechnology 
                    society in England, the young survivors lay the 
                    foundation for a new society.</description>
            </book>
            <book id="bk104">
                <author>Corets, Eva</author>
                <title>Oberon's Legacy</title>
                <genre>Fantasy</genre>
                <price>5.95</price>
                <publish_date>2001-03-10</publish_date>
                <description>In post-apocalypse England, the mysterious 
                    agent known only as Oberon helps to create a new life 
                    for the inhabitants of London. Sequel to...

JavaScript

search_xml = function() {
    var books = $('myxml').getElements('book');
    $('results').innerHTML = "";
    for (var i = 0; i < books.length; i++) {
        // search each book here
        var book_title = books[i].getElement('title');
        var book_match = book_title.textContent.test($('xml_search').value, "i");
        if (book_match) {
            $('results').adopt(new Element('div', {
                id: 'myResult' + i,
                html: books[i].getElement('title').textContent
            }));
        }
    }
};

search_xml();