nickjillings@1307
|
1 <?php
|
nickjillings@1307
|
2 // Comment Parser for PHP
|
nickjillings@1307
|
3
|
nickjillings@1307
|
4 // XML Saves location - assumes it will be saves/
|
nickjillings@1307
|
5 $saves = glob("../saves/*.xml");
|
nickjillings@1307
|
6 $comment_struct = new SimpleXMLElement('<waetprocess/>');
|
nickjillings@1307
|
7 if (is_array($saves))
|
nickjillings@1307
|
8 {
|
nickjillings@1307
|
9 foreach($saves as $filename) {
|
nickjillings@1307
|
10 $xml_string = file_get_contents($filename, FILE_TEXT);
|
nickjillings@1307
|
11 $xml_object = simplexml_load_string($xml_string);
|
nickjillings@1307
|
12 $test_struct = $comment_struct->addChild("test");
|
nickjillings@1307
|
13 if ($xml_object == false) {
|
nickjillings@1307
|
14 echo "<h1>FATAL</h1> <span>could not parse file ".$filename.": </span>";
|
nickjillings@1307
|
15 foreach(libxml_get_errors() as $error) {
|
nickjillings@1307
|
16 echo "<br>", $error->message;
|
nickjillings@1307
|
17 }
|
nickjillings@1307
|
18 } else {
|
nickjillings@1307
|
19 // Iterate over each audioHolder node
|
nickjillings@1307
|
20 foreach($xml_object->page as $pageInstance)
|
nickjillings@1307
|
21 {
|
nickjillings@1307
|
22 $page_struct = $test_struct->addChild("page");
|
nickjillings@1307
|
23 // Get the page-id and attach
|
nickjillings@1307
|
24 $page_struct->addAttribute("page-id",$pageInstance['id']);
|
nickjillings@1307
|
25
|
nickjillings@1307
|
26 // Get the audioelements of the page
|
nickjillings@1307
|
27 foreach($pageInstance->audioelement as $fragment)
|
nickjillings@1307
|
28 {
|
nickjillings@1307
|
29 $fragment_struct = $page_struct->addChild("audioelement");
|
nickjillings@1307
|
30 // Get the element-id and attach
|
nickjillings@1307
|
31 $page_struct->addAttribute("element-id",$fragment['id']);
|
nickjillings@1307
|
32 $page_struct->addAttribute("presented-id",$fragment['presentedId']);
|
nickjillings@1307
|
33 $page_struct->addAttribute("url",$fragment['url']);
|
nickjillings@1307
|
34 // Append the comment data
|
nickjillings@1307
|
35 echo "<p>Comment: ".$fragement->comment."</p>";
|
nickjillings@1307
|
36 $comment = $fragment_struct->addChild("comment");
|
nickjillings@1307
|
37 }
|
nickjillings@1307
|
38 }
|
nickjillings@1307
|
39 }
|
nickjillings@1307
|
40 }
|
nickjillings@1307
|
41 // Now we have a sub <xml> containing all comment data
|
nickjillings@1307
|
42 echo $comment_struct->asXML();
|
nickjillings@1307
|
43 } else {
|
nickjillings@1307
|
44 echo "FATAL - No saved XML files discovered";
|
nickjillings@1307
|
45 }
|
nickjillings@1307
|
46 ?> |