@@ -28,10 +28,10 @@ |
||
28 | 28 | $qp = htmlqp(QueryPath::HTML_STUB, 'body'); |
29 | 29 | |
30 | 30 | |
31 | - $qp->append('<div></div><p id="cool">Hello</p><p id="notcool">Goodbye</p>') |
|
32 | - ->children('p') |
|
33 | - ->after('<p id="new">new paragraph</p>'); |
|
31 | + $qp->append('<div></div><p id="cool">Hello</p><p id="notcool">Goodbye</p>') |
|
32 | + ->children('p') |
|
33 | + ->after('<p id="new">new paragraph</p>'); |
|
34 | 34 | |
35 | - echo ($qp->find('p')->children('p')->html()) ? 'print' : 'dont print';; |
|
35 | + echo ($qp->find('p')->children('p')->html()) ? 'print' : 'dont print';; |
|
36 | 36 | |
37 | 37 | // ->writeHTML(); |
@@ -32,6 +32,6 @@ |
||
32 | 32 | ->children('p') |
33 | 33 | ->after('<p id="new">new paragraph</p>'); |
34 | 34 | |
35 | - echo ($qp->find('p')->children('p')->html()) ? 'print' : 'dont print';; |
|
35 | + echo ($qp->find('p')->children('p')->html()) ? 'print' : 'dont print'; ; |
|
36 | 36 | |
37 | 37 | // ->writeHTML(); |
@@ -32,11 +32,11 @@ |
||
32 | 32 | </svg>'; |
33 | 33 | |
34 | 34 | qp($svg_stub) |
35 | - ->attr(array('width' => 800, 'height' => 600)) |
|
36 | - ->append('<rect id="first"/><rect id="second"/>') |
|
37 | - ->find('#second') |
|
38 | - ->attr(array('x' => 15, 'y' => 4, 'width' => 40, 'height' => 60, 'fill' => 'red')) |
|
39 | - ->prev() |
|
40 | - ->attr(array('x' => 2, 'y' => 2, 'width' => 40, 'height' => 60, 'fill' => 'navy')) |
|
41 | - ->writeXML(); |
|
35 | + ->attr(array('width' => 800, 'height' => 600)) |
|
36 | + ->append('<rect id="first"/><rect id="second"/>') |
|
37 | + ->find('#second') |
|
38 | + ->attr(array('x' => 15, 'y' => 4, 'width' => 40, 'height' => 60, 'fill' => 'red')) |
|
39 | + ->prev() |
|
40 | + ->attr(array('x' => 2, 'y' => 2, 'width' => 40, 'height' => 60, 'fill' => 'navy')) |
|
41 | + ->writeXML(); |
|
42 | 42 |
@@ -29,11 +29,11 @@ discard block |
||
29 | 29 | |
30 | 30 | // Show the "outline": all of the heading items: |
31 | 31 | foreach ($doc->find('text|h') as $header) { |
32 | - $style = $header->attr('text:style-name'); |
|
33 | - $attr_parts = explode('_', $style); |
|
34 | - $level = array_pop($attr_parts); |
|
35 | - $out = str_repeat(' ', $level) . '- ' . $header->text(); |
|
36 | - print $out . PHP_EOL; |
|
32 | + $style = $header->attr('text:style-name'); |
|
33 | + $attr_parts = explode('_', $style); |
|
34 | + $level = array_pop($attr_parts); |
|
35 | + $out = str_repeat(' ', $level) . '- ' . $header->text(); |
|
36 | + print $out . PHP_EOL; |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | // This is a fairly sophisticated selector. It gets the first |
@@ -44,11 +44,11 @@ discard block |
||
44 | 44 | |
45 | 45 | print PHP_EOL . "Bullet List" . PHP_EOL; |
46 | 46 | foreach ($doc->top()->find($selector) as $bullet) { |
47 | - print ' * ' . $bullet->text() . PHP_EOL; |
|
47 | + print ' * ' . $bullet->text() . PHP_EOL; |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | print PHP_EOL . "Ordered List" . PHP_EOL; |
51 | 51 | $i = 0; |
52 | 52 | foreach ($doc->top()->find('text|list[text|style-name="L2"]:first text|p[text|style-name="P2"]') as $bullet) { |
53 | - print ' ' . (++$i) . '. '. $bullet->text() . PHP_EOL; |
|
53 | + print ' ' . (++$i) . '. '. $bullet->text() . PHP_EOL; |
|
54 | 54 | } |
55 | 55 | \ No newline at end of file |
@@ -50,5 +50,5 @@ |
||
50 | 50 | print PHP_EOL . "Ordered List" . PHP_EOL; |
51 | 51 | $i = 0; |
52 | 52 | foreach ($doc->top()->find('text|list[text|style-name="L2"]:first text|p[text|style-name="P2"]') as $bullet) { |
53 | - print ' ' . (++$i) . '. '. $bullet->text() . PHP_EOL; |
|
53 | + print ' ' . (++$i) . '. ' . $bullet->text() . PHP_EOL; |
|
54 | 54 | } |
55 | 55 | \ No newline at end of file |
@@ -20,8 +20,8 @@ discard block |
||
20 | 20 | $artist_url = 'http://musicbrainz.org/ws/1/artist/?type=xml&name=u2'; |
21 | 21 | $album_url = 'http://musicbrainz.org/ws/1/release/?type=xml&artistid='; |
22 | 22 | try { |
23 | - $artist = qp($artist_url, 'artist:first'); |
|
24 | - if ($artist->size() > 0) { |
|
23 | + $artist = qp($artist_url, 'artist:first'); |
|
24 | + if ($artist->size() > 0) { |
|
25 | 25 | $id = $artist->attr('id'); |
26 | 26 | print '<p>The best match we found was for ' . $artist->children('name')->text() . PHP_EOL; |
27 | 27 | print '</p><p>Artist ID: ' . $id . PHP_EOL; |
@@ -30,12 +30,12 @@ discard block |
||
30 | 30 | $albums = qp($album_url . urlencode($id))->writeXML(); |
31 | 31 | |
32 | 32 | foreach ($albums as $album) { |
33 | - print $album->find('title')->text() . PHP_EOL; |
|
34 | - // Fixme: Label is broken. See Drupal QueryPath module. |
|
35 | - print '(' . $album->next('label')->text() . ')' .PHP_EOL; |
|
33 | + print $album->find('title')->text() . PHP_EOL; |
|
34 | + // Fixme: Label is broken. See Drupal QueryPath module. |
|
35 | + print '(' . $album->next('label')->text() . ')' .PHP_EOL; |
|
36 | + } |
|
36 | 37 | } |
37 | - } |
|
38 | 38 | } |
39 | 39 | catch (Exception $e) { |
40 | - print $e->getMessage(); |
|
40 | + print $e->getMessage(); |
|
41 | 41 | } |
@@ -26,13 +26,13 @@ |
||
26 | 26 | print '<p>The best match we found was for ' . $artist->children('name')->text() . PHP_EOL; |
27 | 27 | print '</p><p>Artist ID: ' . $id . PHP_EOL; |
28 | 28 | print '</p><p>Albums for this artist' . PHP_EOL; |
29 | - print '</p><p><a href="'.$album_url . urlencode($id).'">'.$album_url.'</a></p>'; |
|
29 | + print '</p><p><a href="' . $album_url . urlencode($id) . '">' . $album_url . '</a></p>'; |
|
30 | 30 | $albums = qp($album_url . urlencode($id))->writeXML(); |
31 | 31 | |
32 | 32 | foreach ($albums as $album) { |
33 | 33 | print $album->find('title')->text() . PHP_EOL; |
34 | 34 | // Fixme: Label is broken. See Drupal QueryPath module. |
35 | - print '(' . $album->next('label')->text() . ')' .PHP_EOL; |
|
35 | + print '(' . $album->next('label')->text() . ')' . PHP_EOL; |
|
36 | 36 | } |
37 | 37 | } |
38 | 38 | } |
@@ -35,7 +35,6 @@ |
||
35 | 35 | print '(' . $album->next('label')->text() . ')' .PHP_EOL; |
36 | 36 | } |
37 | 37 | } |
38 | -} |
|
39 | -catch (Exception $e) { |
|
38 | +} catch (Exception $e) { |
|
40 | 39 | print $e->getMessage(); |
41 | 40 | } |
@@ -12,8 +12,8 @@ |
||
12 | 12 | print '<h3>Urban Dictionary Random Word Generator</h3>'; |
13 | 13 | |
14 | 14 | $page = rand(0, 288); |
15 | -$qp = htmlqp('http://www.urbandictionary.com/?page='.$page, '#home'); |
|
15 | +$qp = htmlqp('http://www.urbandictionary.com/?page=' . $page, '#home'); |
|
16 | 16 | |
17 | 17 | $rand = rand(0, 7); |
18 | -print $qp->find('.word')->eq($rand)->text().'<br />'; |
|
18 | +print $qp->find('.word')->eq($rand)->text() . '<br />'; |
|
19 | 19 | print $qp->top()->find('.definition')->eq($rand)->text(); |
@@ -20,15 +20,15 @@ discard block |
||
20 | 20 | |
21 | 21 | |
22 | 22 | foreach(qp($path, 'w|p') as $qp) { |
23 | - $qr = $qp->branch(); |
|
24 | - print format($qr->find('w|r:first'), 'w|r:first').' '; |
|
25 | - $qp->find('w|r:first'); |
|
26 | - while($qp->next('w|r')->html() != null) { |
|
23 | + $qr = $qp->branch(); |
|
24 | + print format($qr->find('w|r:first'), 'w|r:first').' '; |
|
25 | + $qp->find('w|r:first'); |
|
26 | + while($qp->next('w|r')->html() != null) { |
|
27 | 27 | $qr = $qp->branch(); |
28 | 28 | print format($qr->find('w|r'), 'w|r').' '; |
29 | 29 | // print $qp->text(); |
30 | - } |
|
31 | - print '</br>'; |
|
30 | + } |
|
31 | + print '</br>'; |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | /** |
@@ -39,17 +39,17 @@ discard block |
||
39 | 39 | */ |
40 | 40 | function format($qp, $findSelector = null) { |
41 | 41 | |
42 | - // Create a new branch for printing later. |
|
43 | - $qr = $qp->branch(); |
|
42 | + // Create a new branch for printing later. |
|
43 | + $qr = $qp->branch(); |
|
44 | 44 | |
45 | - $text = ""; |
|
45 | + $text = ""; |
|
46 | 46 | |
47 | - $text = $qr->find($findSelector)->find('w|t')->text(); |
|
47 | + $text = $qr->find($findSelector)->find('w|t')->text(); |
|
48 | 48 | |
49 | - $text = (checkUnderline($qp->branch())) ? '<u>'.$text.'</u>' : $text; |
|
50 | - $text = (checkBold($qp->branch())) ? '<b>'.$text.'</b>' : $text; |
|
49 | + $text = (checkUnderline($qp->branch())) ? '<u>'.$text.'</u>' : $text; |
|
50 | + $text = (checkBold($qp->branch())) ? '<b>'.$text.'</b>' : $text; |
|
51 | 51 | |
52 | - return $text; |
|
52 | + return $text; |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | /** |
@@ -58,8 +58,8 @@ discard block |
||
58 | 58 | * @return String |
59 | 59 | */ |
60 | 60 | function checkBold($qp) { |
61 | - $qp->children("w|rPr"); |
|
62 | - return ($qp->children('w|b')->html()) ? true : false; |
|
61 | + $qp->children("w|rPr"); |
|
62 | + return ($qp->children('w|b')->html()) ? true : false; |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | /** |
@@ -68,8 +68,8 @@ discard block |
||
68 | 68 | * @return String |
69 | 69 | */ |
70 | 70 | function checkUnderline($qp) { |
71 | - $qp->children("w|rPr"); |
|
72 | - return ($qp->children('w|u')->html()) ? true : false; |
|
71 | + $qp->children("w|rPr"); |
|
72 | + return ($qp->children('w|u')->html()) ? true : false; |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | |
@@ -78,9 +78,9 @@ discard block |
||
78 | 78 | } |
79 | 79 | |
80 | 80 | function readZippedXML($archiveFile, $dataFile) { |
81 | - if (!class_exists('ZipArchive', false)) { |
|
82 | - return "ZipArchive Class Doesn't Exist."; |
|
83 | - } |
|
81 | + if (!class_exists('ZipArchive', false)) { |
|
82 | + return "ZipArchive Class Doesn't Exist."; |
|
83 | + } |
|
84 | 84 | // Create new ZIP archive |
85 | 85 | $zip = new ZipArchive(); |
86 | 86 | // Open received archive file |
@@ -19,13 +19,13 @@ discard block |
||
19 | 19 | $path = $data; |
20 | 20 | |
21 | 21 | |
22 | -foreach(qp($path, 'w|p') as $qp) { |
|
22 | +foreach (qp($path, 'w|p') as $qp) { |
|
23 | 23 | $qr = $qp->branch(); |
24 | - print format($qr->find('w|r:first'), 'w|r:first').' '; |
|
24 | + print format($qr->find('w|r:first'), 'w|r:first') . ' '; |
|
25 | 25 | $qp->find('w|r:first'); |
26 | - while($qp->next('w|r')->html() != null) { |
|
26 | + while ($qp->next('w|r')->html() != null) { |
|
27 | 27 | $qr = $qp->branch(); |
28 | - print format($qr->find('w|r'), 'w|r').' '; |
|
28 | + print format($qr->find('w|r'), 'w|r') . ' '; |
|
29 | 29 | // print $qp->text(); |
30 | 30 | } |
31 | 31 | print '</br>'; |
@@ -46,8 +46,8 @@ discard block |
||
46 | 46 | |
47 | 47 | $text = $qr->find($findSelector)->find('w|t')->text(); |
48 | 48 | |
49 | - $text = (checkUnderline($qp->branch())) ? '<u>'.$text.'</u>' : $text; |
|
50 | - $text = (checkBold($qp->branch())) ? '<b>'.$text.'</b>' : $text; |
|
49 | + $text = (checkUnderline($qp->branch())) ? '<u>' . $text . '</u>' : $text; |
|
50 | + $text = (checkBold($qp->branch())) ? '<b>' . $text . '</b>' : $text; |
|
51 | 51 | |
52 | 52 | return $text; |
53 | 53 | } |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | * @param String $v |
19 | 19 | */ |
20 | 20 | function addClasses($v) { |
21 | - return "<a href='".$_SERVER['PHP_SELF']."?key=$v'><span class='keyname'>$v</span></a><br />"; |
|
21 | + return "<a href='".$_SERVER['PHP_SELF']."?key=$v'><span class='keyname'>$v</span></a><br />"; |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | // The document skeleton |
@@ -36,25 +36,25 @@ discard block |
||
36 | 36 | |
37 | 37 | // Search through the xml file to find any entries of jQuery entities |
38 | 38 | foreach(qp('querypath.xml', 'entry') as $entry) { |
39 | - $qpnames[$entry->attr('name')] = |
|
40 | - array('desc' => $entry->find('desc')->innerXML(), |
|
39 | + $qpnames[$entry->attr('name')] = |
|
40 | + array('desc' => $entry->find('desc')->innerXML(), |
|
41 | 41 | 'jquery' => $entry->parent()->find('jquery')->innerXML(), |
42 | 42 | 'querypath' => $entry->parent()->find('querypath')->innerXML()); |
43 | 43 | } |
44 | 44 | |
45 | 45 | // Search through the xml file to find all entries of jQuery entities |
46 | 46 | foreach(htmlqp('http://api.jquery.com/api/', 'entry') as $entry) { |
47 | - $category = false; |
|
48 | - $category = array_search($entry->find('category:first')->attr('name'), $qparray); |
|
49 | - while($entry->next('category')->html() != null) { |
|
47 | + $category = false; |
|
48 | + $category = array_search($entry->find('category:first')->attr('name'), $qparray); |
|
49 | + while($entry->next('category')->html() != null) { |
|
50 | 50 | $category = (array_search($entry->attr('name'), $qparray)) ? true : $category; |
51 | 51 | if($category) break; |
52 | - } |
|
53 | - if($category) { |
|
52 | + } |
|
53 | + if($category) { |
|
54 | 54 | $jqnames[$entry->parent()->attr('name')] = |
55 | - array('longdesc' => $entry->find('longdesc')->innerXML(), |
|
55 | + array('longdesc' => $entry->find('longdesc')->innerXML(), |
|
56 | 56 | 'name' => $entry->parent()->find('category')->attr('name')); |
57 | - } |
|
57 | + } |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | // Map the keys & sort them |
@@ -65,25 +65,25 @@ discard block |
||
65 | 65 | // Add the keys to the nav bar |
66 | 66 | $qpdoc->find('#leftbody'); |
67 | 67 | foreach($jqkeys as $k => $v) { |
68 | - $qpdoc->append($v); |
|
68 | + $qpdoc->append($v); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | // Add the description to the main window if the key exists |
72 | 72 | if(array_key_exists($key, $jqnames)) { |
73 | - if(array_key_exists($key, $qpnames)) { |
|
73 | + if(array_key_exists($key, $qpnames)) { |
|
74 | 74 | $qpdoc->top()->find('#rightfunction')->text('Function: '.ucfirst($key)); |
75 | 75 | $qpdoc->top()->find('#rightdesc')->text($qpnames[$key]['desc']); |
76 | 76 | $qpdoc->top()->find('#righttitle')->text('How it\'s done in jQuery'); |
77 | 77 | $qpdoc->top()->find('#righttext')->text($qpnames[$key]['jquery']); |
78 | 78 | $qpdoc->top()->find('#righttitle2')->text('How it\'s done in QueryPath'); |
79 | 79 | $qpdoc->top()->find('#righttext2')->text($qpnames[$key]['querypath']); |
80 | - } |
|
81 | - else { |
|
80 | + } |
|
81 | + else { |
|
82 | 82 | $qpdoc->top()->find('#rightfunction')->text('Function: '.ucfirst($key)); |
83 | 83 | $qpdoc->top()->find('#rightdesc')->remove(); |
84 | 84 | $qpdoc->top()->find('#righttitle')->text('jQuery Documentation'); |
85 | 85 | $qpdoc->top()->find('#righttext')->append($jqnames[$key]['longdesc']); |
86 | - } |
|
86 | + } |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | // Write the document |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | * @param String $v |
19 | 19 | */ |
20 | 20 | function addClasses($v) { |
21 | - return "<a href='".$_SERVER['PHP_SELF']."?key=$v'><span class='keyname'>$v</span></a><br />"; |
|
21 | + return "<a href='" . $_SERVER['PHP_SELF'] . "?key=$v'><span class='keyname'>$v</span></a><br />"; |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | // The document skeleton |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | $qpnames = array(); |
36 | 36 | |
37 | 37 | // Search through the xml file to find any entries of jQuery entities |
38 | -foreach(qp('querypath.xml', 'entry') as $entry) { |
|
38 | +foreach (qp('querypath.xml', 'entry') as $entry) { |
|
39 | 39 | $qpnames[$entry->attr('name')] = |
40 | 40 | array('desc' => $entry->find('desc')->innerXML(), |
41 | 41 | 'jquery' => $entry->parent()->find('jquery')->innerXML(), |
@@ -43,14 +43,14 @@ discard block |
||
43 | 43 | } |
44 | 44 | |
45 | 45 | // Search through the xml file to find all entries of jQuery entities |
46 | -foreach(htmlqp('http://api.jquery.com/api/', 'entry') as $entry) { |
|
46 | +foreach (htmlqp('http://api.jquery.com/api/', 'entry') as $entry) { |
|
47 | 47 | $category = false; |
48 | 48 | $category = array_search($entry->find('category:first')->attr('name'), $qparray); |
49 | - while($entry->next('category')->html() != null) { |
|
49 | + while ($entry->next('category')->html() != null) { |
|
50 | 50 | $category = (array_search($entry->attr('name'), $qparray)) ? true : $category; |
51 | - if($category) break; |
|
51 | + if ($category) break; |
|
52 | 52 | } |
53 | - if($category) { |
|
53 | + if ($category) { |
|
54 | 54 | $jqnames[$entry->parent()->attr('name')] = |
55 | 55 | array('longdesc' => $entry->find('longdesc')->innerXML(), |
56 | 56 | 'name' => $entry->parent()->find('category')->attr('name')); |
@@ -64,14 +64,14 @@ discard block |
||
64 | 64 | |
65 | 65 | // Add the keys to the nav bar |
66 | 66 | $qpdoc->find('#leftbody'); |
67 | -foreach($jqkeys as $k => $v) { |
|
67 | +foreach ($jqkeys as $k => $v) { |
|
68 | 68 | $qpdoc->append($v); |
69 | 69 | } |
70 | 70 | |
71 | 71 | // Add the description to the main window if the key exists |
72 | -if(array_key_exists($key, $jqnames)) { |
|
73 | - if(array_key_exists($key, $qpnames)) { |
|
74 | - $qpdoc->top()->find('#rightfunction')->text('Function: '.ucfirst($key)); |
|
72 | +if (array_key_exists($key, $jqnames)) { |
|
73 | + if (array_key_exists($key, $qpnames)) { |
|
74 | + $qpdoc->top()->find('#rightfunction')->text('Function: ' . ucfirst($key)); |
|
75 | 75 | $qpdoc->top()->find('#rightdesc')->text($qpnames[$key]['desc']); |
76 | 76 | $qpdoc->top()->find('#righttitle')->text('How it\'s done in jQuery'); |
77 | 77 | $qpdoc->top()->find('#righttext')->text($qpnames[$key]['jquery']); |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | $qpdoc->top()->find('#righttext2')->text($qpnames[$key]['querypath']); |
80 | 80 | } |
81 | 81 | else { |
82 | - $qpdoc->top()->find('#rightfunction')->text('Function: '.ucfirst($key)); |
|
82 | + $qpdoc->top()->find('#rightfunction')->text('Function: ' . ucfirst($key)); |
|
83 | 83 | $qpdoc->top()->find('#rightdesc')->remove(); |
84 | 84 | $qpdoc->top()->find('#righttitle')->text('jQuery Documentation'); |
85 | 85 | $qpdoc->top()->find('#righttext')->append($jqnames[$key]['longdesc']); |
@@ -48,7 +48,9 @@ discard block |
||
48 | 48 | $category = array_search($entry->find('category:first')->attr('name'), $qparray); |
49 | 49 | while($entry->next('category')->html() != null) { |
50 | 50 | $category = (array_search($entry->attr('name'), $qparray)) ? true : $category; |
51 | - if($category) break; |
|
51 | + if($category) { |
|
52 | + break; |
|
53 | + } |
|
52 | 54 | } |
53 | 55 | if($category) { |
54 | 56 | $jqnames[$entry->parent()->attr('name')] = |
@@ -77,8 +79,7 @@ discard block |
||
77 | 79 | $qpdoc->top()->find('#righttext')->text($qpnames[$key]['jquery']); |
78 | 80 | $qpdoc->top()->find('#righttitle2')->text('How it\'s done in QueryPath'); |
79 | 81 | $qpdoc->top()->find('#righttext2')->text($qpnames[$key]['querypath']); |
80 | - } |
|
81 | - else { |
|
82 | + } else { |
|
82 | 83 | $qpdoc->top()->find('#rightfunction')->text('Function: '.ucfirst($key)); |
83 | 84 | $qpdoc->top()->find('#rightdesc')->remove(); |
84 | 85 | $qpdoc->top()->find('#righttitle')->text('jQuery Documentation'); |
@@ -26,30 +26,30 @@ |
||
26 | 26 | // By default, it will point to the root element, |
27 | 27 | // <author/> |
28 | 28 | $record = qp('<?xml version="1.0"?><author></author>') |
29 | - // Add a new last name inside of author. |
|
30 | - ->append('<lastName>Dostoyevsky</lastName>') |
|
31 | - // Select all of the children of <author/>. In this case, |
|
32 | - // that is <lastName/> |
|
33 | - ->children() |
|
34 | - // Oh, wait... we wanted last name to be inside of a <name/> |
|
35 | - // element. Use wrap to wrap the current element in something: |
|
36 | - ->wrap('<name/>') |
|
37 | - // And before last name, we want to add first name. |
|
38 | - ->before('<firstName/>') |
|
39 | - // Select first name |
|
40 | - ->prev() |
|
41 | - // Set the text of first name |
|
42 | - ->text('Fyodor') |
|
43 | - // And then after first name, add the patronymic |
|
44 | - ->after('<patronymic>Fyodorovich</patronymic>') |
|
45 | - // Now go back to the root element, the top of the document. |
|
46 | - ->top() |
|
47 | - // Add another tag -- origin. |
|
48 | - ->append('<origin>Russia</origin>') |
|
49 | - // turn the QueryPath contents back into a string. Since we are |
|
50 | - // at the top of the document, the whole document will be converted |
|
51 | - // to a string. |
|
52 | - ->xml(); |
|
29 | + // Add a new last name inside of author. |
|
30 | + ->append('<lastName>Dostoyevsky</lastName>') |
|
31 | + // Select all of the children of <author/>. In this case, |
|
32 | + // that is <lastName/> |
|
33 | + ->children() |
|
34 | + // Oh, wait... we wanted last name to be inside of a <name/> |
|
35 | + // element. Use wrap to wrap the current element in something: |
|
36 | + ->wrap('<name/>') |
|
37 | + // And before last name, we want to add first name. |
|
38 | + ->before('<firstName/>') |
|
39 | + // Select first name |
|
40 | + ->prev() |
|
41 | + // Set the text of first name |
|
42 | + ->text('Fyodor') |
|
43 | + // And then after first name, add the patronymic |
|
44 | + ->after('<patronymic>Fyodorovich</patronymic>') |
|
45 | + // Now go back to the root element, the top of the document. |
|
46 | + ->top() |
|
47 | + // Add another tag -- origin. |
|
48 | + ->append('<origin>Russia</origin>') |
|
49 | + // turn the QueryPath contents back into a string. Since we are |
|
50 | + // at the top of the document, the whole document will be converted |
|
51 | + // to a string. |
|
52 | + ->xml(); |
|
53 | 53 | |
54 | 54 | // Print our results. |
55 | 55 | print $record; |
56 | 56 | \ No newline at end of file |
@@ -42,8 +42,8 @@ discard block |
||
42 | 42 | |
43 | 43 | // We first set up the parameters that will be sent. |
44 | 44 | $params = array( |
45 | - 'query' => $sparql, |
|
46 | - 'format' => 'application/sparql-results+xml', |
|
45 | + 'query' => $sparql, |
|
46 | + 'format' => 'application/sparql-results+xml', |
|
47 | 47 | ); |
48 | 48 | |
49 | 49 | // DB Pedia wants a GET query, so we create one. |
@@ -56,27 +56,27 @@ discard block |
||
56 | 56 | // Get the headers from the resulting XML. |
57 | 57 | $headers = array(); |
58 | 58 | foreach ($qp->children('variable') as $col) { |
59 | - $headers[] = $col->attr('name'); |
|
59 | + $headers[] = $col->attr('name'); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | // Get rows of data from result. |
63 | 63 | $rows = array(); |
64 | 64 | $col_count = count($headers); |
65 | 65 | foreach ($qp->top()->find('results>result') as $row) { |
66 | - $cols = array(); |
|
67 | - $row->children(); |
|
68 | - for ($i = 0; $i < $col_count; ++$i) { |
|
66 | + $cols = array(); |
|
67 | + $row->children(); |
|
68 | + for ($i = 0; $i < $col_count; ++$i) { |
|
69 | 69 | $cols[$i] = $row->branch()->eq($i)->text(); |
70 | - } |
|
71 | - $rows[] = $cols; |
|
70 | + } |
|
71 | + $rows[] = $cols; |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | // Turn data into table. |
75 | 75 | $table = '<table><tr><th>' . implode('</th><th>', $headers) . '</th></tr>'; |
76 | 76 | foreach ($rows as $row) { |
77 | - $table .= '<tr><td>'; |
|
78 | - $table .= implode('</td><td>', $row); |
|
79 | - $table .= '</td></tr>'; |
|
77 | + $table .= '<tr><td>'; |
|
78 | + $table .= implode('</td><td>', $row); |
|
79 | + $table .= '</td></tr>'; |
|
80 | 80 | } |
81 | 81 | $table .= '</table>'; |
82 | 82 |