[asterisk-commits] mvanbaak: branch group/appdocsxml r129215 - /team/group/appdocsxml/contrib/sc...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Jul 8 16:32:47 CDT 2008


Author: mvanbaak
Date: Tue Jul  8 16:32:46 2008
New Revision: 129215

URL: http://svn.digium.com/view/asterisk?view=rev&rev=129215
Log:
add php file to parse the documentation.xml.
This is very basic, hacked together during a visit to my 'little room'

23:26 <@      mvanbaak> bkruse: should I add the php I have in the scripts dir ?
23:27 <@        bkruse> contrib?
23:27 <@        bkruse> yes, i can work on it a little too


Added:
    team/group/appdocsxml/contrib/scripts/xmldoc.php   (with props)

Added: team/group/appdocsxml/contrib/scripts/xmldoc.php
URL: http://svn.digium.com/view/asterisk/team/group/appdocsxml/contrib/scripts/xmldoc.php?view=auto&rev=129215
==============================================================================
--- team/group/appdocsxml/contrib/scripts/xmldoc.php (added)
+++ team/group/appdocsxml/contrib/scripts/xmldoc.php Tue Jul  8 16:32:46 2008
@@ -1,0 +1,102 @@
+<?php
+
+/**
+ * Configuration
+ */
+
+// Set the full path to the documentation.xml here
+// XXX: should be put here by the autoconf/make cycle
+$xmlfile = "/home/michiel/dev/personal/asterisk/appdocsxml/documentation.xml";
+
+/**
+ * Logic, no changes needed for end users
+ * XXX: finish this
+ */
+class XmlElement {
+	var $name;
+	var $attributes;
+	var $content;
+	var $children;
+};
+
+function xml_to_object($xml) {
+	$parser = xml_parser_create();
+	xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
+	xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
+	xml_parse_into_struct($parser, $xml, $tags);
+	xml_parser_free($parser);
+
+	$elements = array();  // the currently filling [child] XmlElement array
+	$stack = array();
+	foreach ($tags as $tag) {
+		$index = count($elements);
+		if ($tag["type"] == "complete" || $tag["type"] == "open") {
+			$elements[$index] = new XmlElement;
+			$elements[$index]->name = $tag["tag"];
+			$elements[$index]->attributes = $tag["attributes"];
+			$elements[$index]->content = $tag["value"];
+			if ($tag["type"] == "open") {  // push
+				$elements[$index]->children = array();
+				$stack[count($stack)] = &$elements;
+				$elements = &$elements[$index]->children;
+			}
+		}
+		if ($tag["type"] == "close") {  // pop
+			$elements = &$stack[count($stack) - 1];
+			unset($stack[count($stack) - 1]);
+		}
+	}
+	return $elements[0];  // the single top-level element
+}
+
+// buffer for output
+$buffer = array();
+
+// read xml file
+$xml = file_get_contents($xmlfile);
+
+// parse the xml into an object
+$res = xml_to_object($xml);
+
+// loop through all elements
+foreach ($res->children as $v) {
+	$nodeinfo = array();
+	//var_dump($v);
+	if ($v->attributes["language"]) {
+		$lang = $v->attributes["language"];
+	} else {
+		$lang = "en";
+	}
+	$buffer[$v->name][$lang][$v->attributes["name"]] = array();
+	foreach ($v->children as $child) {
+		//var_dump($child);
+		if ($child->name == "synopsis") {
+			$buffer[$v->name][$lang][$v->attributes["name"]]["synopsis"] = $child->content;
+		}
+		if ($child->name == "description") {
+			$buffer[$v->name][$lang][$v->attributes["name"]]["description"] = $child->content;
+		}
+		if ($child->name == "variable") {
+			$varvalues = array();
+			if (is_array($child->children)) {
+				foreach ($child->children as $childvalues) {
+					$varvalues[$childvalues->attributes["name"]] = array(
+						"description" => $childvalues->content,
+					);
+				}
+			}
+			$buffer[$v->name][$lang][$v->attributes["name"]]["variables"][$child->attributes["name"]] = array(
+				"description" => $child->content,
+				"values" => $varvalues,
+			);
+
+		}
+	}
+	//echo $v->name;
+	//echo "<br>";
+	unset($nodeinfo);
+}
+
+$output = print_r($buffer, true);
+echo "<pre>".$output."</pre>";
+?>

Propchange: team/group/appdocsxml/contrib/scripts/xmldoc.php
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/group/appdocsxml/contrib/scripts/xmldoc.php
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: team/group/appdocsxml/contrib/scripts/xmldoc.php
------------------------------------------------------------------------------
    svn:mime-type = text/plain




More information about the asterisk-commits mailing list