Mercurial > hg > webaudioevaluationtool
comparison scripts/comment_parser.php @ 1107:6ac36f0fb2cd
Starting server side scripts. WIP, stash
author | Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk> |
---|---|
date | Wed, 17 Feb 2016 12:10:55 +0000 |
parents | |
children | d85e219a5eeb |
comparison
equal
deleted
inserted
replaced
1106:282dfb8076f5 | 1107:6ac36f0fb2cd |
---|---|
1 <?php | |
2 // Comment Parser for PHP | |
3 | |
4 // XML Saves location - assumes it will be saves/ | |
5 $saves = glob("../saves/*.xml"); | |
6 $comment_struct = new SimpleXMLElement('<waetprocess/>'); | |
7 if (is_array($saves)) | |
8 { | |
9 foreach($saves as $filename) { | |
10 $xml_string = file_get_contents($filename, FILE_TEXT); | |
11 $xml_object = simplexml_load_string($xml_string); | |
12 $test_struct = $comment_struct->addChild("test"); | |
13 if ($xml_object == false) { | |
14 echo "<h1>FATAL</h1> <span>could not parse file ".$filename.": </span>"; | |
15 foreach(libxml_get_errors() as $error) { | |
16 echo "<br>", $error->message; | |
17 } | |
18 } else { | |
19 // Iterate over each audioHolder node | |
20 foreach($xml_object->page as $pageInstance) | |
21 { | |
22 $page_struct = $test_struct->addChild("page"); | |
23 // Get the page-id and attach | |
24 $page_struct->addAttribute("page-id",$pageInstance['id']); | |
25 | |
26 // Get the audioelements of the page | |
27 foreach($pageInstance->audioelement as $fragment) | |
28 { | |
29 $fragment_struct = $page_struct->addChild("audioelement"); | |
30 // Get the element-id and attach | |
31 $page_struct->addAttribute("element-id",$fragment['id']); | |
32 $page_struct->addAttribute("presented-id",$fragment['presentedId']); | |
33 $page_struct->addAttribute("url",$fragment['url']); | |
34 // Append the comment data | |
35 echo "<p>Comment: ".$fragement->comment."</p>"; | |
36 $comment = $fragment_struct->addChild("comment"); | |
37 } | |
38 } | |
39 } | |
40 } | |
41 // Now we have a sub <xml> containing all comment data | |
42 echo $comment_struct->asXML(); | |
43 } else { | |
44 echo "FATAL - No saved XML files discovered"; | |
45 } | |
46 ?> |