Source for file html.php

Documentation is available at html.php

  1. <?php
  2. /**
  3.  * Using QueryPath.
  4.  *
  5.  * This file contains an example of how QueryPath can be used
  6.  * to generate web pages. Part of the design of this example is to exhibit many
  7.  * different QueryPath functions in one long chain. All of the methods shown
  8.  * here are fully documented in {@link QueryPath}.
  9.  *
  10.  * The method used in this example is a typical example of how QueryPath can
  11.  * gradually build up content. Other methods include using {@link QPTPL} for
  12.  * templates, injecting database information with {@link QPDB}, and merging
  13.  * data from one QueryPath to another.
  14.  *
  15.  * @package Examples
  16.  * @author M Butcher <matt@aleph-null.tv>
  17.  * @license LGPL The GNU Lesser GPL (LGPL) or an MIT-like license.
  18.  */
  19.  
  20. require_once '../src/QueryPath/QueryPath.php';
  21.  
  22. // Begin with an HTML stub document (XHTML, actually), and navigate to the title.
  23. qp(QueryPath::HTML_STUB'title')
  24.   // Add some text to the title
  25.   ->text('Example of QueryPath.')
  26.   // Now look for the <body> element
  27.   ->find(':root body')
  28.   // Inside the body, add a title and paragraph.
  29.   ->append('<h1>This is a test page</h1><p>Test text</p>')
  30.   // Now we select the paragraph we just created inside the body
  31.   ->children('p')
  32.   // Add a 'class="some-class"' attribute to the paragraph
  33.   ->attr('class''some-class')
  34.   // And add a style attribute, too, setting the background color.
  35.   ->css('background-color''#eee')
  36.   // Now go back to the paragraph again
  37.   ->parent()
  38.   // Before the paragraph and the title, add an empty table.
  39.   ->prepend('<table id="my-table"></table>')
  40.   // Now let's go to the table...
  41.   ->find('#my-table')
  42.   // Add a couple of empty rows
  43.   ->append('<tr></tr><tr></tr>')
  44.   // select the rows (both at once)
  45.   ->children()
  46.   // Add a CSS class to both rows
  47.   ->addClass('table-row')
  48.   // Now just get the first row (at position 0)
  49.   ->eq(0)
  50.   // Add a table header in the first row
  51.   ->append('<th>This is the header</th>')
  52.   // Now go to the next row
  53.   ->next()
  54.   // Add some data to this row
  55.   ->append('<td>This is the data</td>')
  56.   // Write it all out as HTML
  57.   ->writeHTML();
  58. ?>

Documentation generated on Sun, 25 Jul 2010 16:09:05 -0500 by phpDocumentor 1.4.3