My favorites | Sign in
Project Logo
                
Feeds:
People details
Project owners:
  henning.schroeder

Look at the examples below to see how the API works

    >>> html = """
    ...   <?xml version="1.0" encoding="ISO-8859-1"?>
    ...    <bookstore>
    ...    <book category="COOKING">
    ...      <title lang="en">Everyday Italian</title>
    ...      <author>Giada De Laurentiis</author>
    ...      <year>2005</year>
    ...      <price>30.00</price>
    ...    </book>
    ...    <book category="CHILDREN">
    ...      <title lang="en">Harry Potter</title>
    ...      <author>J K. Rowling</author>
    ...      <year>2005</year>
    ...      <price>29.99</price>
    ...    </book>
    ...    <book category="WEB">
    ...      <title lang="en">XQuery Kick Start</title>
    ...      <author>James McGovern</author>
    ...      <author>Per Bothner</author>
    ...      <author>Kurt Cagle</author>
    ...      <author>James Linn</author>
    ...      <author>Vaidyanathan Nagarajan</author>
    ...      <year>2003</year>
    ...      <price>49.99</price>
    ...    </book>
    ...    <book category="WEB">
    ...      <title lang="en">Learning XML</title>
    ...      <author>Erik T. Ray</author>
    ...      <year>2003</year>
    ...      <price>39.95</price>
    ...    </book>
    ...    </bookstore>
    ... """

    >>> spoon = Spoon(html)
    >>> print spoon.bookstore.book[1].title
    Harry Potter
    
    >>> len(spoon.bookstore.book)
    4

    >>> for book in spoon.bookstore.book(category="WEB"):
    ...      print book.title
    XQuery Kick Start
    Learning XML
    
    >>> spoon._.author[4]
    <author>Kurt Cagle</author>
    
    >>> books = spoon.bookstore.book
    >>> print books(books.price > 40).title
    XQuery Kick Start
    
    >>> print (books.author == "Erik T. Ray")._parent.title
    Learning XML

    >>> len(books(books.year == 2003))
    2


    >>> print books(lambda souptag: souptag["category"] == "COOKING").title
    Everyday Italian


    >>> query = LazySpoon().bookstore.book[0].author.inner_html()
    >>> print "\\n".join([str(c) for c in query.__calls__])
    (<built-in function getattr>, ('bookstore',), {})
    (<built-in function getattr>, ('book',), {})
    (<built-in function getitem>, (0,), {})
    (<built-in function getattr>, ('author',), {})
    (<built-in function getattr>, ('inner_html',), {})
    (<built-in function apply>, (), {})

    >>> query.evaluate(spoon)
    'Giada De Laurentiis'









Hosted by Google Code