AmazonSearch
Description

   

    <?xml version="1.0"?>
    <!DOCTYPE XIB SYSTEM "http://www.cs.toronto.edu/km/xib/data/XIB.dtd">

    <XIB>
    <SERVICE name="AmazonSearch"/>
    <INPUT>
        <elementType id="amazonQuery"> <string/> </elementType>
        <elementType id="amazonMode">
        <attribute name="amazonModeValues" atttype="ENUMERATION"
            values="books music classical video toys electronics blended" />
        </elementType>
    </INPUT>
    <OUTPUT name="amazonBooks">
        <elementType id="author"> <string/> </elementType>
        <elementType id="title"> <string/> </elementType>
        <elementType id="publisher"> <string/> </elementType>
        <elementType id="year"> <string/> </elementType>
        <elementType id="price"> <string/> </elementType>
        <elementType id="amazonBook">
            <element type="author" />
            <element type="title" />
            <element type="price" />
        </elementType>
        <elementType id="amazonBooks">
            <element type="amazonBook" occurs="ZEROORMORE" />
        </elementType>
    </OUTPUT>
    <INPUTBINDING>
        <BASE method="POST" page="Elem(P, &quot;form&quot;)[0]">
        "http://www.amazon.com" </BASE>
        <BINDING variable="amazonQuery" mapsTo="keyword-query" />
        <BINDING variable="amazonMode" mapsTo="mode"/>
    </INPUTBINDING>
    <OUTPUTBINDING>
        <SCRIPT> <![CDATA[
            var titles = Elem(P, "a") inside Elem(P,"dt");
            var dd = Elem(P,"dd");
            var Author, Price, temp;
            i = 0;
            while i < Size(titles) do
                temp = Pat(dd[i], `[$](\d+[.]\d+)`);
                if (Size(temp) == 0) then
                    Price = nil;
                else
                    Price = ToReal(temp[0][1]);
                end;
                temp = Pat(dd[i], `^[^/]+`);
                if (Size(temp) == 0) then
                    Author = nil;
                else
                    Author = Str_Trim(Text(temp[0]));
                end;
                if(Str_IndexOf("Read more", Author) != -1) then
                    Author = Text(Pat(dd[i], `\w.*\n`)[0]);
                end;
 
                R = R + [
                    [.title = Text(titles[i]), price = Price, author = Author
                    .]];
                i = i+1;
            end; ]]>
        </SCRIPT>
    </OUTPUTBINDING>
    <DESCRIPTION> search for book information from Amazon.
    </DESCRIPTION>
    </XIB>

Return To Previous Page