From c8281eadb91144cf864d5e19b0ee1686bc799cb5 Mon Sep 17 00:00:00 2001
From: Jake Jackson
Date: Sun, 11 Dec 2022 13:23:13 +1100
Subject: [PATCH 01/14] Start fleshing out improvements to the examples
---
examples/at_a_glance.php | 3 +-
examples/database_import.php | 3 +-
examples/dbpedia.php | 2 +-
examples/dirty_html.php | 2 +-
examples/doc.html | 109 --------
examples/doc.php | 108 --------
examples/docx.php | 3 +-
examples/fetch_rss.php | 2 +-
examples/html.php | 2 +-
examples/matching_text_content.php | 2 +-
examples/musicbrainz.php | 2 +-
examples/odt.php | 2 +-
examples/openoffice.odt | Bin 10021 -> 0 bytes
examples/parse_php.php | 4 +-
.../index.php | 93 +++++++
.../template.html | 111 ++++++++
examples/querypath.xml | 236 ------------------
examples/simple_example.php | 4 +-
examples/sparql.php | 2 +-
examples/svg.php | 2 +-
examples/techniques.php | 2 +-
examples/xml.php | 3 +-
22 files changed, 225 insertions(+), 472 deletions(-)
delete mode 100644 examples/doc.html
delete mode 100644 examples/doc.php
create mode 100644 examples/parsing-xml-from-url-and-dynamically-generating-html/index.php
create mode 100644 examples/parsing-xml-from-url-and-dynamically-generating-html/template.html
delete mode 100644 examples/querypath.xml
diff --git a/examples/at_a_glance.php b/examples/at_a_glance.php
index 5f95a5f2..57ee0d41 100644
--- a/examples/at_a_glance.php
+++ b/examples/at_a_glance.php
@@ -1,5 +1,6 @@
diff --git a/examples/database_import.php b/examples/database_import.php
index 308fd947..3a4f5bee 100644
--- a/examples/database_import.php
+++ b/examples/database_import.php
@@ -7,8 +7,7 @@
* @license LGPL The GNU Lesser GPL (LGPL) or an MIT-like license.
*/
-require_once '../src/QueryPath/QueryPath.php';
-require_once '../src/QueryPath/Extension/QPDB.php';
+require_once __DIR__ . '/../vendor/autoload.php';
// Set the default database.
QPDB::baseDB('sqlite:../test/db/qpTest.db');
diff --git a/examples/dbpedia.php b/examples/dbpedia.php
index b4f4f0c5..7efb5b5c 100644
--- a/examples/dbpedia.php
+++ b/examples/dbpedia.php
@@ -25,7 +25,7 @@
* @see musicbrainz.php
*/
-require_once '../src/QueryPath/QueryPath.php';
+require_once __DIR__ . '/../vendor/autoload.php';
// The URL to look up (any of these works):
$url = 'http://dbpedia.org/data/The_Beatles.rdf';
diff --git a/examples/dirty_html.php b/examples/dirty_html.php
index 2c2c3e68..391c47bf 100644
--- a/examples/dirty_html.php
+++ b/examples/dirty_html.php
@@ -7,7 +7,7 @@
* @license LGPL The GNU Lesser GPL (LGPL) or an MIT-like license.
* @see http://www.urbandictionary.com/
*/
-require_once '../src/QueryPath/QueryPath.php';
+require_once __DIR__ . '/../vendor/autoload.php';
print 'Urban Dictionary Random Word Generator
';
diff --git a/examples/doc.html b/examples/doc.html
deleted file mode 100644
index 4588cf18..00000000
--- a/examples/doc.html
+++ /dev/null
@@ -1,109 +0,0 @@
-
-
-
-
-Documentation
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/examples/doc.php b/examples/doc.php
deleted file mode 100644
index f80d7eb7..00000000
--- a/examples/doc.php
+++ /dev/null
@@ -1,108 +0,0 @@
-$v
";
-}
-
-// The document skeleton
-$qpdoc = htmlqp('doc.html', 'body');
-
-$key = $_GET['key'];
-
-// The jQuery categories that are used in QueryPath
-$qparray = [
- 'Tree Traversal',
- 'Child Filter',
- 'Attribute',
- 'Content Filter',
- 'Basic Filter',
- 'Hierarchy',
- 'Basic',
- 'Filtering',
- 'Miscellaneous Traversing',
- 'DOM Insertion, Outside',
- 'DOM Insertion, Inside',
- 'Attributes',
- 'Style Properties',
-];
-
-$jqnames = [];
-$qpnames = [];
-
-// Search through the xml file to find any entries of jQuery entities
-foreach (qp('querypath.xml', 'entry') as $entry) {
- $qpnames[$entry->attr('name')] =
- [
- 'desc' => $entry->find('desc')->innerXML(),
- 'jquery' => $entry->parent()->find('jquery')->innerXML(),
- 'querypath' => $entry->parent()->find('querypath')->innerXML(),
- ];
-}
-
-// Search through the xml file to find all entries of jQuery entities
-foreach (htmlqp('http://api.jquery.com/api/', 'entry') as $entry) {
- $category = false;
- $category = array_search($entry->find('category:first')->attr('name'), $qparray);
- while ($entry->next('category')->html() != null) {
- $category = (array_search($entry->attr('name'), $qparray)) ? true : $category;
- if ($category) {
- break;
- }
- }
- if ($category) {
- $jqnames[$entry->parent()->attr('name')] =
- [
- 'longdesc' => $entry->find('longdesc')->innerXML(),
- 'name' => $entry->parent()->find('category')->attr('name'),
- ];
- }
-}
-
-// Map the keys & sort them
-$jqkeys = array_keys($jqnames);
-$jqkeys = array_map("addClasses", $jqkeys);
-sort($jqkeys);
-
-// Add the keys to the nav bar
-$qpdoc->find('#leftbody');
-foreach ($jqkeys as $k => $v) {
- $qpdoc->append($v);
-}
-
-// Add the description to the main window if the key exists
-if (array_key_exists($key, $jqnames)) {
- if (array_key_exists($key, $qpnames)) {
- $qpdoc->top()->find('#rightfunction')->text('Function: ' . ucfirst($key));
- $qpdoc->top()->find('#rightdesc')->text($qpnames[$key]['desc']);
- $qpdoc->top()->find('#righttitle')->text('How it\'s done in jQuery');
- $qpdoc->top()->find('#righttext')->text($qpnames[$key]['jquery']);
- $qpdoc->top()->find('#righttitle2')->text('How it\'s done in QueryPath');
- $qpdoc->top()->find('#righttext2')->text($qpnames[$key]['querypath']);
- } else {
- $qpdoc->top()->find('#rightfunction')->text('Function: ' . ucfirst($key));
- $qpdoc->top()->find('#rightdesc')->remove();
- $qpdoc->top()->find('#righttitle')->text('jQuery Documentation');
- $qpdoc->top()->find('#righttext')->append($jqnames[$key]['longdesc']);
- }
-}
-
-// Write the document
-$qpdoc->writeHTML();
diff --git a/examples/docx.php b/examples/docx.php
index e917c099..6b872a29 100644
--- a/examples/docx.php
+++ b/examples/docx.php
@@ -9,7 +9,8 @@
* @license LGPL The GNU Lesser GPL (LGPL) or an MIT-like license.
* @see http://www.urbandictionary.com/
*/
-require_once '../src/QueryPath/QueryPath.php';
+require_once __DIR__ . '/../vendor/autoload.php';
+
$path = 'http://eabrand.com/images/test.docx';
//$path = 'docx_document.xml';
diff --git a/examples/fetch_rss.php b/examples/fetch_rss.php
index 44767bc9..3e9243da 100644
--- a/examples/fetch_rss.php
+++ b/examples/fetch_rss.php
@@ -15,7 +15,7 @@
* @author M Butcher
* @license LGPL The GNU Lesser GPL (LGPL) or an MIT-like license.
*/
-require_once '../src/QueryPath/QueryPath.php';
+require_once __DIR__ . '/../vendor/autoload.php';
// The URL of the remote RSS feed.
$remote = 'http://querypath.org/aggregator/rss/2/rss.xml';
diff --git a/examples/html.php b/examples/html.php
index 199ef26d..6d4282ed 100644
--- a/examples/html.php
+++ b/examples/html.php
@@ -16,7 +16,7 @@
* @license LGPL The GNU Lesser GPL (LGPL) or an MIT-like license.
*/
-require_once '../src/qp.php';
+require_once __DIR__ . '/../vendor/autoload.php';
// Begin with an HTML stub document (XHTML, actually), and navigate to the title.
qp(QueryPath::HTML_STUB, 'title')
diff --git a/examples/matching_text_content.php b/examples/matching_text_content.php
index 69891260..3fd6fe20 100644
--- a/examples/matching_text_content.php
+++ b/examples/matching_text_content.php
@@ -18,7 +18,7 @@
*/
/** Include QueryPath. */
-require_once '../src/QueryPath/QueryPath.php';
+require_once __DIR__ . '/../vendor/autoload.php';
/**
* Check if the string 'Release' is in the text content of any matched nodes.
diff --git a/examples/musicbrainz.php b/examples/musicbrainz.php
index 480bf998..a334e43e 100644
--- a/examples/musicbrainz.php
+++ b/examples/musicbrainz.php
@@ -15,7 +15,7 @@
* @license LGPL The GNU Lesser GPL (LGPL) or an MIT-like license.
* @see http://musicbrainz.org
*/
-require_once '../src/QueryPath/QueryPath.php';
+require_once __DIR__ . '/../vendor/autoload.php';
$artist_url = 'http://musicbrainz.org/ws/1/artist/?type=xml&name=u2';
$album_url = 'http://musicbrainz.org/ws/1/release/?type=xml&artistid=';
diff --git a/examples/odt.php b/examples/odt.php
index 1028e494..6a6ad2d1 100644
--- a/examples/odt.php
+++ b/examples/odt.php
@@ -18,7 +18,7 @@
*/
/** Include main QP library. */
-require_once '../src/QueryPath/QueryPath.php';
+require_once __DIR__ . '/../vendor/autoload.php';
// If you have the Zip lib combiled in:
//$file = 'zip://openoffice.odt#content';
diff --git a/examples/openoffice.odt b/examples/openoffice.odt
index 69632f530767fd2ddeec399f3a4167a58b563455..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644
GIT binary patch
literal 0
HcmV?d00001
literal 10021
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
NcN4LvFEL)e{U2CrZKePK
diff --git a/examples/parse_php.php b/examples/parse_php.php
index c2b6dc6e..bb39506a 100644
--- a/examples/parse_php.php
+++ b/examples/parse_php.php
@@ -14,6 +14,8 @@
* @author M Butcher
* @license LGPL The GNU Lesser GPL (LGPL) or an MIT-like license.
*/
+
+require_once __DIR__ . '/../vendor/autoload.php';
?>
@@ -21,8 +23,6 @@
text();
?>
diff --git a/examples/parsing-xml-from-url-and-dynamically-generating-html/index.php b/examples/parsing-xml-from-url-and-dynamically-generating-html/index.php
new file mode 100644
index 00000000..2b82441a
--- /dev/null
+++ b/examples/parsing-xml-from-url-and-dynamically-generating-html/index.php
@@ -0,0 +1,93 @@
+' . htmlentities($name) . '
';
+}
+
+// The document skeleton
+$qp = html5qp(__DIR__ . '/template.html', 'body');
+
+$key = $_GET['key'] ?? '';
+
+// Only display jQuery methods from these categories
+$categories = [
+ 'traversing/tree-traversal' => 'Tree Traversal',
+ 'selectors/child-filter-selectors' => 'Child Filter',
+ 'selectors/attribute-selectors' => 'Attribute',
+ 'selectors/content-filter-selector' => 'Content Filter',
+ 'selectors/basic-filter-selectors' => 'Basic Filter',
+ 'selectors/hierarchy-selectors' => 'Hierarchy',
+ 'selectors/basic-css-selectors' => 'Basic',
+ 'traversing/filtering' => 'Filtering',
+ 'traversing/miscellaneous-traversal' => 'Miscellaneous Traversing',
+ 'manipulation/dom-insertion-outside' => 'DOM Insertion, Outside',
+ 'manipulation/dom-insertion-inside' => 'DOM Insertion, Inside',
+ 'manipulation/style-properties' => 'Style Properties',
+];
+
+$jquery = [];
+
+try {
+ // Search through the xml file to find all entries of jQuery entities
+ foreach (qp('https://api.jquery.com/resources/api.xml', 'entry') as $entry) {
+ foreach ($entry->find('category') as $item) {
+ $category = $categories[ $item->attr('slug') ] ?? '';
+ if ($category) {
+ $jquery[ $entry->attr('name') ] = [
+ 'longdesc' => $entry->find('longdesc')->innerXML(),
+ 'name' => sprintf('%s: %s', $category, $entry->attr('name')),
+ ];
+
+ break;
+ }
+ }
+ }
+
+ // Map the keys & sort them
+ $jqueryKeys = array_keys($jquery);
+ sort($jqueryKeys);
+
+ $links = array_map('addClasses', $jqueryKeys);
+ // Add the keys to the nav bar
+ $sidebar = $qp->find('#leftbody');
+ foreach ($links as $link) {
+ $sidebar->append($link);
+ }
+
+ // Add the description to the main window if the key exists
+ $key = isset($jquery[$key]) ? $key : $jqueryKeys[0];
+
+ $qp->top()->find('#rightfunction')->text('Function: ' . ucfirst($key));
+ $qp->top()->find('#rightdesc')->remove();
+ $qp->top()->find('#righttitle')->text('jQuery Documentation');
+ $qp->top()->find('#righttext')->append($jquery[ $key ]['longdesc']);
+
+ $qp->top()->find('#current-year')->text(date('Y'));
+
+ // Write the document
+ $qp->writeHTML5();
+} catch (\QueryPath\Exception $e) {
+ die($e->getMessage());
+}
diff --git a/examples/parsing-xml-from-url-and-dynamically-generating-html/template.html b/examples/parsing-xml-from-url-and-dynamically-generating-html/template.html
new file mode 100644
index 00000000..5a06fc4e
--- /dev/null
+++ b/examples/parsing-xml-from-url-and-dynamically-generating-html/template.html
@@ -0,0 +1,111 @@
+
+
+
+
+ Example: Parsing XML from a URL and inserting into a HTML Template File
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/examples/querypath.xml b/examples/querypath.xml
deleted file mode 100644
index f16e4beb..00000000
--- a/examples/querypath.xml
+++ /dev/null
@@ -1,236 +0,0 @@
-
-
-
-
- Add constructs a new element at the specified location in the document.
-
-
-
-
- - list item 1
- - list item 2
- - list item 3
-
- a paragraph
-
- $('li').add('new paragraph
')
- .css('background-color', 'red');
-
-
-
- test.html
-
-
-
-
- Hello
- Hello Again
-
-
-
-
- test.php
-
- require_once 'QueryPath.php';
-
- htmlqp('test.html')
- $qp->append('new paragraph
')
- ->find('p')
- ->css('background-color', 'red')
- ->top()
- ->writeXHTML();
-
-
-
-
-
- It's important to note that this method does not replace a class. It simply adds the class, appending it to any which may already be assigned to the elements.
-
- More than one class may be added at a time, separated by a space, to the set of matched elements.
-
-
- This method is often used with .removeClass() to switch elements' classes from one to another.
-
- $('p').addClass('myClass yourClass');
-
- $('p').removeClass('myClass noClass').addClass('yourClass');
-
- $('ul li:last').addClass(function() {
- return 'item-' + $(this).index();
- });
-
- Given an unordered list with five li elements, this example adds the class "item-4" to the last li.
-
-
- test.html
-
-
-
-
- Hello
- Hello Again
-
-
-
-
- test.php
-
- require_once 'QueryPath.php';
-
- htmlqp('test.html')
- $qp->append('')
- ->find('div')
- ->addClass('testing one two three')
- ->top()
- ->writeXHTML();
-
-
-
-
-
- The selector expression preceding the method is the container after which the content is inserted.
-
-
- This method is often used with .removeClass() to switch elements' classes from one to another.
-
-
-
Greetings
-
Hello
-
Goodbye
-
- We can create content and insert it after several elements at once:
- $('.inner').after('Test
');
- We can also select an element on the page and insert it after another:
- $('.container').after($('h2'));
- .after() will also work on disconnected DOM nodes. For example, given the following code:
- $('').after('');
-
-
-
- test.html
-
-
-
-
- Hello
- Hello Again
-
-
-
-
- test.php
-
- require_once 'QueryPath.php';
-
- htmlqp('test.html')
- $qp->append('First P
Second P
')
- ->children('p')
- ->after('new paragraph
')
- ->top()
- ->writeHTML();
-
-
-
-
-
-
-
-
-
-
-
Greetings
-
Hello
-
Goodbye
-
-
-
-
- test.html
-
-
-
-
- Hello
- Hello Again
-
-
-
-
- test.php
-
- require_once 'QueryPath.php';
-
- htmlqp('test.html')
- $qp->append('First P
Second P
')
- ->children('p')
- ->after('new paragraph
')
- ->top()
- ->writeHTML();
-
-
-
-
-
- Add a yellow background to a span and to all of the children of an element.
-
-
-
-
-
-
-
-
-
- Hello
- Hello Again
-
-
-
-
-
-
- test.html
-
-
-
-
- Hello
- Hello Again
-
-
-
-
- test.php
-
- require_once 'QueryPath.php';
-
- htmlqp('test.html')
- ->find('span') // Point querypath to the span
- ->css('background', 'yellow') // Add the CSS
- ->top() // Point QueryPath to the top of the page
- ->writeXHTML(); // Write HTML, notice it does not use print
-
-
-
-
\ No newline at end of file
diff --git a/examples/simple_example.php b/examples/simple_example.php
index 61c31d8f..1474727d 100644
--- a/examples/simple_example.php
+++ b/examples/simple_example.php
@@ -22,7 +22,9 @@
* @see html.php
* @see https://fedorahosted.org/querypath/wiki/QueryPathTutorial The Official Tutorial
*/
-require_once '../src/QueryPath/QueryPath.php';
+
+require_once __DIR__ . '/../vendor/autoload.php';
+
qp(QueryPath::HTML_STUB)->find('body')->text('Hello World')->writeHTML();
$qp = htmlqp(QueryPath::HTML_STUB, 'body');
diff --git a/examples/sparql.php b/examples/sparql.php
index b8dcceb0..ef73ab9c 100644
--- a/examples/sparql.php
+++ b/examples/sparql.php
@@ -20,7 +20,7 @@
* @see http://drupal.org/project/querypath
*/
-require '../src/QueryPath/QueryPath.php';
+require_once __DIR__ . '/../vendor/autoload.php';
// We are using the dbpedia database to execute a SPARQL query.
diff --git a/examples/svg.php b/examples/svg.php
index 23e655a3..d173318a 100644
--- a/examples/svg.php
+++ b/examples/svg.php
@@ -16,7 +16,7 @@
* @license LGPL The GNU Lesser GPL (LGPL) or an MIT-like license.
*/
-require_once '../src/QueryPath/QueryPath.php';
+require_once __DIR__ . '/../vendor/autoload.php';
// Let's stub out a basic SVG document.
$svg_stub = '
diff --git a/examples/techniques.php b/examples/techniques.php
index e47f5ddb..19f7cefd 100644
--- a/examples/techniques.php
+++ b/examples/techniques.php
@@ -19,7 +19,7 @@
* @license LGPL (The GNU Lesser GPL) or an MIT-like license.
*/
-require '../src/QueryPath/QueryPath.php';
+require_once __DIR__ . '/../vendor/autoload.php';
$demo = '
diff --git a/examples/xml.php b/examples/xml.php
index 1293f29b..36448ccf 100644
--- a/examples/xml.php
+++ b/examples/xml.php
@@ -19,8 +19,7 @@
* @license LGPL The GNU Lesser GPL (LGPL) or an MIT-like license.
*/
-require_once '../src/QueryPath/QueryPath.php';
-
+require_once __DIR__ . '/../vendor/autoload.php';
// Create a new XML document wrapped in a QueryPath.
// By default, it will point to the root element,
From c9280d6eeb67d0a3139028855991f2425c93aef1 Mon Sep 17 00:00:00 2001
From: Jake Jackson
Date: Sun, 11 Dec 2022 20:43:55 +1100
Subject: [PATCH 02/14] Refine example
---
.../index.php | 127 ++++++++++++++++++
.../index.php | 28 ++--
2 files changed, 141 insertions(+), 14 deletions(-)
create mode 100644 examples/basic-manipulation-filter-and-retrieval/index.php
diff --git a/examples/basic-manipulation-filter-and-retrieval/index.php b/examples/basic-manipulation-filter-and-retrieval/index.php
new file mode 100644
index 00000000..6584822d
--- /dev/null
+++ b/examples/basic-manipulation-filter-and-retrieval/index.php
@@ -0,0 +1,127 @@
+
+
+ | one |
+ two |
+ three |
+
+
+
+ | four |
+ five |
+ six |
+
+
+EOF;
+
+echo 'Basic HTML Usage
';
+echo 'The following HTML chunk will get parsed, traverse, filtered, and manipulated:';
+echo '' . htmlspecialchars($html) . '
';
+
+echo 'Example 1
';
+echo 'Add the attribute class="cell" to all <td> elements:';
+
+echo '';
+
+echo htmlspecialchars(
+ html5qp($html, 'td')
+ ->attr('class', 'cell')
+ ->top() // return to tag
+ ->innerHTML5() // get mark-up without . Use ->html5() to return a valid HTML document (Doctype and all)
+);
+
+echo '
';
+
+echo 'Example 2
';
+echo 'Use html5qp($html)->find(\'#row2 > td:nth-child(2)\')->text(); to display the contents of the second <td> in the second <tr>:
';
+
+echo html5qp($html)
+ ->find('#row2 > td:nth-child(2)')
+ ->text();
+
+echo '';
+
+echo 'Example 3
';
+echo 'Append another row to the HTML and output the results:';
+echo '';
+
+echo htmlspecialchars(
+ html5qp($html, 'tr:last')
+ ->after("\n\n\t\n\t\t| seven | \n\t\teight | \n\t\tnine | \n\t
")
+ ->top() // return to tag
+ ->innerHTML5() // get mark-up without . Use ->html5() to return a valid HTML document (Doctype and all)
+);
+
+echo '';
+
+
+/*
+ * XML Example
+ */
+$xml = <<
+
+
+ This is the DOM description...
+
+
+
+ This is the Traversing description...
+
+
+
+ This is the Filtering description...
+
+
+
+ This is the Selectors description...
+
+
+EOF;
+
+echo 'Basic XML Usage
';
+echo 'The following XML will get parsed, traverse, filtered, and manipulated:';
+echo '' . htmlspecialchars($xml) . '
';
+
+echo 'Example 1
';
+echo 'Add the attribute class="item" to all <desc> elements:';
+
+echo '';
+
+echo htmlspecialchars(
+ qp($xml, 'desc')
+ ->attr('class', 'item')
+ ->top() // return to the tag
+ ->xml() // output a valid XML document. Use ->innerXML() to get the contents of instead.
+);
+
+echo '
';
+
+echo 'Example 2
';
+echo 'Use qp($xml)->find(\'categories > category:nth-child(3) desc\')->text(); to display the contents of the third <desc>:
';
+
+echo qp($xml)
+ ->find('categories > category:nth-child(3) desc')
+ ->text();
+
+echo '';
+
+echo 'Example 3
';
+echo 'Append another category to the XML and output the results:';
+echo '';
+
+echo htmlspecialchars(
+ qp($xml, 'category:last')
+ ->after("\n\n\t\n\t\tThe appended node...\n\t")
+ ->top()
+ ->xml()
+);
+
+echo '';
diff --git a/examples/parsing-xml-from-url-and-dynamically-generating-html/index.php b/examples/parsing-xml-from-url-and-dynamically-generating-html/index.php
index 2b82441a..76443cfa 100644
--- a/examples/parsing-xml-from-url-and-dynamically-generating-html/index.php
+++ b/examples/parsing-xml-from-url-and-dynamically-generating-html/index.php
@@ -33,18 +33,18 @@ function addClasses(string $name): string
// Only display jQuery methods from these categories
$categories = [
- 'traversing/tree-traversal' => 'Tree Traversal',
- 'selectors/child-filter-selectors' => 'Child Filter',
- 'selectors/attribute-selectors' => 'Attribute',
+ 'traversing/tree-traversal' => 'Tree Traversal',
+ 'selectors/child-filter-selectors' => 'Child Filter',
+ 'selectors/attribute-selectors' => 'Attribute',
'selectors/content-filter-selector' => 'Content Filter',
- 'selectors/basic-filter-selectors' => 'Basic Filter',
- 'selectors/hierarchy-selectors' => 'Hierarchy',
- 'selectors/basic-css-selectors' => 'Basic',
- 'traversing/filtering' => 'Filtering',
+ 'selectors/basic-filter-selectors' => 'Basic Filter',
+ 'selectors/hierarchy-selectors' => 'Hierarchy',
+ 'selectors/basic-css-selectors' => 'Basic',
+ 'traversing/filtering' => 'Filtering',
'traversing/miscellaneous-traversal' => 'Miscellaneous Traversing',
- 'manipulation/dom-insertion-outside' => 'DOM Insertion, Outside',
- 'manipulation/dom-insertion-inside' => 'DOM Insertion, Inside',
- 'manipulation/style-properties' => 'Style Properties',
+ 'manipulation/dom-insertion-outside' => 'DOM Insertion, Outside',
+ 'manipulation/dom-insertion-inside' => 'DOM Insertion, Inside',
+ 'manipulation/style-properties' => 'Style Properties',
];
$jquery = [];
@@ -53,11 +53,11 @@ function addClasses(string $name): string
// Search through the xml file to find all entries of jQuery entities
foreach (qp('https://api.jquery.com/resources/api.xml', 'entry') as $entry) {
foreach ($entry->find('category') as $item) {
- $category = $categories[ $item->attr('slug') ] ?? '';
+ $category = $categories[$item->attr('slug')] ?? '';
if ($category) {
- $jquery[ $entry->attr('name') ] = [
+ $jquery[$entry->attr('name')] = [
'longdesc' => $entry->find('longdesc')->innerXML(),
- 'name' => sprintf('%s: %s', $category, $entry->attr('name')),
+ 'name' => sprintf('%s: %s', $category, $entry->attr('name')),
];
break;
@@ -82,7 +82,7 @@ function addClasses(string $name): string
$qp->top()->find('#rightfunction')->text('Function: ' . ucfirst($key));
$qp->top()->find('#rightdesc')->remove();
$qp->top()->find('#righttitle')->text('jQuery Documentation');
- $qp->top()->find('#righttext')->append($jquery[ $key ]['longdesc']);
+ $qp->top()->find('#righttext')->append($jquery[$key]['longdesc']);
$qp->top()->find('#current-year')->text(date('Y'));
From 760d88f49f07b1eaf8e25096b8f9b419e76b04eb Mon Sep 17 00:00:00 2001
From: Jake Jackson
Date: Sun, 11 Dec 2022 22:46:06 +1100
Subject: [PATCH 03/14] Do HTTP Stream + Namespace Example
---
examples/at_a_glance.php | 29 ------
examples/database_import.php | 61 ------------
examples/dbpedia.php | 98 -------------------
.../index.php | 77 +++++++++++++++
4 files changed, 77 insertions(+), 188 deletions(-)
delete mode 100644 examples/at_a_glance.php
delete mode 100644 examples/database_import.php
delete mode 100644 examples/dbpedia.php
create mode 100644 examples/http-stream-xml-namespaces-and-linked-data/index.php
diff --git a/examples/at_a_glance.php b/examples/at_a_glance.php
deleted file mode 100644
index 57ee0d41..00000000
--- a/examples/at_a_glance.php
+++ /dev/null
@@ -1,29 +0,0 @@
-
-
-
- | one | two | three |
-
-
- | four | five | six |
-
-
-EOF;
-
-print "\nExample 1: \n";
-// Get all of the elements in the document and add the
-// attribute `foo='bar'`:
-qp($xml, 'td')->attr('foo', 'bar')->writeXML();
-
-print "\nExample 2: \n";
-
-// Or print the contents of the third TD in the second row:
-print qp($xml, '#row2>td:nth(3)')->text();
-
-print "\nExample 3: \n";
-// Or append another row to the XML and then write the
-// result to standard output:
-qp($xml, 'tr:last')->after(' | | | |
')->writeXML();
diff --git a/examples/database_import.php b/examples/database_import.php
deleted file mode 100644
index 3a4f5bee..00000000
--- a/examples/database_import.php
+++ /dev/null
@@ -1,61 +0,0 @@
-
- * @license LGPL The GNU Lesser GPL (LGPL) or an MIT-like license.
- */
-
-require_once __DIR__ . '/../vendor/autoload.php';
-
-// Set the default database.
-QPDB::baseDB('sqlite:../test/db/qpTest.db');
-
-// To begin, let's create a new database. We can do this outside
-// of QueryPath:
-$db = QPDB::getBaseDB();
-$db->exec('CREATE TABLE IF NOT EXISTS qpdb_article (title, author, body)');
-
-// Here's our sample article:
-$article = '
-
- Use QueryPath for Fun and Profit
-
- Matt
- Butcher
-
-
- QueryPath is a great tool.
- Use it in many ways.
- ]]>
-
-';
-
-// Now let's take this article and insert it into the database:
-$qp = qp($article);
-
-// We are going to store our insert params in here.
-$params = [];
-
-// First, let's get the title
-$params[':title'] = $qp->find('title')->text();
-
-// Next, let's get the name:
-$params[':name'] = $qp->top()->find('author>last')->text() . ', ' . $qp->prev('first')->text();
-
-// Finally, let's get the article content:
-$params[':body'] = $qp->top()->find('body')->text();
-
-// Here's the query we are going to run:
-$sql = 'INSERT INTO qpdb_article (title, author, body) VALUES (:title, :name, :body)';
-
-// Now we can insert this:
-$qp->query($sql, $params);
-
-// Finally, we can now read this information back out into an HTML document
-qp(QueryPath::HTML_STUB, 'body')->queryInto('SELECT * FROM qpdb_article')->writeHTML();
-
-// Finally, we clean up:
-$qp->exec('DROP TABLE qpdb_article');
diff --git a/examples/dbpedia.php b/examples/dbpedia.php
deleted file mode 100644
index 7efb5b5c..00000000
--- a/examples/dbpedia.php
+++ /dev/null
@@ -1,98 +0,0 @@
-
- * @license LGPL The GNU Lesser GPL (LGPL) or an MIT-like license.
- * @see http://www.w3.org/DesignIssues/LinkedData.html
- * @see http://dbpedia.org
- * @see sparql.php
- * @see musicbrainz.php
- */
-
-require_once __DIR__ . '/../vendor/autoload.php';
-
-// The URL to look up (any of these works):
-$url = 'http://dbpedia.org/data/The_Beatles.rdf';
-//$url = 'http://dbpedia.org/data/Swansea.rdf';
-//$url = 'http://dbpedia.org/data/The_Lord_of_the_Rings.rdf';
-// HTTP headers:
-$headers = [
- 'Accept: application/rdf,application/rdf+xml;q=0.9,*/*;q=0.8',
- 'Accept-Language: en-us,en',
- 'Accept-Charset: ISO-8859-1,utf-8',
- 'User-Agent: QueryPath/1.2',
-];
-
-// The context options:
-$options = [
- 'http' => [
- 'method' => 'GET',
- 'protocol_version' => 1.1,
- 'header' => implode("\r\n", $headers),
- ],
-];
-
-// Create a stream context that will tell QueryPath how to
-// load the file.
-$cxt = stream_context_create($options);
-
-// Fetch the URL and select all rdf:Description elements.
-// (Note that | is the CSS 3 equiv of colons for namespacing.)
-// To add the context, we pass it in as an option to QueryPath.
-$qp = qp($url, 'rdf|Description', ['context' => $cxt]);
-//$qp = qp('The_Beatles.rdf');
-
-printf("There are %d descriptions in this record.\n", $qp->size());
-
-// Here, we use rdf|* to select all elements in the RDF namespace.
-$qp->top()->find('rdf|*');
-printf("There are %d RDF items in this record.\n", $qp->size());
-
-// Standard pseudo-classes that are not HTML specific can be used on
-// namespaced elements, too.
-print "About: " . $qp->top()->find('rdfs|label:first')->text() . PHP_EOL;
-print "About (FOAF): " . $qp->top()->find('foaf|name:first')->text() . PHP_EOL;
-
-// Namespaced attributes can be retrieved using the same sort of delimiting.
-print "\nComment:\n";
-print $qp->top()->find('rdfs|comment[xml|lang="en"]')->text();
-print PHP_EOL;
-
-$qp->top();
-
-print "\nImages:\n";
-foreach ($qp->branch()->find('foaf|img') as $img) {
- // Note that when we use attr() we are using the XML name, NOT
- // the CSS 3 name. So it is rdf:resource, not rdf|resource.
- // The same goes for the tag() function -- it will return
- // the full element name (e.g. rdf:Description).
- print $img->attr('rdf:resource') . PHP_EOL;
-}
-
-print "\nImages Galleries:\n";
-foreach ($qp->branch()->find('dbpprop|hasPhotoCollection') as $img) {
- print $img->attr('rdf:resource') . PHP_EOL;
-}
-
-print "\nOther Sites:\n";
-foreach ($qp->branch()->find('foaf|page') as $img) {
- print $img->attr('rdf:resource') . PHP_EOL;
-}
-
-//$qp->writeXML();
diff --git a/examples/http-stream-xml-namespaces-and-linked-data/index.php b/examples/http-stream-xml-namespaces-and-linked-data/index.php
new file mode 100644
index 00000000..5bd51974
--- /dev/null
+++ b/examples/http-stream-xml-namespaces-and-linked-data/index.php
@@ -0,0 +1,77 @@
+
+ * @license LGPL The GNU Lesser GPL (LGPL) or an MIT-like license.
+ * @see http://www.w3.org/DesignIssues/LinkedData.html
+ * @see http://dbpedia.org
+ * @see sparql.php
+ * @see musicbrainz.php
+ */
+
+require_once __DIR__ . '/../../vendor/autoload.php';
+
+// The URL to look up:
+$url = 'https://dbpedia.org/resource/Ben_Sealey';
+
+// HTTP headers:
+$headers = [
+ 'Accept: application/rdf,application/rdf+xml;q=0.9,*/*;q=0.8',
+ 'Accept-Language: en-us,en',
+ 'Accept-Charset: ISO-8859-1,utf-8',
+ 'User-Agent: QueryPath/1.2',
+];
+
+// The context options:
+$options = [
+ 'http' => [
+ 'method' => 'GET',
+ 'protocol_version' => 1.1,
+ 'header' => implode("\r\n", $headers),
+ ],
+];
+
+// Create a stream context that will tell QueryPath how to load the file.
+$context = stream_context_create($options);
+
+// Fetch the URL and select all rdf:Description elements.
+// (Note that | is the CSS 3 equiv of colons for namespacing.)
+// To add the context, we pass it in as an option to QueryPath.
+$qp = qp($url, 'rdf|Description', ['context' => $context]);
+
+printf('There are %d descriptions in this record.
' . PHP_EOL, $qp->count());
+
+// Here, we use foaf|* to select all elements in the FOAF namespace.
+printf('There are %d DBO items in this record.
' . PHP_EOL, $qp->top()->find('dbo|*')->count());
+
+// Standard pseudo-classes that are not HTML specific can be used on namespaced elements, too.
+echo 'About (RDFS): ' . $qp->top()->find('rdfs|label:first-of-type')->text() . '
' . PHP_EOL;
+echo 'About (FOAF): ' . $qp->top()->find('foaf|name:first-of-type')->text() . '
' . PHP_EOL;
+
+// Namespaced attributes can be retrieved using the same sort of delimiting.
+echo PHP_EOL . '
Comment:
' . PHP_EOL;
+echo $qp->top()->find('rdfs|comment[xml|lang="en"]')->text();
+echo '
' . PHP_EOL;
+
+$qp->top();
+
+echo PHP_EOL . '
Other Sites:
' . PHP_EOL;
+foreach ($qp as $item) {
+ echo $item->attr('rdf:about') . '
' . PHP_EOL;
+}
From d6058ff76423389b5ded12f27b53715be7d481b0 Mon Sep 17 00:00:00 2001
From: Jake Jackson
Date: Tue, 13 Dec 2022 08:58:22 +1100
Subject: [PATCH 04/14] Continue refactoring examples
---
examples/basic-docx-parser/index.php | 115 +
examples/basic-docx-parser/output.xml | 2035 +++++++++
examples/{ => basic-docx-parser}/test.docx | Bin
.../index.php | 144 +-
examples/dirty_html.php | 19 -
examples/docx.php | 117 -
examples/docx_document.xml | 3914 -----------------
.../index.php | 41 +-
.../index.php | 45 +-
.../remote-filter-and-retrieval/index.php | 46 +
10 files changed, 2316 insertions(+), 4160 deletions(-)
create mode 100644 examples/basic-docx-parser/index.php
create mode 100644 examples/basic-docx-parser/output.xml
rename examples/{ => basic-docx-parser}/test.docx (100%)
delete mode 100644 examples/dirty_html.php
delete mode 100644 examples/docx.php
delete mode 100644 examples/docx_document.xml
create mode 100644 examples/remote-filter-and-retrieval/index.php
diff --git a/examples/basic-docx-parser/index.php b/examples/basic-docx-parser/index.php
new file mode 100644
index 00000000..f4339d08
--- /dev/null
+++ b/examples/basic-docx-parser/index.php
@@ -0,0 +1,115 @@
+find('w|r') as $qr) {
+ echo format($qr);
+ }
+
+ echo '
';
+ }
+} catch (Exception $e) {
+ die($e->getMessage());
+}
+
+/**
+ * Get the node text and apply basic formatting, if necessary
+ *
+ * @param DOMQuery $qp
+ *
+ * @return string
+ * @throws ParseException
+ * @throws Exception
+ */
+function format(DOMQuery $qp): string
+{
+ $text = $qp->find('w|t')->text() . ' ';
+
+ $text = checkUnderline($qp) ? sprintf('%s', $text) : $text;
+ $text = checkBold($qp) ? sprintf('%s', $text) : $text;
+
+ return $text;
+}
+
+/**
+ * Look for the node to determine if the text is bolded
+ *
+ * @param DOMQuery $qp
+ *
+ * @return bool
+ * @throws ParseException
+ * @throws Exception
+ */
+function checkBold(DOMQuery $qp): bool
+{
+ return (bool) $qp->children('w|rPr')
+ ->children('w|b')
+ ->count();
+}
+
+/**
+ * Look for the node to determine if the text is underlined
+ *
+ * @param DOMQuery $qp
+ *
+ * @return bool
+ * @throws ParseException
+ * @throws Exception
+ */
+function checkUnderline(DOMQuery $qp): bool
+{
+ return (bool) $qp->children('w|rPr')
+ ->children('w|u')
+ ->count();
+}
+
+/**
+ * Extract the text from a docx file
+ *
+ * @param string $archiveFile The path to the .docx file to extract information from
+ * @return string
+ */
+function docx2text(string $archiveFile): string
+{
+ $dataFile = 'word/document.xml';
+
+ if (!class_exists('ZipArchive', false)) {
+ throw new RuntimeException('ZipArchive extension must be enabled to parse .docx files');
+ }
+
+ $zip = new ZipArchive();
+ // Open received archive file
+ if (true !== $zip->open($archiveFile)) {
+ throw new RuntimeException('Could not open the file using ZipArchive: ' . $zip->getStatusString());
+ }
+
+ $data = '';
+ // Search for the docx data file
+ if (($index = $zip->locateName($dataFile)) !== false) {
+ $data = $zip->getFromIndex($index);
+ }
+
+ // Close zip to prevent memory leak
+ $zip->close();
+
+ return $data;
+}
diff --git a/examples/basic-docx-parser/output.xml b/examples/basic-docx-parser/output.xml
new file mode 100644
index 00000000..d7341169
--- /dev/null
+++ b/examples/basic-docx-parser/output.xml
@@ -0,0 +1,2035 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Computer Forensics Class Syllabus
+
+
+
+
+
+
+
+
+ -
+
+
+
+
+
+
+
+
+
+ Fall
+
+
+
+
+
+
+
+
+
+ 2009
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Course No.:
+
+
+
+
+
+
+
+
+ Comp 340-001 /
+
+
+
+
+
+
+
+ Comp 488-004
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ INSTRUCTOR:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Scott Jones
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Email
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ sjone18@luc.edu
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Work Phone
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 312-915-7987
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Office Location
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 512D Lewis Tower
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Office Hours
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 6PM to 7PM Wednesdays or by appt.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ OFFICIAL TEXT:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ “Computer Evidence Collection and Preservation Second Edition”
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ by
+
+
+
+
+
+
+
+ Christopher L.T. Brown, ISBN-10: 1-58450-699-7
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ The schedule of class readings is officially as follows:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Week
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Date
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Book Chapter To Read
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ ------------------------
+
+
+
+
+
+
+ -----------------------------------------------------
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 8/26
+
+
+
+
+
+
+
+
+
+
+
+
+
+ N/A – Class Intro
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 9/2
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Chapters 1 & 2
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 9/9
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Chapters 3 & 4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 9/16
+
+
+
+
+
+
+
+ Chapters 5 & 6
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 9/23
+
+
+
+
+
+
+
+ Chapters 7 & 8
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 9/30
+
+
+
+
+
+
+
+ Chapters 9 & 10
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 10/7
+
+
+
+
+
+
+
+ Chapters 11 & 12
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 10/14
+
+
+
+
+
+
+
+ Chapters 13 & 14
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 10/21
+
+
+
+
+
+
+
+ Chapters 15, 16, & 17
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 10/28
+
+
+
+
+
+
+
+ In-class projects
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 11/4
+
+
+
+
+
+
+
+ In-class projects
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 11/11
+
+
+
+
+
+
+
+ In-class projects
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 11/18
+
+
+
+
+
+
+
+ In-class projects
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 11/25
+
+
+
+
+
+
+
+ In-class projects
+
+
+
+
+
+
+ *
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 12/2
+
+
+
+
+
+
+
+ In-class projects
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 12/9
+
+
+
+
+
+
+
+ In-class projects
+
+
+
+
+
+
+ *
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 12/16
+
+
+
+
+
+
+
+ In-class projects
+
+
+
+
+
+
+ *
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Class readings and assignments may change as needed.
+
+
+
+
+
+
+ 12/9/09 is generally designated a rest/study day in the academic calendar, so class may not be
+ meeting. 12/16/09 is the final Wednesday within this semester and the tentative date for the final
+ exam. This may be changed with short notice by the school as needed.
+
+
+
+
+
+
+
+ To the extent that a given date for class is cancelled by the school for any reason, that week’s reading will be bumped back accordingly.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ As newsworthy events become available, we may supplement our classroom discussions accordingly. I
+ encourage all students to pay attention to news stories on television or the Internet related to
+ computer forensics and computer technology in general.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ IN-CLASS PROJECTS:
+
+
+
+
+
+
+
+ Starting in week four, this class will begin to conduct in-class work using real-world computer
+ forensics hardware and/or software. In order to accomplish this, I highly recommend that each
+ student bring two or more USB thumb drives to class. I recommend that the smaller of the two be
+ around 512 MB in size and the larger one be at least 2 GB in size.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ QUIZZES & TESTS:
+
+
+
+
+
+
+
+ All quizzes and tests will be administered via Blackboard. Without prior arrangements I will not
+ accept make up quizzes or tests. Emergencies require that I receive an email in a timely fashion (24
+ hour period) telling me your name, the date you missed class, and explaining to me why I should
+ allow you to take the quiz or test late. By default my answer will be no. If I allow you to retake
+ the quiz or test, I reserve the right to deduct points accordingly for your lateness.
+
+
+
+
+
+
+
+ I reserve the right to give pop quizzes at any time.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ GROUPWORK:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Each student will be sharing a laptop computer with at least one other student each week. I may
+ also require students
+
+
+
+
+
+
+
+ to work in larger groups for specific tasks/projects. I reserve the right to ask specific students to swap groups if/when I find that students are not intermingling adequately. In the real world, you do not always get to choose with whom you work, and this class strives to provide real world examples and experience.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ GOALS:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ There are a few specific goals for which this class will strive.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ GOAL 1 – by mid-term, every student will have created at least one or more forensic images
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ GOAL 2 – every student understands how to create basic forensic images
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ GOAL 3 – every student understands the fundamental theories underlying computer forensics
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ GOAL 4 – every student will gain basic skills desired presently by employers for IT staff
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ GRADE SCALE:
+
+
+
+
+
+
+
+ Every student EARNS their own grade. The grading scale is as follows:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 92+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 91
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ A-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 90
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ B+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 89 – 84
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ B
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 83
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ B-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 82
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ C+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 81
+
+
+
+
+
+
+ -75
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 74
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ C-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 73
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ D+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 72-67
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ D
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 66
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ D-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 65 or less
+
+
+
+
+
+
+
+ F
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Instructor Comments:
+
+
+
+
+
+
+
+ There are no dumb questions, only unasked ones. If you do not understand something it is your
+ responsibility to let me know. Please ask questions in class, during breaks, after class, and even
+ via email if you like. I will assume you understand and m
+
+
+
+
+
+
+
+ ove on if you do not inform me otherwise
+
+
+
+
+
+
+ .
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ I welcome feedback from my students. Please feel free to send an email to the above LUC email address. No class-related emails at any other address will be accepted.
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/examples/test.docx b/examples/basic-docx-parser/test.docx
similarity index 100%
rename from examples/test.docx
rename to examples/basic-docx-parser/test.docx
diff --git a/examples/basic-manipulation-filter-and-retrieval/index.php b/examples/basic-manipulation-filter-and-retrieval/index.php
index 6584822d..48983897 100644
--- a/examples/basic-manipulation-filter-and-retrieval/index.php
+++ b/examples/basic-manipulation-filter-and-retrieval/index.php
@@ -21,47 +21,6 @@
EOF;
-echo 'Basic HTML Usage
';
-echo 'The following HTML chunk will get parsed, traverse, filtered, and manipulated:';
-echo '' . htmlspecialchars($html) . '
';
-
-echo 'Example 1
';
-echo 'Add the attribute class="cell" to all <td> elements:';
-
-echo '';
-
-echo htmlspecialchars(
- html5qp($html, 'td')
- ->attr('class', 'cell')
- ->top() // return to tag
- ->innerHTML5() // get mark-up without . Use ->html5() to return a valid HTML document (Doctype and all)
-);
-
-echo '
';
-
-echo 'Example 2
';
-echo 'Use html5qp($html)->find(\'#row2 > td:nth-child(2)\')->text(); to display the contents of the second <td> in the second <tr>:
';
-
-echo html5qp($html)
- ->find('#row2 > td:nth-child(2)')
- ->text();
-
-echo '';
-
-echo 'Example 3
';
-echo 'Append another row to the HTML and output the results:';
-echo '';
-
-echo htmlspecialchars(
- html5qp($html, 'tr:last')
- ->after("\n\n\t\n\t\t| seven | \n\t\teight | \n\t\tnine | \n\t
")
- ->top() // return to tag
- ->innerHTML5() // get mark-up without . Use ->html5() to return a valid HTML document (Doctype and all)
-);
-
-echo '';
-
-
/*
* XML Example
*/
@@ -86,42 +45,87 @@
EOF;
-echo 'Basic XML Usage
';
-echo 'The following XML will get parsed, traverse, filtered, and manipulated:';
-echo '' . htmlspecialchars($xml) . '
';
+try {
+ echo 'Basic HTML Usage
';
+ echo 'The following HTML chunk will get parsed, traverse, filtered, and manipulated:';
+ echo '' . htmlspecialchars($html) . '
';
+
+ echo 'Example 1
';
+ echo 'Add the attribute class="cell" to all <td> elements:';
+
+ echo '';
+
+ echo htmlspecialchars(
+ html5qp($html, 'td')
+ ->attr('class', 'cell')
+ ->top() // return to tag
+ ->innerHTML5() // get mark-up without . Use ->html5() to return a valid HTML document (Doctype and all)
+ );
+
+ echo '
';
+
+ echo 'Example 2
';
+ echo 'Use html5qp($html)->find(\'#row2 > td:nth-child(2)\')->text(); to display the contents of the second <td> in the second <tr>:
';
+
+ echo html5qp($html)
+ ->find('#row2 > td:nth-child(2)')
+ ->text();
+
+ echo '';
+
+ echo 'Example 3
';
+ echo 'Append another row to the HTML and output the results:';
+ echo '';
+
+ echo htmlspecialchars(
+ html5qp($html, 'tr:last')
+ ->after("\n\n\t\n\t\t| seven | \n\t\teight | \n\t\tnine | \n\t
")
+ ->top() // return to tag
+ ->innerHTML5() // get mark-up without . Use ->html5() to return a valid HTML document (Doctype and all)
+ );
+
+ echo '';
+
+ echo 'Basic XML Usage
';
+ echo 'The following XML will get parsed, traverse, filtered, and manipulated:';
+ echo '' . htmlspecialchars($xml) . '
';
-echo 'Example 1
';
-echo 'Add the attribute class="item" to all <desc> elements:';
+ echo 'Example 1
';
+ echo 'Add the attribute class="item" to all <desc> elements:';
-echo '';
+ echo '';
-echo htmlspecialchars(
- qp($xml, 'desc')
- ->attr('class', 'item')
- ->top() // return to the tag
- ->xml() // output a valid XML document. Use ->innerXML() to get the contents of instead.
-);
+ echo htmlspecialchars(
+ qp($xml, 'desc')
+ ->attr('class', 'item')
+ ->top() // return to the tag
+ ->xml() // output a valid XML document. Use ->innerXML() to get the contents of instead.
+ );
-echo '
';
+ echo '
';
-echo 'Example 2
';
-echo 'Use qp($xml)->find(\'categories > category:nth-child(3) desc\')->text(); to display the contents of the third <desc>:
';
+ echo 'Example 2
';
+ echo 'Use qp($xml)->find(\'categories > category:nth-child(3) desc\')->text(); to display the contents of the third <desc>:
';
-echo qp($xml)
- ->find('categories > category:nth-child(3) desc')
- ->text();
+ echo qp($xml)
+ ->find('categories > category:nth-child(3) desc')
+ ->text();
-echo '';
+ echo '';
-echo 'Example 3
';
-echo 'Append another category to the XML and output the results:';
-echo '';
+ echo 'Example 3
';
+ echo 'Append another category to the XML and output the results:';
+ echo '';
-echo htmlspecialchars(
- qp($xml, 'category:last')
- ->after("\n\n\t\n\t\tThe appended node...\n\t")
- ->top()
- ->xml()
-);
+ echo htmlspecialchars(
+ qp($xml, 'category:last')
+ ->after("\n\n\t\n\t\tThe appended node...\n\t")
+ ->top()
+ ->xml()
+ );
-echo '';
+ echo '
';
+} catch (\QueryPath\Exception $e) {
+ // Handle QueryPath exceptions
+ die($e->getMessage());
+}
diff --git a/examples/dirty_html.php b/examples/dirty_html.php
deleted file mode 100644
index 391c47bf..00000000
--- a/examples/dirty_html.php
+++ /dev/null
@@ -1,19 +0,0 @@
-Urban Dictionary Random Word Generator';
-
-$page = rand(0, 288);
-$qp = htmlqp('http://www.urbandictionary.com/?page=' . $page, '#home');
-
-$rand = rand(0, 7);
-print $qp->find('.word')->eq($rand)->text() . '
';
-print $qp->top()->find('.definition')->eq($rand)->text();
diff --git a/examples/docx.php b/examples/docx.php
deleted file mode 100644
index 6b872a29..00000000
--- a/examples/docx.php
+++ /dev/null
@@ -1,117 +0,0 @@
-branch();
- print format($qr->find('w|r:first'), 'w|r:first') . ' ';
- $qp->find('w|r:first');
- while ($qp->next('w|r')->html() != null) {
- $qr = $qp->branch();
- print format($qr->find('w|r'), 'w|r') . ' ';
- // print $qp->text();
- }
- print '';
-}
-
-/**
- *
- * @param QueryPath $qp
- * @param String $findSelector
- *
- * @return String
- */
-function format($qp, $findSelector = null)
-{
-
- // Create a new branch for printing later.
- $qr = $qp->branch();
-
- $text = "";
-
- $text = $qr->find($findSelector)->find('w|t')->text();
-
- $text = (checkUnderline($qp->branch())) ? '' . $text . '' : $text;
- $text = (checkBold($qp->branch())) ? '' . $text . '' : $text;
-
- return $text;
-}
-
-/**
- *
- * @param QueryPath $qp
- *
- * @return String
- */
-function checkBold($qp)
-{
- $qp->children("w|rPr");
-
- return ($qp->children('w|b')->html()) ? true : false;
-}
-
-/**
- *
- * @param QueryPath $qp
- *
- * @return String
- */
-function checkUnderline($qp)
-{
- $qp->children("w|rPr");
-
- return ($qp->children('w|u')->html()) ? true : false;
-}
-
-
-function docx2text($filename)
-{
- return readZippedXML($filename, "word/document.xml");
-}
-
-function readZippedXML($archiveFile, $dataFile)
-{
- if (! class_exists('ZipArchive', false)) {
- return "ZipArchive Class Doesn't Exist.";
- }
- // Create new ZIP archive
- $zip = new ZipArchive();
- // Open received archive file
- if (true === $zip->open($archiveFile)) {
- // If done, search for the data file in the archive
- if (($index = $zip->locateName($dataFile)) !== false) {
- // If found, read it to the string
- $data = $zip->getFromIndex($index);
- // Close archive file
- $zip->close();
- // Load XML from a string
- // Skip errors and warnings
- return $data;
- // $xml = DOMDocument::loadXML($data, LIBXML_NOENT | LIBXML_XINCLUDE | LIBXML_NOERROR | LIBXML_NOWARNING);
- // // Return data without XML formatting tags
- // return strip_tags($xml->saveXML());
- }
- $zip->close();
- }
-
- // In case of failure return empty string
- return $zip->getStatusString();
-}
diff --git a/examples/docx_document.xml b/examples/docx_document.xml
deleted file mode 100644
index fcf8614f..00000000
--- a/examples/docx_document.xml
+++ /dev/null
@@ -1,3914 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- I. Para
-
-
-
-
-
-
-
-
- :
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 1. In order to + infinitive (Hago ejercicos
-
-
-
-
-
-
-
-
-
- para
-
-
-
-
-
-
-
- rebajar) (Tomo la medicina
-
-
-
-
-
-
-
-
-
- para
-
-
-
-
-
-
-
- sentirme mejor)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 2. For = destined for, to be given to (Todo mi amor es
-
-
-
-
-
-
-
-
-
-
- para
-
-
-
-
-
-
-
-
- ti)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 3. For = by deadline, specified future time (La tarea es
-
-
-
-
-
-
-
-
-
- para
-
-
-
-
-
-
-
- el lunes)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- (Es
-
-
-
-
-
-
-
-
-
- para
-
-
-
-
-
-
-
- las cinco de la tarde)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 4. For = toward in the direction of (destination) (Sarah salió
-
-
-
-
-
-
-
-
-
-
- para
-
-
-
-
-
-
-
-
- España)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- (Manolo Salió
-
-
-
-
-
-
-
-
-
- para
-
-
-
-
-
-
-
- el campo)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 5. For = to be used for (purpose of an object) (La taza es
-
-
-
-
-
-
-
-
-
-
- para
-
-
-
-
-
-
-
-
- el café)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- (El dinero es
-
-
-
-
-
-
-
-
-
- para
-
-
-
-
-
-
-
- la matricula)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 6. For = as compared with others, in relation to others (
-
-
-
-
-
-
-
-
-
-
- Para
-
-
-
-
-
-
-
- mí, el español es fácil) (
-
-
-
-
-
-
-
-
-
- Para
-
-
-
-
-
-
-
- ser extranjero, habla muy bien el inglés)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 7. For = in the employ
-
-
-
-
-
-
-
- ment
-
-
-
-
-
-
-
- of (Trabajan
-
-
-
-
-
-
-
-
-
- para
-
-
-
-
-
-
-
- el gobierno) (Nosotros trabajamos
-
-
-
-
-
-
-
-
-
- para
-
-
-
-
-
-
-
- la universidad)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- II
-
-
-
-
-
-
-
-
-
- . Por:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 1. By means of (voy a España
-
-
-
-
-
-
-
-
-
- por
-
-
-
-
-
-
-
- avión)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 2. Through, along ( Camino por el parque) (Paseo
-
-
-
-
-
-
-
-
-
- por
-
-
-
-
-
-
-
- la ciudad)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 3. Duration of time, time of day, (Trabajo
-
-
-
-
-
-
-
-
-
- por
-
-
-
-
-
-
-
- la noche, trabajo
-
-
-
-
-
-
-
-
-
- por
-
-
-
-
-
-
-
- cinco horas)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- (Voy a Perú
-
-
-
-
-
-
-
-
-
- por
-
-
-
-
-
-
-
- un año)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 4. Because of, due to (Estoy nervioso
-
-
-
-
-
-
-
-
-
- por
-
-
-
-
-
-
-
- la entrevista) (Megan tiene tos
-
-
-
-
-
-
-
-
-
- por
-
-
-
-
-
-
-
- el resfriado)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 5. For = in Exchange for (Te cambio mi BMW
-
-
-
-
-
-
-
-
-
- por
-
-
-
-
-
-
-
- tu Mercedes)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- (Compré un CD
-
-
-
-
-
-
-
-
-
- por
-
-
-
-
-
-
-
- 10 dólares)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 6. For = for the sake of, on behalf of (Lo hago
-
-
-
-
-
-
-
-
-
-
- por
-
-
-
-
-
-
-
-
- ti) (Trabajo
-
-
-
-
-
-
-
-
-
-
- por
-
-
-
-
-
-
-
-
- los niños)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 7. To do something for someone else (a favor) (Esta semana, Juan va a trabajar
-
-
-
-
-
-
-
-
-
- por
-
-
-
-
-
-
-
- María)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Por is also used with some “fixed expressions” (Know them)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Por Dios
-
-
-
-
-
-
-
-
- (for heaven’s sake)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Por ejemplo
-
-
-
-
-
-
-
- (for example)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Por ahí, por allí
-
-
-
-
-
-
-
-
-
- (around there)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Por eso
-
-
-
-
-
-
-
-
- (that’s why)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Por cierto
-
-
-
-
-
-
-
-
- (by the way)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Por favor
-
-
-
-
-
-
-
- (please)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Por fin
-
-
-
-
-
-
-
- (finally)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Por lo general
-
-
-
-
-
-
-
- (in general, generally)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Por lo menos
-
-
-
-
-
-
-
- (at least)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Por primera/última vez
-
-
-
-
-
-
-
-
- (for the first/last time)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Por si acaso
-
-
-
-
-
-
-
- (just in case)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Por supuesto
-
-
-
-
-
-
-
- (of course)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Por todas partes
-
-
-
-
-
-
-
- (everywhere)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Por ahora
-
-
-
-
-
-
-
- (for now)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Por lo visto
-
-
-
-
-
-
-
- (apparently)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Por último
-
-
-
-
-
-
-
- (finally)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- A.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Por y Para 1-
-
-
-
-
-
-
-
-
- Un viaje a Costa Rica-Write por or para in the lines below, depending on the context.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Ellos hicieron un viaje a Costa Rica ______________
- (1)cinco semanas. Viajaron ______________(2) avión y cuando
- llegaron al país, tomaron unos taxis______________(3) ir a su
- hotel.____________(4) ser viajeros en un país extranjero,
- tenían mucho miedo al principio del viaje. Cuando llegaron al
- hotel, entraron _____________(5) las puertas principales y
- subieron ______________(6) el elevador para llegar a sus
- propias habitaciones. Estaban emocionados de ir a este nuevo
- país____________(7) conocer sus lugares turisticos.
- ____________(8) disfrutar del lugar, ellos salían a los discos
- ___________(9) las noches. Después de entrar en las
- discos___________(10) bailar, podían comprar bebidas caras.
- Casi siempre cuesta menos de dos dólares_____________(11) una
- cerveza. Pero hay muchas otras cosas que hicieron durante su
- visita. Ellos no fueron allá solamente ___________(12)
- festejar. Hay muchas cosas diferentes en Costa Rica que no hay
- en los Estados Unidos.__________(13) ejemplo, el paisaje es
- algo que no se puede encontrar en todas partes del mundo. La
- mayoría de los estudiantes gozaron su viaje y les
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- gustaría ir__________(14) Latinoamérica otra vez.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- B. Por y Para 2-
-
-
-
-
-
-
-
- Complete los siguientes diálogos y oraciones utilizando por
- o para:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 1. Carla, Kyra y Melissa salieron__________Pepe’s ayer. Van
- a Pepe’s _________coche y luego de ir a Pepe’s irán a pa
-
-
-
-
-
-
-
- s
-
-
-
-
-
-
-
- ear _________toda la ciudad. Va a ser una buena experiencia
- ________las tres.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 2. Mi hermano Miguel quiere estudiar __________ser doctor.
- ________eso, trabaja _________mi madre que es médica. Trabaja
- _________las mañanas y __________las tardes. Trabaja
- _________muchas horas
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- _________obtener más experiencia.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 3. ________lo general, Joel es una persona muy amable.
- ________ejemplo, la semana pasado nos trajo donas y galletas.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 4. El cuadro de Guernica fue pintado ________Pablo Picasso.
- Lo pintó _______representar las atrocidades de la guerra.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 5. Asia, Angie y Erica iban a dar un paseo __________el
- parque pero lo cancelaron _________el mal tiempo (bad weather)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- C.
-
-
-
-
-
-
-
-
-
-
-
-
- Pretérito e Imperfecto
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
- Gloria Fernández, the graduate student who spends many hours daily in front of the computer, wants to tell her friend Kathy about her visit to the doctor, so she sends her an e-mail. The main frame, however, is acting up, and some of the verbs have been deleted. Help Kathy complete the message by providing the missing verbs in the appropriate tense—either the preterite or the imperfect.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- correo_para_kathy@abc.edu
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Tema: Mi visita al doctor
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Querida Kathy:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Ayer fui al doctor porque no (sentirse) __________________
-
-
-
-
-
-
-
-
-
-
-
-
- 1
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- bien: me (doler) __________________
-
-
-
-
-
-
-
-
-
-
-
- 2
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- la cabeza y (tener) __________________
-
-
-
-
-
-
-
-
-
-
-
- 3
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- los ojos irritados. Primero, el doctor me (tomar)
- _______________
-
-
-
-
-
-
-
-
-
-
-
- 4
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- la temperatura, pero no (tener) ____________
-
-
-
-
-
-
-
-
-
-
-
- 5
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- fiebre. Después me (examinar) _______________
-
-
-
-
-
-
-
-
-
-
-
- 6
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- los ojos y me (preguntar) __________________
-
-
-
-
-
-
-
-
-
-
-
- 7
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- si (trabajar) __________________
-
-
-
-
-
-
-
-
-
-
-
- 8
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- mucho con la computadora; yo le (decir) __________________
-
-
-
-
-
-
-
-
-
-
-
-
- 9
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- que sí. Entonces él me (recomendar) __________________
-
-
-
-
-
-
-
-
-
-
-
-
- 10
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- que tomara
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- descansos y relajara
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- los ojos, porque las computadoras son malas para la vista.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- D.
-
-
-
-
-
-
-
-
-
-
-
-
- Unplanned/Unexpected Events
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Pamela is at work and her friend Susana arrives late. She has had a horrible morning. Pamela discusses Susana’s horrible morning with her coworkers during her lunch break.
-
-
-
-
-
-
-
-
-
-
- Following the model, use the cues and the verbs in parentheses to write complete sentences with
-
-
-
-
-
-
-
-
-
-
-
-
- se
-
-
-
-
-
-
-
-
-
-
- describing Susana’s actions.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- MODELO
-
-
-
-
-
-
-
-
-
-
- :
-
-
-
-
-
-
-
-
-
-
-
- When she tells them that Susana forgot her keys in her
- house, she says
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- (olvidar)
-
-
-
-
-
-
-
-
-
-
-
- A Susana se le olvidaron las llaves en su casa.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 1.
-
-
-
-
-
-
-
-
-
-
-
- When she tells them that Susana lost her cellular phone,
- she says:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- (perder)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 2.
-
-
-
-
-
-
-
-
-
-
-
- When she tells them that Susana ‘s car ran out of gas she
- says:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- (acabar)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 3.
-
-
-
-
-
-
-
-
-
-
-
- When she tells them that Susana’s glasses broke, she says:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- (romper)_______________________________________________________________________
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 4.
-
-
-
-
-
-
-
-
-
-
-
- When she tells them that Susana left her documents at home,
- she says:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- (quedar)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 5.
-
-
-
-
-
-
-
-
-
-
-
- When she tells them that Susana dropped her coffee, she
- says:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- (caer)
- _________________________________________________________________________
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- E
-
-
-
-
-
-
-
-
-
-
-
-
- . Los Adverbios-
-
-
-
-
-
-
-
-
-
-
- Change the adjectives in parentheses to adverbs.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- La doctora le dice a Pablo que todo va a ir bien:
-
-
-
-
-
-
-
-
-
- —
-
-
-
-
-
-
-
-
-
-
- Señor Ortiz, su salud está
-
-
-
-
-
-
-
-
-
-
-
- (perfecto) ________________
-
-
-
-
-
-
-
-
-
-
-
- 1
-
-
-
-
-
-
-
-
-
-
- bien. Su peso está bajando (rápida) ________________
-
-
-
-
-
-
-
-
-
-
-
- 2
-
-
-
-
-
-
-
-
-
-
- de 220 libras a 180 y parece que hace ejercicios
- (frecuente) ________________
-
-
-
-
-
-
-
-
-
-
-
- 3.
-
-
-
-
-
-
-
-
-
-
- Necesita una dieta (total) ________________
-
-
-
-
-
-
-
-
-
-
-
- 4
-
-
-
-
-
-
-
-
-
-
- baja en grasas para mantener su peso. Además, quiero que
- escuche mis consejos (cuidadoso) ________________
-
-
-
-
-
-
-
-
-
-
-
- 5
-
-
-
-
-
-
-
-
-
-
- y espero que vaya a casa más (tranquilo)
-
-
-
-
-
-
-
-
-
-
- _______________________________.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/examples/http-stream-xml-namespaces-and-linked-data/index.php b/examples/http-stream-xml-namespaces-and-linked-data/index.php
index 5bd51974..3cd3c128 100644
--- a/examples/http-stream-xml-namespaces-and-linked-data/index.php
+++ b/examples/http-stream-xml-namespaces-and-linked-data/index.php
@@ -50,28 +50,33 @@
// Create a stream context that will tell QueryPath how to load the file.
$context = stream_context_create($options);
-// Fetch the URL and select all rdf:Description elements.
-// (Note that | is the CSS 3 equiv of colons for namespacing.)
-// To add the context, we pass it in as an option to QueryPath.
-$qp = qp($url, 'rdf|Description', ['context' => $context]);
+try {
+ // Fetch the URL and select all rdf:Description elements.
+ // (Note that | is the CSS 3 equiv of colons for namespacing.)
+ // To add the context, we pass it in as an option to QueryPath.
+ $qp = qp($url, 'rdf|Description', ['context' => $context]);
-printf('There are %d descriptions in this record.
' . PHP_EOL, $qp->count());
+ printf('There are %d descriptions in this record.
' . PHP_EOL, $qp->count());
-// Here, we use foaf|* to select all elements in the FOAF namespace.
-printf('There are %d DBO items in this record.
' . PHP_EOL, $qp->top()->find('dbo|*')->count());
+ // Here, we use foaf|* to select all elements in the FOAF namespace.
+ printf('There are %d DBO items in this record.
' . PHP_EOL, $qp->top()->find('dbo|*')->count());
-// Standard pseudo-classes that are not HTML specific can be used on namespaced elements, too.
-echo 'About (RDFS): ' . $qp->top()->find('rdfs|label:first-of-type')->text() . '
' . PHP_EOL;
-echo 'About (FOAF): ' . $qp->top()->find('foaf|name:first-of-type')->text() . '
' . PHP_EOL;
+ // Standard pseudo-classes that are not HTML specific can be used on namespaced elements, too.
+ echo 'About (RDFS): ' . $qp->top()->find('rdfs|label:first-of-type')->text() . '
' . PHP_EOL;
+ echo 'About (FOAF): ' . $qp->top()->find('foaf|name:first-of-type')->text() . '
' . PHP_EOL;
-// Namespaced attributes can be retrieved using the same sort of delimiting.
-echo PHP_EOL . '
Comment:
' . PHP_EOL;
-echo $qp->top()->find('rdfs|comment[xml|lang="en"]')->text();
-echo '
' . PHP_EOL;
+ // Namespaced attributes can be retrieved using the same sort of delimiting.
+ echo PHP_EOL . '
Comment:
' . PHP_EOL;
+ echo $qp->top()->find('rdfs|comment[xml|lang="en"]')->text();
+ echo '
' . PHP_EOL;
-$qp->top();
+ $qp->top();
-echo PHP_EOL . '
Other Sites:
' . PHP_EOL;
-foreach ($qp as $item) {
- echo $item->attr('rdf:about') . '
' . PHP_EOL;
+ echo PHP_EOL . '
Other Sites:
' . PHP_EOL;
+ foreach ($qp as $item) {
+ echo $item->attr('rdf:about') . '
' . PHP_EOL;
+ }
+} catch (\QueryPath\Exception $e) {
+ // Handle QueryPath exceptions
+ die($e->getMessage());
}
diff --git a/examples/parsing-xml-from-url-and-dynamically-generating-html/index.php b/examples/parsing-xml-from-url-and-dynamically-generating-html/index.php
index 76443cfa..6ca1b7e0 100644
--- a/examples/parsing-xml-from-url-and-dynamically-generating-html/index.php
+++ b/examples/parsing-xml-from-url-and-dynamically-generating-html/index.php
@@ -2,8 +2,7 @@
/**
* Load XML from a URL, parse the data, and output into a HTML template
*
- * @author Original: Emily Brand
- * @author Updated by: Jake Jackson
+ * @author Emily Brand
* @license LGPL The GNU Lesser GPL (LGPL) or an MIT-like license.
*
* @internal IMPORTANT: if you don't trust the source of the data being loaded make sure to sanitize the output
@@ -26,30 +25,31 @@ function addClasses(string $name): string
return '' . htmlentities($name) . '
';
}
-// The document skeleton
-$qp = html5qp(__DIR__ . '/template.html', 'body');
+try {
+ // The document skeleton
+ $qp = html5qp(__DIR__ . '/template.html', 'body');
-$key = $_GET['key'] ?? '';
+ $key = $_GET['key'] ?? '';
-// Only display jQuery methods from these categories
-$categories = [
- 'traversing/tree-traversal' => 'Tree Traversal',
- 'selectors/child-filter-selectors' => 'Child Filter',
- 'selectors/attribute-selectors' => 'Attribute',
- 'selectors/content-filter-selector' => 'Content Filter',
- 'selectors/basic-filter-selectors' => 'Basic Filter',
- 'selectors/hierarchy-selectors' => 'Hierarchy',
- 'selectors/basic-css-selectors' => 'Basic',
- 'traversing/filtering' => 'Filtering',
- 'traversing/miscellaneous-traversal' => 'Miscellaneous Traversing',
- 'manipulation/dom-insertion-outside' => 'DOM Insertion, Outside',
- 'manipulation/dom-insertion-inside' => 'DOM Insertion, Inside',
- 'manipulation/style-properties' => 'Style Properties',
-];
+ // Only display jQuery methods from these categories
+ $categories = [
+ 'traversing/tree-traversal' => 'Tree Traversal',
+ 'selectors/child-filter-selectors' => 'Child Filter',
+ 'selectors/attribute-selectors' => 'Attribute',
+ 'selectors/content-filter-selector' => 'Content Filter',
+ 'selectors/basic-filter-selectors' => 'Basic Filter',
+ 'selectors/hierarchy-selectors' => 'Hierarchy',
+ 'selectors/basic-css-selectors' => 'Basic',
+ 'traversing/filtering' => 'Filtering',
+ 'traversing/miscellaneous-traversal' => 'Miscellaneous Traversing',
+ 'manipulation/dom-insertion-outside' => 'DOM Insertion, Outside',
+ 'manipulation/dom-insertion-inside' => 'DOM Insertion, Inside',
+ 'manipulation/style-properties' => 'Style Properties',
+ ];
+
+ $jquery = [];
-$jquery = [];
-try {
// Search through the xml file to find all entries of jQuery entities
foreach (qp('https://api.jquery.com/resources/api.xml', 'entry') as $entry) {
foreach ($entry->find('category') as $item) {
@@ -89,5 +89,6 @@ function addClasses(string $name): string
// Write the document
$qp->writeHTML5();
} catch (\QueryPath\Exception $e) {
+ // Handle QueryPath exceptions
die($e->getMessage());
}
diff --git a/examples/remote-filter-and-retrieval/index.php b/examples/remote-filter-and-retrieval/index.php
new file mode 100644
index 00000000..44b4205f
--- /dev/null
+++ b/examples/remote-filter-and-retrieval/index.php
@@ -0,0 +1,46 @@
+Urban Dictionary Random Word Generator';
+
+try {
+ $page = random_int(0, 288);
+ $word = random_int(0, 7);
+
+ // Load a random page from the Urban Dictionary
+ $qp = html5qp('https://www.urbandictionary.com/?page=' . $page);
+
+ // Select a random word/definition out of the 7 shown on the loaded page
+ // Get the Word
+ printf(
+ 'Word: %s
',
+ $qp->find('.word')
+ ->eq($word)
+ ->text()
+ );
+
+ $qp->top();
+
+ // Get the definition
+ echo 'Definition: ' .
+ $qp->find('.meaning')
+ ->eq($word)
+ ->text();
+} catch (\QueryPath\Exception $e) {
+ // Handle QueryPath exceptions
+ die($e->getMessage());
+} catch (Exception $e) {
+ // Handle the random_int() exception
+ die($e->getMessage());
+}
From 5aa7dcee52fb7524e835c6ee73f469e61ab44ef9 Mon Sep 17 00:00:00 2001
From: Jake Jackson
Date: Fri, 16 Dec 2022 09:15:23 +1100
Subject: [PATCH 05/14] Continue refactoring examples
---
examples/create-html-document/index.php | 58 +++++++++++++++++++
examples/create-xml-document/index.php | 52 +++++++++++++++++
examples/fetch_rss.php | 45 --------------
examples/filtering-by-text-content/index.php | 50 ++++++++++++++++
examples/html.php | 56 ------------------
examples/matching_text_content.php | 51 ----------------
examples/parsing-rss-feed/index.php | 51 ++++++++++++++++
.../remote-filter-and-retrieval/index.php | 3 -
examples/xml.php | 54 -----------------
9 files changed, 211 insertions(+), 209 deletions(-)
create mode 100644 examples/create-html-document/index.php
create mode 100644 examples/create-xml-document/index.php
delete mode 100644 examples/fetch_rss.php
create mode 100644 examples/filtering-by-text-content/index.php
delete mode 100644 examples/html.php
delete mode 100644 examples/matching_text_content.php
create mode 100644 examples/parsing-rss-feed/index.php
delete mode 100644 examples/xml.php
diff --git a/examples/create-html-document/index.php b/examples/create-html-document/index.php
new file mode 100644
index 00000000..60b4d179
--- /dev/null
+++ b/examples/create-html-document/index.php
@@ -0,0 +1,58 @@
+
+ * @license LGPL The GNU Lesser GPL (LGPL) or an MIT-like license.
+ */
+
+require_once __DIR__ . '/../../vendor/autoload.php';
+
+try {
+ // Begin with an HTML5 stub document and navigate to the title.
+ html5qp(\QueryPath\QueryPath::HTML5_STUB, 'title')
+ // Add some text to the title
+ ->text('Example of QueryPath.')
+ // Now look for the element
+ ->top('body')
+ // Inside the body, add a title and paragraph.
+ ->append('This is a test page
Test text
')
+ // Now we select the paragraph we just created inside the body
+ ->children('p')
+ // Add a 'class="some-class"' attribute to the paragraph
+ ->attr('class', 'some-class')
+ // And add a style attribute, too, setting the background color.
+ ->css('background-color', '#eee')
+ // Now go back to the paragraph again
+ ->parent()
+ // Before the paragraph and the title, add an empty table.
+ ->prepend('')
+ // Now let's go to the table...
+ ->top('#my-table')
+ // Add a couple of empty rows
+ ->append('|
')
+ // select the rows (both at once)
+ ->children()
+ // Add a CSS class to both rows
+ ->addClass('table-row')
+ // Now just get the first row (at position 0)
+ ->eq(0)
+ // Add a table header in the first row
+ ->append('This is the header | ')
+ // Now go to the next row
+ ->next()
+ // Add some data to this row
+ ->append('This is the data | ')
+ // Write it all out as HTML
+ ->writeHTML5();
+} catch (\QueryPath\Exception $e) {
+ die($e->getMessage());
+}
\ No newline at end of file
diff --git a/examples/create-xml-document/index.php b/examples/create-xml-document/index.php
new file mode 100644
index 00000000..2407e604
--- /dev/null
+++ b/examples/create-xml-document/index.php
@@ -0,0 +1,52 @@
+`
+ *
+ * @author M Butcher
+ * @license LGPL The GNU Lesser GPL (LGPL) or an MIT-like license.
+ */
+
+require_once __DIR__ . '/../../vendor/autoload.php';
+
+/*
+ * Create a new XML document wrapped in a QueryPath.
+ * By default, it will point to the root element ``
+ */
+
+try {
+ echo qp('')
+ // Add a new last name inside of author.
+ ->append('Wiseman')
+ // Select all of the children of . In this case,
+ // that is
+ ->children()
+ // Oh, wait... we wanted last name to be inside of a
+ // element. Use wrap to wrap the current element in something:
+ ->wrap('')
+ // And before last name, we want to add first name.
+ ->before('')
+ // Select first name
+ ->prev()
+ // Set the text of first name
+ ->text('Simon')
+ // And then after first name, add the patronymic
+ ->after('J.')
+ // Now go back to the root element, the top of the document.
+ ->top()
+ // Add another tag -- origin.
+ ->append('Australia')
+ // turn the QueryPath contents back into a string. Since we are
+ // at the top of the document, the whole document will be converted
+ // to a string.
+ ->xml();
+} catch (\QueryPath\Exception $e) {
+ die($e->getMessage());
+}
diff --git a/examples/fetch_rss.php b/examples/fetch_rss.php
deleted file mode 100644
index 3e9243da..00000000
--- a/examples/fetch_rss.php
+++ /dev/null
@@ -1,45 +0,0 @@
-
- * @license LGPL The GNU Lesser GPL (LGPL) or an MIT-like license.
- */
-require_once __DIR__ . '/../vendor/autoload.php';
-
-// The URL of the remote RSS feed.
-$remote = 'http://querypath.org/aggregator/rss/2/rss.xml';
-
-// We will write the results into this document.
-$out = qp(QueryPath::HTML_STUB, 'title')
- ->text('RSS Titles')
- ->top()
- ->find('body')
- ->append('')
- ->children('ul');
-
-// Load the remote document and loop through all of the items.
-foreach (qp($remote, 'channel>item') as $item) {
- // Get title and link.
- $title = $item->find('title')->text();
- $link = $item->next('link')->text();
-
- // Do a little string building.
- $bullet = '' . $title . '';
-
- // Add it to the output document.
- $out->append($bullet);
-}
-
-// Write the results.
-$out->writeHTML();
diff --git a/examples/filtering-by-text-content/index.php b/examples/filtering-by-text-content/index.php
new file mode 100644
index 00000000..bb4dbde9
--- /dev/null
+++ b/examples/filtering-by-text-content/index.php
@@ -0,0 +1,50 @@
+
+ * @license LGPL The GNU Lesser GPL (LGPL) or an MIT-like license.
+ */
+
+require_once __DIR__ . '/../../vendor/autoload.php';
+
+try {
+ $qp = html5qp('https://www.php.net');
+
+ echo 'Filtering Content
';
+ echo 'PHP Releases
';
+
+ /* Get any posts containing the word 'Release' */
+ echo $qp->find('h2.newstitle a:contains(Release)')
+ ->textImplode('
' . PHP_EOL);
+
+ echo 'PHP news in the past 30 days...
';
+
+ echo $qp->find('header.title')
+ ->filterCallback(function ($index, $item) {
+ /*
+ * Returns TRUE to keep current $item in matches, or FALSE to remove
+ *
+ * $item is a DOMNode (actually, a DOMElement). So if we wanted to do QueryPath
+ * manipulations on it, you can pass it to html5qp()
+ */
+
+ /* Get the current post datetime */
+ $datetime = new DateTimeImmutable(html5qp($item, 'time')->attr('datetime'));
+
+ /* Keep any posts less than 30 days old */
+ return $datetime > (new DateTimeImmutable('-30 days'));
+ })
+ ->find('a')
+ ->textImplode('
' . PHP_EOL);
+} catch (\QueryPath\Exception $e) {
+ die($e->getMessage());
+}
\ No newline at end of file
diff --git a/examples/html.php b/examples/html.php
deleted file mode 100644
index 6d4282ed..00000000
--- a/examples/html.php
+++ /dev/null
@@ -1,56 +0,0 @@
-
- * @license LGPL The GNU Lesser GPL (LGPL) or an MIT-like license.
- */
-
-require_once __DIR__ . '/../vendor/autoload.php';
-
-// Begin with an HTML stub document (XHTML, actually), and navigate to the title.
-qp(QueryPath::HTML_STUB, 'title')
- // Add some text to the title
- ->text('Example of QueryPath.')
- // Now look for the element
- ->top('body')
- // Inside the body, add a title and paragraph.
- ->append('This is a test page
Test text
')
- // Now we select the paragraph we just created inside the body
- ->children('p')
- // Add a 'class="some-class"' attribute to the paragraph
- ->attr('class', 'some-class')
- // And add a style attribute, too, setting the background color.
- ->css('background-color', '#eee')
- // Now go back to the paragraph again
- ->parent()
- // Before the paragraph and the title, add an empty table.
- ->prepend('')
- // Now let's go to the table...
- ->top('#my-table')
- // Add a couple of empty rows
- ->append('|
')
- // select the rows (both at once)
- ->children()
- // Add a CSS class to both rows
- ->addClass('table-row')
- // Now just get the first row (at position 0)
- ->eq(0)
- // Add a table header in the first row
- ->append('This is the header | ')
- // Now go to the next row
- ->next()
- // Add some data to this row
- ->append('This is the data | ')
- // Write it all out as HTML
- ->writeHTML();
diff --git a/examples/matching_text_content.php b/examples/matching_text_content.php
deleted file mode 100644
index 3fd6fe20..00000000
--- a/examples/matching_text_content.php
+++ /dev/null
@@ -1,51 +0,0 @@
-
- * @license LGPL The GNU Lesser GPL (LGPL) or an MIT-like license.
- */
-
-/** Include QueryPath. */
-require_once __DIR__ . '/../vendor/autoload.php';
-
-/**
- * Check if the string 'Release' is in the text content of any matched nodes.
- *
- * Returns TRUE if the text is found, FALSE otherwise. Anytime a filter callback
- * returns FALSE, QueryPath will remove it from the matches.
- *
- * Note that $item is a DOMNode (actually, a DOMElement). So if we wanted to do QueryPath
- * manipulations on it, we could wrap it in a `qp()`.
- */
-function exampleCallback($index, $item)
-{
- $text = qp($item)->text();
-
- return strpos($text, 'Release') !== false;
-}
-
-/*
- * This is the QueryPath call.
- *
- * First we fetch the remote page, parse it, and grab just the `a` tags inside of the summary.
- * Then we filter the results through our callback.
- * Finally, we fetch all of the matching text and print it.
- *
- * NOTE: If you are using PHP 5.3, you can define the callback inline instead of separating it
- * into a stand-alone function.
- */
-print htmlqp('http://php.net/', 'h1.summary a')
- ->filterCallback('exampleCallback')
- ->textImplode(PHP_EOL);
diff --git a/examples/parsing-rss-feed/index.php b/examples/parsing-rss-feed/index.php
new file mode 100644
index 00000000..13014280
--- /dev/null
+++ b/examples/parsing-rss-feed/index.php
@@ -0,0 +1,51 @@
+
+ * @license LGPL The GNU Lesser GPL (LGPL) or an MIT-like license.
+ */
+require_once __DIR__ . '/../../vendor/autoload.php';
+
+// The URL of the remote RSS feed.
+$remote = 'https://en.wikipedia.org/w/index.php?title=Special:NewPages&feed=rss';
+
+try {
+ // We will write the results into this document.
+ $qp = html5qp(\QueryPath\QueryPath::HTML5_STUB, 'title')
+ ->text('New Wikipedia Pages')
+ ->top('body')
+ ->append('New Wikipedia Pages
')
+ ->append('')
+ ->children('ul');
+
+ // Load the remote document and loop through all the items.
+ foreach (qp($remote, 'channel>item') as $item) {
+ // Get title and link.
+ $title = $item->find('title')->text();
+ $link = $item->find('link')->text();
+
+ $list = html5qp('', 'li')
+ ->append('')
+ ->find('a')
+ ->attr('href', $link)
+ ->text($title);
+
+ // Add it to the output document.
+ $qp->append($list->top()->innerHTML5());
+ }
+
+ // Write the results.
+ $qp->writeHTML5();
+} catch (Exception $e) {
+ die($e->getMessage());
+}
\ No newline at end of file
diff --git a/examples/remote-filter-and-retrieval/index.php b/examples/remote-filter-and-retrieval/index.php
index 44b4205f..2842e0c3 100644
--- a/examples/remote-filter-and-retrieval/index.php
+++ b/examples/remote-filter-and-retrieval/index.php
@@ -5,10 +5,7 @@
* @author Emily Brand
* @license LGPL The GNU Lesser GPL (LGPL) or an MIT-like license.
*
- * @internal IMPORTANT: if you don't trust the source of the data being loaded make sure to sanitize the output
- *
* @see https://www.urbandictionary.com/
- * @see https://github.com/symfony/html-sanitizer
*/
require_once __DIR__ . '/../../vendor/autoload.php';
diff --git a/examples/xml.php b/examples/xml.php
deleted file mode 100644
index 36448ccf..00000000
--- a/examples/xml.php
+++ /dev/null
@@ -1,54 +0,0 @@
-
- * xml version="1.0"?>
- *
- * (A space was inserted above to prevent the documentation renderer from
- * misinterpreting it.)
- *
- * @author M Butcher
- * @license LGPL The GNU Lesser GPL (LGPL) or an MIT-like license.
- */
-
-require_once __DIR__ . '/../vendor/autoload.php';
-
-// Create a new XML document wrapped in a QueryPath.
-// By default, it will point to the root element,
-//
-$record = qp('')
- // Add a new last name inside of author.
- ->append('Dostoyevsky')
- // Select all of the children of . In this case,
- // that is
- ->children()
- // Oh, wait... we wanted last name to be inside of a
- // element. Use wrap to wrap the current element in something:
- ->wrap('')
- // And before last name, we want to add first name.
- ->before('')
- // Select first name
- ->prev()
- // Set the text of first name
- ->text('Fyodor')
- // And then after first name, add the patronymic
- ->after('Fyodorovich')
- // Now go back to the root element, the top of the document.
- ->top()
- // Add another tag -- origin.
- ->append('Russia')
- // turn the QueryPath contents back into a string. Since we are
- // at the top of the document, the whole document will be converted
- // to a string.
- ->xml();
-
-// Print our results.
-print $record;
From 5bb8097e4fe493673698be53a95773791b132b13 Mon Sep 17 00:00:00 2001
From: Jake Jackson
Date: Fri, 1 Dec 2023 17:40:08 +1100
Subject: [PATCH 06/14] Add missing extensions to composer dependencies.
---
composer.json | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/composer.json b/composer.json
index 5fc1970c..b15ac0be 100644
--- a/composer.json
+++ b/composer.json
@@ -24,7 +24,9 @@
],
"require": {
"php": "^7.1 || ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0",
- "masterminds/html5": "^2.0"
+ "masterminds/html5": "^2.0",
+ "ext-dom": "*",
+ "ext-simplexml": "*"
},
"autoload": {
"psr-4": {
From 635c44d4d57c7c655aaed0db8b24fe1e67c55bbe Mon Sep 17 00:00:00 2001
From: Jake Jackson
Date: Fri, 1 Dec 2023 23:15:07 +1100
Subject: [PATCH 07/14] Update musicbrainz example
---
.../curl-xml-filter-and-retrival/index.php | 103 ++++++++++++++++++
examples/musicbrainz.php | 40 -------
2 files changed, 103 insertions(+), 40 deletions(-)
create mode 100644 examples/curl-xml-filter-and-retrival/index.php
delete mode 100644 examples/musicbrainz.php
diff --git a/examples/curl-xml-filter-and-retrival/index.php b/examples/curl-xml-filter-and-retrival/index.php
new file mode 100644
index 00000000..449a01d6
--- /dev/null
+++ b/examples/curl-xml-filter-and-retrival/index.php
@@ -0,0 +1,103 @@
+
+ * @license LGPL The GNU Lesser GPL (LGPL) or an MIT-like license.
+ * @see https://musicbrainz.org
+ */
+require_once __DIR__ . '/../../vendor/autoload.php';
+
+$artist_name = 'U2';
+$artist_url = 'https://musicbrainz.org/ws/2/artist/?query=' . rawurlencode($artist_name);
+$album_url = 'https://musicbrainz.org/ws/2/release-group?&artist=';
+
+try {
+ /* Make a remote cURL request to get the XML */
+ $artist_xml = get($artist_url);
+
+ /* Load the XML into QueryPath and select the first artist in the list */
+ $artist = qp($artist_xml, 'artist:first');
+
+ /* Check if nothing in the XML matched the selector */
+ if (count($artist) === 0) {
+ echo 'No results found
';
+ exit;
+ }
+
+ /* Get direct children of "artist", filter by the "name" tag, and output the text */
+ echo sprintf('Albums by %s
', $artist->children('name')->text());
+
+ /* Get the unique albums listed for this artist */
+ $id = $artist->attr('id');
+ $album_url .= rawurlencode($id);
+ $albums_xml = get($album_url);
+
+ /* Load the XML into QueryPath */
+ $albums = qp($albums_xml, 'release-group');
+
+ /* Loop over the results */
+ echo '';
+ foreach ($albums as $album) {
+ echo sprintf(
+ '- %1$s (%2$s)
',
+ $album->find('title')->text(),
+ $album->find('first-release-date')->text()
+ );
+ }
+ echo '
';
+
+ /* The XML retrieved via cURL and fed into QueryPath */
+ echo 'XML
';
+
+ echo 'Artists
';
+ echo sprintf('%s', $artist_url);
+ echo '';
+ echo htmlspecialchars($artist->top()->xml());
+ echo '
';
+
+ echo 'Albums
';
+ echo sprintf('%s', $album_url);
+ echo '';
+ echo htmlspecialchars($albums->top()->xml());
+ echo '
';
+
+} catch (Exception $e) {
+ echo $e->getMessage();
+}
+
+/**
+ * Make a GET request using cURL and return the results
+ *
+ * @param string $url
+ * @return string
+ */
+function get($url)
+{
+ $defaults = array(
+ CURLOPT_URL => $url,
+ CURLOPT_HEADER => 0,
+ CURLOPT_RETURNTRANSFER => true,
+ CURLOPT_FAILONERROR => true,
+ CURLOPT_FOLLOWLOCATION => true,
+ CURLOPT_USERAGENT => 'QueryPath/3.0'
+ );
+
+ $ch = curl_init();
+
+ curl_setopt_array($ch, $defaults);
+
+ if (!$result = curl_exec($ch)) {
+ throw new RuntimeException(curl_error($ch));
+ }
+
+ curl_close($ch);
+
+ return $result;
+}
\ No newline at end of file
diff --git a/examples/musicbrainz.php b/examples/musicbrainz.php
deleted file mode 100644
index a334e43e..00000000
--- a/examples/musicbrainz.php
+++ /dev/null
@@ -1,40 +0,0 @@
-
- * @license LGPL The GNU Lesser GPL (LGPL) or an MIT-like license.
- * @see http://musicbrainz.org
- */
-require_once __DIR__ . '/../vendor/autoload.php';
-
-$artist_url = 'http://musicbrainz.org/ws/1/artist/?type=xml&name=u2';
-$album_url = 'http://musicbrainz.org/ws/1/release/?type=xml&artistid=';
-try {
- $artist = qp($artist_url, 'artist:first');
- if ($artist->size() > 0) {
- $id = $artist->attr('id');
- print 'The best match we found was for ' . $artist->children('name')->text() . PHP_EOL;
- print '
Artist ID: ' . $id . PHP_EOL;
- print '
Albums for this artist' . PHP_EOL;
- print '
' . $album_url . '
';
- $albums = qp($album_url . urlencode($id))->writeXML();
-
- foreach ($albums as $album) {
- print $album->find('title')->text() . PHP_EOL;
- // Fixme: Label is broken. See Drupal QueryPath module.
- print '(' . $album->next('label')->text() . ')' . PHP_EOL;
- }
- }
-} catch (Exception $e) {
- print $e->getMessage();
-}
From f4cdeffb9d13a77ca11f57d322a747b42262e2de Mon Sep 17 00:00:00 2001
From: Jake Jackson
Date: Fri, 1 Dec 2023 23:15:25 +1100
Subject: [PATCH 08/14] Improve typehinting
---
src/DOMQuery.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/DOMQuery.php b/src/DOMQuery.php
index ae6ace88..42603ba6 100644
--- a/src/DOMQuery.php
+++ b/src/DOMQuery.php
@@ -1594,7 +1594,7 @@ public function __call($name, $arguments)
/**
* Get an iterator for the matches in this object.
*
- * @return Traversable
+ * @return Traversable
* Returns an iterator.
*/
public function getIterator(): Traversable
From cc7dc2b6b6753e8ecaa011747cb83ea1c2978fef Mon Sep 17 00:00:00 2001
From: Jake Jackson
Date: Fri, 12 Apr 2024 17:10:47 +1000
Subject: [PATCH 09/14] Fix typehint in docblock
---
src/DOMQuery.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/DOMQuery.php b/src/DOMQuery.php
index 42603ba6..8231fa18 100644
--- a/src/DOMQuery.php
+++ b/src/DOMQuery.php
@@ -1216,8 +1216,8 @@ public function xhtml($markup = null)
* In getter mode, the first element wrapped by this DOMNode object will be
* converted to an XML string and returned.
*
- * @param string|null $markup
- * A string containing XML data.
+ * @param string|true|null $markup
+ * A string containing XML data. If true is passed, the XML declaration will be omitted.
*
* @return DOMQuery|string|null
* If markup is passed in, a DOMQuery is returned. If no markup is passed
From d9e304da9ad813e4600e596f215ceced699f3bde Mon Sep 17 00:00:00 2001
From: Jake Jackson
Date: Fri, 12 Apr 2024 17:26:58 +1000
Subject: [PATCH 10/14] Refine the basic manipulation example
---
.../index.php | 103 +++++++++++++++---
1 file changed, 89 insertions(+), 14 deletions(-)
diff --git a/examples/basic-manipulation-filter-and-retrieval/index.php b/examples/basic-manipulation-filter-and-retrieval/index.php
index 48983897..caf3c4a8 100644
--- a/examples/basic-manipulation-filter-and-retrieval/index.php
+++ b/examples/basic-manipulation-filter-and-retrieval/index.php
@@ -53,35 +53,78 @@
echo 'Example 1
';
echo 'Add the attribute class="cell" to all <td> elements:';
+ echo '
+<?php
+
+echo html5qp($html, "td")
+->attr("class", "cell")
+->top("table")
+->html()
+
';
+
+ echo 'This will output the following HTML:';
+
+ echo '';
+
+ echo htmlspecialchars(
+ html5qp($html, 'td')
+ ->attr('class', 'cell')
+ ->top('table') // jump back up the DOM to the table
+ ->html() // get get HTML of the table
+ );
+
+ echo '
';
+
+ echo 'If you want to output a valid HTML document, use top() without an argument:';
+
echo '';
echo htmlspecialchars(
html5qp($html, 'td')
->attr('class', 'cell')
- ->top() // return to tag
- ->innerHTML5() // get mark-up without . Use ->html5() to return a valid HTML document (Doctype and all)
+ ->top()
+ ->html()
);
echo '
';
echo 'Example 2
';
- echo 'Use html5qp($html)->find(\'#row2 > td:nth-child(2)\')->text(); to display the contents of the second <td> in the second <tr>:
';
+ echo 'Find and output the text of the second cell in the second row of the table:';
- echo html5qp($html)
+ $text = html5qp($html)
->find('#row2 > td:nth-child(2)')
->text();
- echo '';
+ echo '
+<?php
+
+echo html5qp($html)
+->find("#row2 > td:nth-child(2)")
+->text();
+
+// Result: '. $text. '
+
';
echo 'Example 3
';
- echo 'Append another row to the HTML and output the results:';
+ echo 'Append an additional row at the end of the table:';
+ echo '
+<?php
+
+echo html5qp($html, "td")
+->after("<tr><td>seven</td><td>eight</td><td>nine</td></tr>")
+->top("table")
+->html()
+
';
+
+ echo 'This will output the following HTML:';
+
echo '';
echo htmlspecialchars(
html5qp($html, 'tr:last')
->after("\n\n\t\n\t\t| seven | \n\t\teight | \n\t\tnine | \n\t
")
- ->top() // return to tag
- ->innerHTML5() // get mark-up without . Use ->html5() to return a valid HTML document (Doctype and all)
+ ->top("table")
+ ->html()
);
echo '';
@@ -93,33 +136,65 @@
echo 'Example 1
';
echo 'Add the attribute class="item" to all <desc> elements:';
+ echo '
+<?php
+
+echo qp($xml, "desc")
+->attr("class", "item)
+->top() // return to the <categories> tag
+->xml(); // output a valid XML document.
+
';
+
+ echo 'This will output the following XML:';
+
echo '';
echo htmlspecialchars(
qp($xml, 'desc')
->attr('class', 'item')
->top() // return to the tag
- ->xml() // output a valid XML document. Use ->innerXML() to get the contents of instead.
+ ->xml() // output a valid XML document
);
echo '
';
+ echo 'You can omit the XML declaration by setting the first argument to true: ->xml(true).';
+
echo 'Example 2
';
- echo 'Use qp($xml)->find(\'categories > category:nth-child(3) desc\')->text(); to display the contents of the third <desc>:
';
+ echo 'Find and output the text of the third <desc> tag:';
- echo qp($xml)
+ $text = qp($xml)
->find('categories > category:nth-child(3) desc')
->text();
- echo '';
+ echo '
+<?php
+
+echo qp($xml)
+->find("categories > category:nth-child(3) desc")
+->text();
+
+ // Result: '.$text.'
+
';
echo 'Example 3
';
- echo 'Append another category to the XML and output the results:';
+ echo 'Append a category at the end of the group:';
+ echo '
+<?php
+
+echo qp($xml, "category:last")
+->after("<category name=\'Appended\'><desc>The appended node...</desc></category>")
+->top()
+->xml()
+
';
+
+ echo 'This will output the following HTML:';
+
echo '';
echo htmlspecialchars(
qp($xml, 'category:last')
- ->after("\n\n\t\n\t\tThe appended node...\n\t")
+ ->after("\n\n\t\n\t\tThe appended node...\n\t")
->top()
->xml()
);
From da3b193afa7946ffbeec7682e30e3b21fcbdc77d Mon Sep 17 00:00:00 2001
From: Jake Jackson
Date: Fri, 12 Apr 2024 17:27:20 +1000
Subject: [PATCH 11/14] Fix lint issues
---
examples/create-html-document/index.php | 2 +-
examples/curl-xml-filter-and-retrival/index.php | 2 +-
examples/filtering-by-text-content/index.php | 2 +-
examples/parsing-rss-feed/index.php | 2 +-
4 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/examples/create-html-document/index.php b/examples/create-html-document/index.php
index 60b4d179..f36978f8 100644
--- a/examples/create-html-document/index.php
+++ b/examples/create-html-document/index.php
@@ -55,4 +55,4 @@
->writeHTML5();
} catch (\QueryPath\Exception $e) {
die($e->getMessage());
-}
\ No newline at end of file
+}
diff --git a/examples/curl-xml-filter-and-retrival/index.php b/examples/curl-xml-filter-and-retrival/index.php
index 449a01d6..b8eb23dc 100644
--- a/examples/curl-xml-filter-and-retrival/index.php
+++ b/examples/curl-xml-filter-and-retrival/index.php
@@ -100,4 +100,4 @@ function get($url)
curl_close($ch);
return $result;
-}
\ No newline at end of file
+}
diff --git a/examples/filtering-by-text-content/index.php b/examples/filtering-by-text-content/index.php
index bb4dbde9..895f8ca6 100644
--- a/examples/filtering-by-text-content/index.php
+++ b/examples/filtering-by-text-content/index.php
@@ -47,4 +47,4 @@
->textImplode('
' . PHP_EOL);
} catch (\QueryPath\Exception $e) {
die($e->getMessage());
-}
\ No newline at end of file
+}
diff --git a/examples/parsing-rss-feed/index.php b/examples/parsing-rss-feed/index.php
index 13014280..a0adea93 100644
--- a/examples/parsing-rss-feed/index.php
+++ b/examples/parsing-rss-feed/index.php
@@ -48,4 +48,4 @@
$qp->writeHTML5();
} catch (Exception $e) {
die($e->getMessage());
-}
\ No newline at end of file
+}
From b4b2bd176ad36977b8838801065be68e6094327e Mon Sep 17 00:00:00 2001
From: Jake Jackson
Date: Fri, 12 Apr 2024 17:43:18 +1000
Subject: [PATCH 12/14] Improve intro for Docx parser
---
.../basic-docx-parser/{test.docx => example.docx} | Bin
.../basic-docx-parser/{output.xml => example.xml} | 0
examples/basic-docx-parser/index.php | 8 +++++++-
3 files changed, 7 insertions(+), 1 deletion(-)
rename examples/basic-docx-parser/{test.docx => example.docx} (100%)
rename examples/basic-docx-parser/{output.xml => example.xml} (100%)
diff --git a/examples/basic-docx-parser/test.docx b/examples/basic-docx-parser/example.docx
similarity index 100%
rename from examples/basic-docx-parser/test.docx
rename to examples/basic-docx-parser/example.docx
diff --git a/examples/basic-docx-parser/output.xml b/examples/basic-docx-parser/example.xml
similarity index 100%
rename from examples/basic-docx-parser/output.xml
rename to examples/basic-docx-parser/example.xml
diff --git a/examples/basic-docx-parser/index.php b/examples/basic-docx-parser/index.php
index f4339d08..88fe1b77 100644
--- a/examples/basic-docx-parser/index.php
+++ b/examples/basic-docx-parser/index.php
@@ -16,9 +16,15 @@
require_once __DIR__ . '/../../vendor/autoload.php';
+echo 'Create a Basic Docx Parser
';
+
+echo 'This example parses a .docx file, traverse the nodes and displays the text with basic formatting. The contents of the example.xml file is the data extracted from the .docx file that QueryPath processes.
';
+
+echo 'Content of example.docx file...
';
+
try {
// Try load the test.docx file, parse for text nodes and output with basic formatting
- foreach (qp(docx2text('test.docx'), 'w|p') as $qp) {
+ foreach (qp(docx2text('example.docx'), 'w|p') as $qp) {
/** @var $qp DOMQuery */
/** @var $qr DOMQuery */
foreach ($qp->find('w|r') as $qr) {
From c5f1174103b20b9409ea34cfaaafceccc0648546 Mon Sep 17 00:00:00 2001
From: Jake Jackson
Date: Fri, 12 Apr 2024 18:01:46 +1000
Subject: [PATCH 13/14] Improve documentation for specific commands
---
.../index.php | 34 ++---
examples/create-html-document/index.php | 128 +++++++++++++-----
2 files changed, 107 insertions(+), 55 deletions(-)
diff --git a/examples/basic-manipulation-filter-and-retrieval/index.php b/examples/basic-manipulation-filter-and-retrieval/index.php
index caf3c4a8..8ca19baf 100644
--- a/examples/basic-manipulation-filter-and-retrieval/index.php
+++ b/examples/basic-manipulation-filter-and-retrieval/index.php
@@ -53,12 +53,11 @@
echo 'Example 1
';
echo 'Add the attribute class="cell" to all <td> elements:';
- echo '
-<?php
+ echo '<?php
echo html5qp($html, "td")
->attr("class", "cell")
-->top("table")
+->parents("table")
->html()
';
@@ -69,13 +68,13 @@
echo htmlspecialchars(
html5qp($html, 'td')
->attr('class', 'cell')
- ->top('table') // jump back up the DOM to the table
- ->html() // get get HTML of the table
+ ->parents('table') // traverse up the DOM until we match the table
+ ->html() // get the HTML of the table
);
echo '
';
- echo 'If you want to output a valid HTML document, use top() without an argument:';
+ echo 'If you want to output a valid HTML document, replace parents(\'table\') with top():';
echo '';
@@ -95,8 +94,7 @@
->find('#row2 > td:nth-child(2)')
->text();
- echo '
-<?php
+ echo '<?php
echo html5qp($html)
->find("#row2 > td:nth-child(2)")
@@ -107,12 +105,11 @@
echo 'Example 3
';
echo 'Append an additional row at the end of the table:';
- echo '
-<?php
+ echo '<?php
echo html5qp($html, "td")
->after("<tr><td>seven</td><td>eight</td><td>nine</td></tr>")
-->top("table")
+->parents("table") // traverse up the DOM until we match the table
->html()
';
@@ -123,7 +120,7 @@
echo htmlspecialchars(
html5qp($html, 'tr:last')
->after("\n\n\t\n\t\t| seven | \n\t\teight | \n\t\tnine | \n\t
")
- ->top("table")
+ ->parents('table')
->html()
);
@@ -136,12 +133,11 @@
echo 'Example 1
';
echo 'Add the attribute class="item" to all <desc> elements:';
- echo '
-<?php
+ echo '<?php
echo qp($xml, "desc")
->attr("class", "item)
-->top() // return to the <categories> tag
+->top() // return to the root node (<categories>)
->xml(); // output a valid XML document.
';
@@ -152,7 +148,7 @@
echo htmlspecialchars(
qp($xml, 'desc')
->attr('class', 'item')
- ->top() // return to the tag
+ ->top() // return to the root node
->xml() // output a valid XML document
);
@@ -167,8 +163,7 @@
->find('categories > category:nth-child(3) desc')
->text();
- echo '
-<?php
+ echo '<?php
echo qp($xml)
->find("categories > category:nth-child(3) desc")
@@ -179,8 +174,7 @@
echo 'Example 3
';
echo 'Append a category at the end of the group:';
- echo '
-<?php
+ echo '<?php
echo qp($xml, "category:last")
->after("<category name=\'Appended\'><desc>The appended node...</desc></category>")
diff --git a/examples/create-html-document/index.php b/examples/create-html-document/index.php
index f36978f8..aeead712 100644
--- a/examples/create-html-document/index.php
+++ b/examples/create-html-document/index.php
@@ -16,43 +16,101 @@
require_once __DIR__ . '/../../vendor/autoload.php';
+echo 'Building a HTML Document with QueryPath
';
+
+echo 'You can use QueryPath to build complex HTML documents using a simple jQuery-like API:';
+
+echo '<?php
+
+// Begin with an HTML5 stub document and navigate to the title.
+html5qp(\QueryPath\QueryPath::HTML5_STUB, "title")
+ // Add text to the title
+ ->text("Example of QueryPath.")
+ // Traverse to the root of the document, then locate the body tag
+ ->top("body")
+ // Inside the body, add a heading and paragraph.
+ ->append("<h1>This is a test page</h1><p>Test text</p>")
+ // Select the paragraph we just created inside the body
+ ->children("p")
+ // Add a class attribute to the paragraph
+ ->attr("class", "some-class")
+ // And an inline style to the paragraph
+ ->css("background-color", "#eee")
+ // Traverse back up the DOM to the body
+ ->parent()
+ // Add an empty table to the body, before the heading
+ ->prepend("<table id=\'my-table\'></table>")
+ // Now go to the table...
+ ->find("#my-table")
+ // Add a couple of empty rows
+ ->append("<tr></tr><tr></tr>")
+ // select the rows (both at once)
+ ->children()
+ // Add a CSS class to both rows
+ ->addClass("table-row")
+ // Get the first row (at position 0)
+ ->eq(0)
+ // Add a table header in the first row
+ ->append("<th>This is the header</th>")
+ // Now go to the next row
+ ->next()
+ // Add some data to this row
+ ->append("<td>This is the data</td>")
+ // Traverse to the root of the document
+ ->top()
+ // Write it all out as HTML
+ ->html();
+';
+
+echo '
';
+
+echo 'Results
';
+
try {
+ echo '';
+
+ echo htmlspecialchars(
// Begin with an HTML5 stub document and navigate to the title.
- html5qp(\QueryPath\QueryPath::HTML5_STUB, 'title')
- // Add some text to the title
- ->text('Example of QueryPath.')
- // Now look for the element
- ->top('body')
- // Inside the body, add a title and paragraph.
- ->append('This is a test page
Test text
')
- // Now we select the paragraph we just created inside the body
- ->children('p')
- // Add a 'class="some-class"' attribute to the paragraph
- ->attr('class', 'some-class')
- // And add a style attribute, too, setting the background color.
- ->css('background-color', '#eee')
- // Now go back to the paragraph again
- ->parent()
- // Before the paragraph and the title, add an empty table.
- ->prepend('')
- // Now let's go to the table...
- ->top('#my-table')
- // Add a couple of empty rows
- ->append('|
')
- // select the rows (both at once)
- ->children()
- // Add a CSS class to both rows
- ->addClass('table-row')
- // Now just get the first row (at position 0)
- ->eq(0)
- // Add a table header in the first row
- ->append('This is the header | ')
- // Now go to the next row
- ->next()
- // Add some data to this row
- ->append('This is the data | ')
- // Write it all out as HTML
- ->writeHTML5();
+ html5qp(\QueryPath\QueryPath::HTML5_STUB, 'title')
+ // Add text to the title
+ ->text('Example of QueryPath.')
+ // Traverse to the root of the document, then locate the body tag
+ ->top('body')
+ // Inside the body, add a heading and paragraph.
+ ->append('This is a test page
Test text
')
+ // Select the paragraph we just created inside the body
+ ->children('p')
+ // Add a class attribute to the paragraph
+ ->attr('class', 'some-class')
+ // And an inline style to the paragraph
+ ->css('background-color', '#eee')
+ // Traverse back up the DOM to the body
+ ->parent()
+ // Add an empty table to the body, before the heading
+ ->prepend('')
+ // Now let's go to the table...
+ ->find('#my-table')
+ // Add a couple of empty rows
+ ->append('|
')
+ // select the rows (both at once)
+ ->children()
+ // Add a CSS class to both rows
+ ->addClass('table-row')
+ // Get the first row (at position 0)
+ ->eq(0)
+ // Add a table header in the first row
+ ->append('This is the header | ')
+ // Now go to the next row
+ ->next()
+ // Add some data to this row
+ ->append('This is the data | ')
+ // Traverse to the root of the document
+ ->top()
+ // Write it all out as HTML
+ ->html()
+ );
+
+ echo '
';
} catch (\QueryPath\Exception $e) {
die($e->getMessage());
}
From 7a9aeae5625a4b9e62a5a2745160f8e50e0b8a1a Mon Sep 17 00:00:00 2001
From: Jake Jackson
Date: Fri, 12 Apr 2024 18:09:12 +1000
Subject: [PATCH 14/14] For later
---
.../basic-manipulation-filter-and-retrieval/index.php | 2 ++
examples/create-html-document/index.php | 4 +++-
examples/create-xml-document/index.php | 10 ++++++++--
3 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/examples/basic-manipulation-filter-and-retrieval/index.php b/examples/basic-manipulation-filter-and-retrieval/index.php
index 8ca19baf..84f99cb0 100644
--- a/examples/basic-manipulation-filter-and-retrieval/index.php
+++ b/examples/basic-manipulation-filter-and-retrieval/index.php
@@ -2,6 +2,8 @@
require_once __DIR__ . '/../../vendor/autoload.php';
+//TODO - consider writeHTML() or writeXML() instead of html() / xml()
+
/*
* HTML Example
*/
diff --git a/examples/create-html-document/index.php b/examples/create-html-document/index.php
index aeead712..7ba80c20 100644
--- a/examples/create-html-document/index.php
+++ b/examples/create-html-document/index.php
@@ -20,10 +20,12 @@
echo 'You can use QueryPath to build complex HTML documents using a simple jQuery-like API:';
+//TODO - consider writeHTML() instead of html()
+
echo '<?php
// Begin with an HTML5 stub document and navigate to the title.
-html5qp(\QueryPath\QueryPath::HTML5_STUB, "title")
+echo html5qp(\QueryPath\QueryPath::HTML5_STUB, "title")
// Add text to the title
->text("Example of QueryPath.")
// Traverse to the root of the document, then locate the body tag
diff --git a/examples/create-xml-document/index.php b/examples/create-xml-document/index.php
index 2407e604..e5c6c6f7 100644
--- a/examples/create-xml-document/index.php
+++ b/examples/create-xml-document/index.php
@@ -21,8 +21,14 @@
* By default, it will point to the root element ``
*/
+//TODO
+// Use QueryPath::withXML() will allow you to omit the XML declaration ""
+// \QueryPath\QueryPath::withXML('')
+// ->append('Wiseman')
+// ->writeXML();
+
try {
- echo qp('')
+ qp('')
// Add a new last name inside of author.
->append('Wiseman')
// Select all of the children of . In this case,
@@ -46,7 +52,7 @@
// turn the QueryPath contents back into a string. Since we are
// at the top of the document, the whole document will be converted
// to a string.
- ->xml();
+ ->writeXML();
} catch (\QueryPath\Exception $e) {
die($e->getMessage());
}