Index: aws_xml/includes/minixml/docs/rsstest.xml =================================================================== RCS file: aws_xml/includes/minixml/docs/rsstest.xml diff -N aws_xml/includes/minixml/docs/rsstest.xml --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ aws_xml/includes/minixml/docs/rsstest.xml 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,76 @@ + + + + +ireland.com Latest Irish News +http://www.ireland.com/breakingnews +hourly +5 +2005-03-01T07:27:33+00:00 + + + +Irish news and breaking headlines from ireland.com - Ireland + +en-ie +ireland.com +2005-03-01T07:27:33+00:00 +Copyright 2005, ireland.com. + + + + + + + + + + + + +Man questioned over Co Tyrone murder + + +http://www.ireland.com/newspaper/breaking/2005/0301/breaking8.htm + + + +Police in the North are today questioning a man about the murder of a retired postmaster and a sexual assault on the victim's elderly sister. + +Irish +text/html +2005-03-01T07:10:09+00:00 + + + +Keane to take stand in assault court case + + +http://www.ireland.com/newspaper/breaking/2005/0301/breaking7.htm + + + +Irish international footballer Roy Keane is due to give evidence in a Manchester court today after allegedly grabbing a teenager then throwing a punch at his face. + +Irish +text/html +2005-03-01T07:06:45+00:00 + + + +Curtin challenge to Oireachtas hearing opens + + +http://www.ireland.com/newspaper/breaking/2005/0301/breaking2.htm + + + + + +The High Court will today start hearing the judicial review of the Oireachtas decision setting up a committee to inquire into the conduct of Judge Brian Curtin. + +Irish +text/html +2005-03-01T06:06:58+00:00 + + Index: aws_xml/includes/minixml/README =================================================================== RCS file: aws_xml/includes/minixml/README diff -N aws_xml/includes/minixml/README --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ aws_xml/includes/minixml/README 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,57 @@ +*********************************************************************** +*********************************************************************** +***** +***** MiniXML/XML::Mini - PHP and Perl classes for generating +***** and parsing XML. +***** +***** Copyright (C) 2002 Patrick Deegan, Psychogenic.com +***** All rights reserved. +***** +***** http://minixml.psychogenic.com +***** +***** This program is free software; you can redistribute +***** it and/or modify it under the terms of the GNU +***** General Public License as published by the Free +***** Software Foundation; either version 2 of the +***** License, or (at your option) any later version. +***** +***** This program is distributed in the hope that it will +***** be useful, but WITHOUT ANY WARRANTY; without even +***** the implied warranty of MERCHANTABILITY or FITNESS +***** FOR A PARTICULAR PURPOSE. See the GNU General +***** Public License for more details. +***** +***** You should have received a copy of the GNU General +***** Public License along with this program; if not, +***** write to the Free Software Foundation, Inc., 675 +***** Mass Ave, Cambridge, MA 02139, USA. +***** +***** +***** You may contact the author, Pat Deegan, through the +***** contact section at http://www.psychogenic.com +***** +***** Much more information on using this API can be found on the +***** official MiniXML website - http://minixml.psychogenic.com +***** +*********************************************************************** +*********************************************************************** + +MiniXML provides a simple API to generating and parsing XML with 2 implementations: +- a 100% PHP implementation +- a set of Pure Perl modules. + +Either of the implementations may be used seperately. + +MiniXML provides classes for XML documents and elements. + +There is some example code in the docs directory but the full API, +an overview and example code are all available on the official website at: + +http://minixml.psychogenic.com + +Also have a look in the ./doc directory, for a few examples of PHP (*.php) and +Perl (*.pl) + +Regards, +Pat Deegan + Index: aws_xml/includes/minixml/classes/doc.inc.php =================================================================== RCS file: aws_xml/includes/minixml/classes/doc.inc.php diff -N aws_xml/includes/minixml/classes/doc.inc.php --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ aws_xml/includes/minixml/classes/doc.inc.php 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,892 @@ +]+)([^>]+)?>(.*?)<\s*\/\\1\s*>\s*([^<]+)?(.*)|\s*\s*|^\s*<\s*([^\s>]+)([^>]*)\/\s*>\s*([^<>]+)?|||]+)\s*(["\'])([^\14]+)\14\s*>|^([^<]+)(.*)/smi'); +*/ + +define("MINIXML_COMPLETE_REGEX",'/^\s*<\s*([^\s>]+)(\s+[^>]+)?>(.*?)<\s*\/\1\s*>\s*([^<]+)?(.*)|^\s*\s*(.*)|^\s*<\s*([^\s>]+)([^>]+)\/\s*>\s*(.*)|^\s*\s*(.*)|^\s*\s*(.*)|^\s*]+)\s*(["\'])([^\17]+)\17\s*>\s*(.*)|^([^<]+)(.*)/smi'); + +/* +#define("MINIXML_SIMPLE_REGEX", +# // 1 2 3 4 5 6 7 8 9 #10 11 +#'/\s*<\s*([^\s>]+)([^>]+)?>(.*?)<\s*\/\\1\s*>\s*([^<]+)?(.*)|\s*\s*|\s*<\s*([^\s>]+)([^>]*)\/\s*>\s*([^<>]+)?|^([^<]+)(.*)/smi'); + +*/ +define("MINIXML_SIMPLE_REGEX",'/^\s*<\s*([^\s>]+)(\s+[^>]+)?>(.*?)<\s*\/\1\s*>\s*([^<]+)?(.*)|^\s*\s*(.*)|^\s*<\s*([^\s>]+)([^>]+)\/\s*>\s*(.*)|^([^<]+)(.*)/smi'); + + +require_once(MINIXML_CLASSDIR . "/element.inc.php"); + +/*************************************************************************************************** +**************************************************************************************************** +***** +***** MiniXMLDoc +***** +**************************************************************************************************** +***************************************************************************************************/ + +/* MiniXMLDoc class +** +** The MiniXMLDoc class is the programmer's handle to MiniXML functionality. +** +** A MiniXMLDoc instance is created in every program that uses MiniXML. +** With the MiniXMLDoc object, you can access the root MiniXMLElement, +** find/fetch/create elements and read in or output XML strings. +**/ +class MiniXMLDoc { + var $xxmlDoc; + var $xuseSimpleRegex; + var $xRegexIndex; + + /* MiniXMLDoc [XMLSTRING] + ** Constructor, create and init a MiniXMLDoc object. + ** + ** If the optional XMLSTRING is passed, the document will be initialised with + ** a call to fromString using the XMLSTRING. + ** + */ + function MiniXMLDoc ($string=NULL) + { + /* Set up the root element - note that it's name get's translated to a + ** string. + */ + $this->xxmlDoc = new MiniXMLElement("PSYCHOGENIC_ROOT_ELEMENT"); + $this->xuseSimpleRegex = MINIXML_USE_SIMPLE; + if (! is_null($string)) + { + $this->fromString($string); + } + + } + + function init () + { + $this->xxmlDoc = new MiniXMLElement("PSYCHOGENIC_ROOT_ELEMENT"); + } + + /* getRoot + ** Returns a reference the this document's root element + ** (an instance of MiniXMLElement) + */ + function &getRoot () + { + return $this->xxmlDoc; + } + + + /* setRoot NEWROOT + ** Set the document root to the NEWROOT MiniXMLElement object. + **/ + function setRoot (&$root) + { + if ($this->isElement($root)) + { + $this->xxmlDoc = $root; + } else { + return _MiniXMLError("MiniXMLDoc::setRoot(): Trying to set non-MiniXMLElement as root"); + } + } + + /* isElement ELEMENT + ** Returns a true value if ELEMENT is an instance of MiniXMLElement, + ** false otherwise. + */ + function isElement (&$testme) + { + if (is_null($testme)) + { + return 0; + } + + return method_exists($testme, 'MiniXMLElement'); + } + + + /* isNode NODE + ** Returns a true value if NODE is an instance of MiniXMLNode, + ** false otherwise. + */ + function isNode (&$testme) + { + if (is_null($testme)) + { + return 0; + } + + return method_exists($testme, 'MiniXMLNode'); + } + + + /* createElement NAME [VALUE] + ** Creates a new MiniXMLElement with name NAME. + ** This element is an orphan (has no assigned parent) + ** and will be lost unless it is appended (MiniXMLElement::appendChild()) + ** to an element at some point. + ** + ** If the optional VALUE (string or numeric) parameter is passed, + ** the new element's text/numeric content will be set using VALUE. + ** + ** Returns a reference to the newly created element (use the =& operator) + */ + function &createElement ($name=NULL, $value=NULL) + { + $newElement = new MiniXMLElement($name); + + if (! is_null($value)) + { + if (is_numeric($value)) + { + $newElement->numeric($value); + } elseif (is_string($value)) + { + $newElement->text($value); + } + } + + return $newElement; + } + + /* getElement NAME + ** Searches the document for an element with name NAME. + ** + ** Returns a reference to the first MiniXMLElement with name NAME, + ** if found, NULL otherwise. + ** + ** NOTE: The search is performed like this, returning the first + ** element that matches: + ** + ** - Check the Root Element's immediate children (in order) for a match. + ** - Ask each immediate child (in order) to MiniXMLElement::getElement() + ** (each child will then proceed similarly, checking all it's immediate + ** children in order and then asking them to getElement()) + */ + function &getElement ($name) + { + + $element = $this->xxmlDoc->getElement($name); + if (MINIXML_DEBUG > 0) + { + _MiniXMLLog("MiniXMLDoc::getElement(): Returning element $element"); + } + + return $element; + + } + + + /* getElementByPath PATH + ** Attempts to return a reference to the (first) element at PATH + ** where PATH is the path in the structure from the root element to + ** the requested element. + ** + ** For example, in the document represented by: + ** + ** + ** + ** + ** + ** + ** + ** DA42 + ** + ** + ** D99983FFF + ** + ** + ** ss-839uent + ** + ** + ** + ** + ** $accessid =& $xmlDocument->getElementByPath('partRateRequest/vendor/accessid'); + ** + ** Will return what you expect (the accessid element with attributes user = "myusername" + ** and password = "mypassword"). + ** + ** BUT be careful: + ** $accessid =& $xmlDocument->getElementByPath('partRateRequest/partList/partNum'); + ** + ** will return the partNum element with the value "DA42". Other partNums are + ** inaccessible by getElementByPath() - Use MiniXMLElement::getAllChildren() instead. + ** + ** Returns the MiniXMLElement reference if found, NULL otherwise. + */ + function &getElementByPath ($path) + { + + $element = $this->xxmlDoc->getElementByPath($path); + if (MINIXML_DEBUG > 0) + { + _MiniXMLLog("Returning element $element"); + } + + return $element; + + } + + function fromFile ($filename) + { + $modified = stat($filename); + if (! is_array($modified)) + { + _MiniXMLError("Can't stat '$filename'"); + return NULL; + } + + if (MINIXML_USEFROMFILECACHING > 0) + { + + $tmpName = MINIXML_FROMFILECACHEDIR . '/' . 'minixml-' . md5($filename); + if (MINIXML_DEBUG > 0) + { + _MiniXMLLog("Trying to open cach file $tmpName (for '$filename')"); + } + $cacheFileStat = stat($tmpName); + + if (is_array($cacheFileStat) && $cacheFileStat[9] > $modified[9]) + { + + $fp = @fopen($tmpName,"r"); + if ($fp) + { + if (MINIXML_DEBUG > 0) + { + _MiniXMLLog("Reading file '$filename' from object cache instead ($tmpName)"); + } + $tmpFileSize = filesize($tmpName); + $tmpFileContents = fread($fp, $tmpFileSize); + + $serializedObj = unserialize($tmpFileContents); + + $sRoot =& $serializedObj->getRoot(); + if ($sRoot) + { + if (MINIXML_DEBUG > 0) + { + _MiniXMLLog("Restoring object from cache file $tmpName"); + } + $this->setRoot($sRoot); + + /* Return immediately, such that we don't refresh the cache */ + return $this->xxmlDoc->numChildren(); + + } /* end if we got a root element from unserialized object */ + + } /* end if we sucessfully opened the file */ + + + } /* end if cache file exists and is more recent */ + } + + + ob_start(); + readfile($filename); + $filecontents = ob_get_contents(); + ob_end_clean(); + + $retVal = $this->fromString($filecontents); + + if (MINIXML_USEFROMFILECACHING > 0) + { + $this->saveToCache($filename); + } + + return $retVal; + + + } + + function saveToCache ($filename) + { + $tmpName = MINIXML_FROMFILECACHEDIR . '/' . 'minixml-' . md5($filename); + + $fp = @fopen($tmpName, "w"); + + if (MINIXML_DEBUG > 0) + { + _MiniXMLLog("Saving object to cache as '$tmpName'"); + } + + if ($fp) + { + + $serialized = serialize($this); + fwrite($fp, $serialized); + + fclose($fp); + } else { + _MiniXMLError("Could not open $tmpName for write in MiniXMLDoc::saveToCache()"); + } + + } + + /* fromString XMLSTRING + ** + ** Initialise the MiniXMLDoc (and it's root MiniXMLElement) using the + ** XML string XMLSTRING. + ** + ** Returns the number of immediate children the root MiniXMLElement now + ** has. + */ + function fromString (&$XMLString) + { + $useSimpleFlag = $this->xuseSimpleRegex; + + + if ($this->xuseSimpleRegex || ! preg_match('/xuseSimpleRegex = 1; + + $this->xRegexIndex = array( + 'biname' => 1, + 'biattr' => 2, + 'biencl' => 3, + 'biendtxt' => 4, + 'birest' => 5, + 'comment' => 6, + 'uname' => 8, + 'uattr' => 9, + 'plaintxt' => 11, + 'plainrest' => 12 + ); + $regex = MINIXML_SIMPLE_REGEX; + + } else { + + $this->xRegexIndex = array( + 'biname' => 1, + 'biattr' => 2, + 'biencl' => 3, + 'biendtxt' => 4, + 'birest' => 5, + 'comment' => 6, + 'uname' => 8, + 'uattr' => 9, + 'cdata' => 11, + 'doctypedef' => 13, + 'doctypecont' => 14, + 'entityname' => 16, + 'entitydef' => 18, + 'plaintxt' => 20, + 'plainrest' => 21 + ); + $regex = MINIXML_COMPLETE_REGEX; + } + + $this->fromSubString($this->xxmlDoc, $XMLString, $regex); + + $this->xuseSimpleRegex = $useSimpleFlag; + + return $this->xxmlDoc->numChildren(); + + } + + + function fromArray (&$init, $params=NULL) + { + + $this->init(); + + + if (! is_array($init) ) + { + + return _MiniXMLError("MiniXMLDoc::fromArray(): Must Pass an ARRAY to initialize from"); + } + + if (! is_array($params) ) + { + $params = array(); + } + + if ( $params["attributes"] && is_array($params["attributes"]) ) + { + + $attribs = array(); + foreach ($params["attributes"] as $attribName => $value) + { + if (! (array_key_exists($attribName, $attribs) && is_array($attribs[$attribName]) ) ) + { + $attribs[$attribName] = array(); + } + + if (is_array($value)) + { + foreach ($value as $v) + { + if (array_key_exists($v, $attribs[$attribName])) + { + $attribs[$attribName][$v]++; + } else { + $attribs[$attribName][$v] = 1; + } + } + } else { + if (array_key_exists($value,$attribs[$attribName])) + { + $attribs[$attribName][$value]++; + } else { + $attribs[$attribName][$value] = 1; + } + } + } + + // completely replace old attributes by our optimized array + $params["attributes"] = $attribs; + } else { + $params["attributes"] = array(); + } + + foreach ($init as $keyname => $value) + { + $sub = $this->_fromArray_getExtractSub($value); + + + $this->$sub($keyname, $value, $this->xxmlDoc, $params); + + } + + + return $this->xxmlDoc->numChildren(); + + } + + function _fromArray_getExtractSub ($v) + { + // is it a string, a numerical array or an associative array? + $sub = "_fromArray_extract"; + if (is_array($v)) + { + if (_MiniXML_NumKeyArray($v)) + { + // All numeric - assume it is a "straight" array + $sub .= "ARRAY"; + } else { + $sub .= "AssociativeARRAY"; + } + + } else { + $sub .= "STRING"; + } + + + return $sub; + } + + + + + + function _fromArray_extractAssociativeARRAY ($name, &$value, &$parent, &$params) + { + + $thisElement =& $parent->createChild($name); + + foreach ($value as $key => $val) + { + + $sub = $this->_fromArray_getExtractSub($val); + + + $this->$sub($key, $val, $thisElement, $params); + + } + + return; + } + + function _fromArray_extractARRAY ($name, &$value, &$parent, &$params) + { + + foreach ($value as $val) + { + $sub = $this->_fromArray_getExtractSub($val); + + + $this->$sub($name, $val, $parent, $params); + + } + + return; + } + + + function _fromArray_extractSTRING ($name, $value="", &$parent, &$params) + { + + $pname = $parent->name(); + + if ( + ( array_key_exists($pname, $params['attributes']) && is_array($params['attributes'][$pname]) + && array_key_exists($name, $params['attributes'][$pname]) && $params['attributes'][$pname][$name]) + || ( + array_key_exists('-all', $params['attributes']) && is_array($params['attributes']['-all']) + && array_key_exists($name, $params['attributes']['-all']) && $params['attributes']['-all'][$name]) + ) + { + $parent->attribute($name, $value); + } elseif ($name == '-content') { + + $parent->text($value); + } else { + $parent->createChild($name, $value); + } + + return; + } + + + + function time ($msg) + { + error_log("\nMiniXML msg '$msg', time: ". time() . "\n"); + } + // fromSubString PARENTMINIXMLELEMENT XMLSUBSTRING + // private method, called recursively to parse the XMLString in little sub-chunks. + function fromSubString (&$parentElement, &$XMLString, &$regex) + { + //$this->time('fromSubStr'); + + if (is_null($parentElement) || empty($XMLString) || preg_match('/^\s*$/', $XMLString)) + { + return; + } + if (MINIXML_DEBUG > 0) + { + _MiniXMLLog("Called fromSubString() with parent '" . $parentElement->name() . "'\n"); + } + + $matches = array(); + if (preg_match_all( $regex, $XMLString, $matches)) + { + // $this->time('a match'); + + $mcp = $matches; + + $numMatches = count($mcp[0]); + + for($i=0; $i < $numMatches; $i++) + { + if (MINIXML_DEBUG > 1) + { + _MiniXMLLog ("Got $numMatches CHECKING: ". $mcp[0][$i] . "\n"); + } + + $uname = $mcp[$this->xRegexIndex['uname']][$i]; + $comment = $mcp[$this->xRegexIndex['comment']][$i]; + if ($this->xuseSimpleRegex) + { + $cdata = NULL; + $doctypecont = NULL; + $entityname = NULL; + + $tailEndIndexes = array(5, 7, 10, 12); + } else { + + $cdata = $mcp[$this->xRegexIndex['cdata']][$i]; + $doctypecont = $mcp[$this->xRegexIndex['doctypecont']][$i]; + $entityname = $mcp[$this->xRegexIndex['entityname']][$i]; + + $tailEndIndexes = array(5, 7, 10, 12, 15, 19, 21); + } + + $plaintext = $mcp[$this->xRegexIndex['plaintxt']][$i]; + + // check all the 'tailend' (i.e. rest of string) matches for more content + $moreContent = ''; + $idx = 0; + while (empty($moreContent) && ($idx < count($tailEndIndexes))) + { + if (! empty($mcp[$tailEndIndexes[$idx]][$i])) + { + $moreContent = $mcp[$tailEndIndexes[$idx]][$i]; + } + + $idx++; + } + + + + if ($uname) + { + // _MiniXMLLog ("Got UNARY $uname"); + $newElement =& $parentElement->createChild($uname); + $this->_extractAttributesFromString($newElement, $mcp[$this->xRegexIndex['uattr']][$i]); + + } elseif ($comment) { + //_MiniXMLLog ("Got comment $comment"); + $parentElement->comment($comment); + + } elseif ($cdata) { + //_MiniXMLLog ("Got cdata $cdata"); + $newElement = new MiniXMLElementCData($cdata); + $parentElement->appendChild($newElement); + } elseif ($doctypecont) { + //_MiniXMLLog ("Got doctype $doctypedef '" . $mcp[11][$i] . "'"); + $newElement = new MiniXMLElementDocType($mcp[$this->xRegexIndex['doctypedef']][$i]); + $appendedChild =& $parentElement->appendChild($newElement); + $this->fromSubString($appendedChild, $doctypecont, $regex); + + } elseif ($entityname ) { + //_MiniXMLLog ("Got entity $entityname"); + $newElement = new MiniXMLElementEntity ($entityname, $mcp[$this->xRegexIndex['entitydef']][$i]); + $parentElement->appendChild($newElement); + + } elseif ($plaintext) { + + if (! preg_match('/^\s+$/', $plaintext)) + { + $parentElement->createNode($plaintext); + } + + } elseif($mcp[$this->xRegexIndex['biname']]) { + + // _MiniXMLLog("Got BIN NAME: " . $mcp[$this->xRegexIndex['biname']][$i]); + + $nencl = $mcp[$this->xRegexIndex['biencl']][$i]; + $finaltxt = $mcp[$this->xRegexIndex['biendtxt']][$i]; + + $newElement =& $parentElement->createChild($mcp[$this->xRegexIndex['biname']][$i]); + $this->_extractAttributesFromString($newElement, $mcp[$this->xRegexIndex['biattr']][$i]); + + + + $plaintxtMatches = array(); + if (preg_match("/^\s*([^\s<][^<]*)/", $nencl, $plaintxtMatches)) + { + $txt = $plaintxtMatches[1]; + $newElement->createNode($txt); + + $nencl = preg_replace("/^\s*([^<]+)/", "", $nencl); + } + + + if ($nencl && !preg_match('/^\s*$/', $nencl)) + { + $this->fromSubString($newElement, $nencl, $regex); + } + + if ($finaltxt) + { + $parentElement->createNode($finaltxt); + } + + + } /* end switch over type of match */ + + if (! empty($moreContent)) + { + $this->fromSubString($parentElement, $moreContent, $regex); + } + + + } /* end loop over all matches */ + + + } /* end if there was a match */ + + } /* end method fromSubString */ + + + /* toString [DEPTH] + ** Converts this MiniXMLDoc object to a string and returns it. + ** + ** The optional DEPTH may be passed to set the space offset for the + ** first element. + ** + ** If the optional DEPTH is set to MINIXML_NOWHITESPACES. + ** When it is, no \n or whitespaces will be inserted in the xml string + ** (ie it will all be on a single line with no spaces between the tags. + ** + ** Returns a string of XML representing the document. + */ + function toString ($depth=0) + { + $retString = $this->xxmlDoc->toString($depth); + + if ($depth == MINIXML_NOWHITESPACES) + { + $xmlhead = ""; + } else { + $xmlhead = "\n "; + } + $search = array("/]*)>\s*/smi", + "/<\/PSYCHOGENIC_ROOT_ELEMENT>/smi"); + $replace = array($xmlhead, + ""); + $retString = preg_replace($search, $replace, $retString); + + + if (MINIXML_DEBUG > 0) + { + _MiniXMLLog("MiniXML::toString() Returning XML:\n$retString\n\n"); + } + + + return $retString; + } + + + /* toArray + ** + ** Transforms the XML structure currently represented by the MiniXML Document object + ** into an array. + ** + ** More docs to come - for the moment, use var_dump($miniXMLDoc->toArray()) to see + ** what's going on :) + */ + + function & toArray () + { + + $retVal = $this->xxmlDoc->toStructure(); + + if (is_array($retVal)) + { + return $retVal; + } + + $retArray = array( + '-content' => $retVal, + ); + + return $retArray; + } + + + + + /* getValue() + ** Utility function, call the root MiniXMLElement's getValue() + */ + function getValue () + { + return $this->xxmlDoc->getValue(); + } + + + + /* dump + ** Debugging aid, dump returns a nicely formatted dump of the current structure of the + ** MiniXMLDoc object. + */ + function dump () + { + return serialize($this); + } + + + + // _extractAttributesFromString + // private method for extracting and setting the attributs from a + // ' a="b" c = "d"' string + function _extractAttributesFromString (&$element, &$attrString) + { + + if (! $attrString) + { + return NULL; + } + + $count = 0; + $attribs = array(); + // Set the attribs + preg_match_all('/([^\s]+)\s*=\s*([\'"])([^\2]*?)\2/sm', $attrString, $attribs); + + + for ($i = 0; $i < count($attribs[0]); $i++) + { + $attrname = $attribs[1][$i]; + $attrval = $attribs[3][$i]; + + if ($attrname) + { + $element->attribute($attrname, $attrval, ''); + $count++; + } + } + + return $count; + } + + /* Destructor to keep things clean -- patch by Ilya */ + function __destruct() + { + $this->xxmlDoc = null; + } + + +} + + + +/*************************************************************************************************** +**************************************************************************************************** +***** +***** MiniXML +***** +**************************************************************************************************** +***************************************************************************************************/ + +/* class MiniXML (MiniXMLDoc) +** +** Avoid using me - I involve needless overhead. +** +** Utility class - this is just an name aliase for the +** MiniXMLDoc class as I keep repeating the mistake of +** trying to create +** +** $xml = new MiniXML(); +** +*/ +class MiniXML extends MiniXMLDoc { + + function MiniXML () + { + $this->MiniXMLDoc(); + } +} + + + Index: aws_xml/includes/minixml/INSTALL =================================================================== RCS file: aws_xml/includes/minixml/INSTALL diff -N aws_xml/includes/minixml/INSTALL --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ aws_xml/includes/minixml/INSTALL 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,38 @@ +Installation instructions for MiniXML: + +===== PHP Implementation ==== + +- Select a directory to install minixml, say /path/to/minixmlinstall and + create it: + $ mkdir /path/to/minixmlinstall + + +- Copy the minixml.inc.php file and the 'classes' directory somewhere. + $ cp -R minixml.inc.php classes /path/to/minixmlinstall + +- Add a + require_once("/path/to/minixmlinstall/minixml.inc.php"); + to your PHP source + +- Use! + + +===== Perl implementation ===== + +- Get the latest source from CPAN. As root, run + +# perl -MCPAN -e 'install XML::Mini' + +OR + +- cd Perl/XML-Mini +- perl Makefile.PL +- make +- make test +- su; make install + +- Add a 'use XML::Mini::Document;' to your Perl source +- Use! + +Regards, +Pat Deegan Index: aws_xml/aws_xml.module =================================================================== RCS file: aws_xml/aws_xml.module diff -N aws_xml/aws_xml.module --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ aws_xml/aws_xml.module 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,16 @@ +fromString($xml); + return($result->toArray()); +} Index: aws_xml/includes/minixml/docs/newsmltest.xml =================================================================== RCS file: aws_xml/includes/minixml/docs/newsmltest.xml diff -N aws_xml/includes/minixml/docs/newsmltest.xml --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ aws_xml/includes/minixml/docs/newsmltest.xml 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,243 @@ + + + + + 20040602T085510Z + + + + + afp.com + 20040602 + 040602085459.e508mtfk + 1 + urn:newsml:afp.com:20040602:040602085459.e508mtfk:1 + + Iraq-US + + + + 20040602T085459Z + 20040602T085459Z + + + + + Iraqi cabinet readies for transition, draft UN resolution boosts sovereignty + + BAGHDAD (AFP) + © 2004 AFP + + + + + + + + + + + + + + + + + + + +

The newly-appointed Iraqi government began preparing for full sovereignty handover from US-led occupation authorities at the end of the month, and received a boost from a new US-British UN resolution draft giving it increased security control.

+ +

While coalition officials hailed the diversity of the line-up presented Tuesday by prime minister Iyad Allawi, some Iraqis were dismissive of a cabinet consisting chiefly of former exiles.

+

UN envoy Lakhdar Brahimi, who had been entrusted with the nomination process and came under pressure from all sides, fell short of his plan to select a government which would be both popular and at the same time willing to work closely with the coalition.

+

UN chief Kofi Annan could not disguise his displeasure that Brahimi was frozen out of the process by Iraqi and US officials opposed to his vision for a technocratic government.

+

"We all have to recognise that the process wasn't perfect," Annan said Tuesday.

+

Brahimi himself stressed on Wednesday at a press conference that the leaders were not elected and would have their work cut out to gain legitimacy. "It will not be easy for them to prove the sceptics wrong," he said.

+

Kurdish leaders took plum posts in the government and tribal leader Ghazi al-Yawar was named president after elder statesman Adnan Pachachi refused the post.

+

The US-backed Allawi hailed the nomination of the new government as an historic step towards sovereignty but showed no sign of rushing to ease the coalition out of Iraq.

+ + + +

"We Iraqis are just like the rest of the peoples in the world. We don't want our country to remain under occupation," he said but then went on to stress that Baghdad would still rely heavily on the US-led coalition.

+ +

"We are seeking to be able to deal in the best possible way with the terrorism and security threats by ourselves but because of the situation prevailing it appears to be impossible and we will need the help and support of the multinational forces to defeat the enemies of Iraq, who don't want stability, freedom and prosperity for us," he explained.

+

At the United Nations, changes were made to a UN Security Council resolution sponsored by Britain and the United States after an outcry from other council nations about sending a clear signal that Iraq will gain full sovereignty when the US-led occupation on June 30 hands power to the interim government.

+

Under the new draft, obtained by AFP, the mandate of US-led troops who will remain in Iraq after this month would expire "upon completion of the political process" to create a constitutionally elected Iraqi government.

+

But with that expected to take until late 2005 or even early 2006, it was not immediately clear if the changes would satisfy opposition to the first text led by China, France and Germany.

+

And the draft still fails to clarify the level of sovereignty the Iraqi leadership will enjoy after June 30, in the run-up to elections next year.

+ + + +

Iraq's interim foreign minister Hoshyar Zebari who flew to New York on Tuesday was expected to meet Security Council members on Thursday.

+ +

The new government was greeted Tuesday by a new surge of violence on the ground, with car bombs in Baghdad and the northern town of Bayji killing a total of 14.

+

Fresh fighting broke out between members of radical Shiite cleric Moqtada Sadr's militia and US forces, leaving eight Iraqi fighters dead and 23 wounded, medical sources said.

+

One was killed and 12 wounded near a US base in Najaf, while five were killed and 11 wounded in the twin city of Kufa.

+

In the Baghdad neighbourhood of Sadr City, two militiamen were also killed by US troops, Sadr's office said.

+

The renewed bloodshed came a day after the governor of Najaf announced 72-hour truce between the two sides.

+

Meanwhile, three coalition soldiers were wounded near the town of Kish, south of Baghdad, when gunmen ambushed a group of soldiers on their way to the inauguration of a local school, said the Polish command in the region.

+
+
+
+ + + Iraqis stand on a pavement in Baghdad to read headlines about the new government + + + + + + + + + + + + + + + +

Iraqis stand on a pavement in Baghdad reading the newspaper headlines a day after the first post-Saddam Hussein era government was unveiled

+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + Iraqi's at a Baghdad coffee shop watch the installing of the new government + + + + + + + + + + + + + + + +

An Iraqi man points at the television in a Baghdad coffee shop showing the new President of Iraq Sheikh Ghazi al-Yawar speaking during the official ceremony installing a new interim government. The US-led occupation force in Iraq dissolved the Governing Council which it set up after toppling Saddam Hussein 14 months ago and installed a new interim government as the UN Security Council prepared to debate a resolution on the country's future

+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + Fighter of radical Shiite Muslim cleric Moqtada Sadr's Mehdi Army runs down a street during clashes with US troops + + + + + + + + + + + + + + + +

A fighter of radical Shiite Muslim cleric Moqtada Sadr's Mehdi Army runs down a street during clashes with US troops in the town of Kufa, a few kilometers away from the holy city of Najaf south of Baghdad

+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
Index: aws_xml/includes/minixml/docs/chewnspit.php =================================================================== RCS file: aws_xml/includes/minixml/docs/chewnspit.php diff -N aws_xml/includes/minixml/docs/chewnspit.php --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ aws_xml/includes/minixml/docs/chewnspit.php 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,20 @@ +fromFile('./test.xml'); + +print $xmlDoc->toString(); + +?> Index: aws_xml/includes/minixml/classes/treecomp.inc.php =================================================================== RCS file: aws_xml/includes/minixml/classes/treecomp.inc.php diff -N aws_xml/includes/minixml/classes/treecomp.inc.php --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ aws_xml/includes/minixml/classes/treecomp.inc.php 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,172 @@ +xparent = NULL; + } /* end MiniXMLTreeComponent constructor */ + + + /* Get set function for the element name + */ + function name ($setTo=NULL) + { + return NULL; + } + + /* Function to fetch an element */ + function & getElement ($name) + { + return NULL; + } + + /* Function that returns the value of this + component and its children */ + function getValue () + { + return NULL; + } + + /* parent NEWPARENT + ** + ** The parent() method is used to get/set the element's parent. + ** + ** If the NEWPARENT parameter is passed, sets the parent to NEWPARENT + ** (NEWPARENT must be an instance of a class derived from MiniXMLTreeComponent) + ** + ** Returns a reference to the parent MiniXMLTreeComponent if set, NULL otherwise. + */ + function &parent (&$setParent) + { + if (! is_null($setParent)) + { + /* Parents can only be MiniXMLElement objects */ + if (! method_exists($setParent, 'MiniXMLTreeComponent')) + { + return _MiniXMLError("MiniXMLTreeComponent::parent(): Must pass an instance derived from " + . "MiniXMLTreeComponent to set."); + } + $this->xparent = $setParent; + } + + return $this->xparent; + + + } + + /* Return a stringified version of the XML representing + this component and all sub-components */ + function toString ($depth=0) + { + return NULL; + } + + /* dump + ** Debugging aid, dump returns a nicely formatted dump of the current structure of the + ** MiniXMLTreeComponent-derived object. + */ + function dump () + { + return var_dump($this); + } + + /* helper class that everybody loves */ + function _spaceStr ($numSpaces) + { + $retStr = ''; + if ($numSpaces < 0) + { + return $retStr; + } + + for($i = 0; $i < $numSpaces; $i++) + { + $retStr .= ' '; + } + + return $retStr; + } + + /* Destructor to keep things clean -- patch by Ilya */ + function __destruct() + { + $this->xparent = null; + } + +} /* end class definition */ + + + Index: aws_xml/includes/minixml/docs/orphan.php =================================================================== RCS file: aws_xml/includes/minixml/docs/orphan.php diff -N aws_xml/includes/minixml/docs/orphan.php --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ aws_xml/includes/minixml/docs/orphan.php 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,44 @@ +getRoot(); + + # Create a sub element + $newChild =& $xmlElement->createChild('mychild'); + + $newChild->text('hello mommy'); + + + # Create an orphan element + + $orphan =& $xmlDoc->createElement('annie'); + $orphan->attribute('hair', '#ff0000'); + $orphan->text('tomorrow, tomorrow'); + + # Adopt the orphan + $newChild->prependChild($orphan); + + $toy =& $xmlDoc->createElement('toy'); + $toy->attribute('color', '#0000ff'); + $toy->createChild('type', 'teddybear'); + + $newChild->insertChild($toy, 1); + + print $xmlDoc->toString(); + + print "\nUhm, it's not working out - she won't stop singing... Calling removeChild()\n\n"; + + $newChild->removeChild($orphan); + $newChild->text('???'); + + print $xmlDoc->toString(); + +?> Index: aws_xml/includes/minixml/docs/genhtml.php =================================================================== RCS file: aws_xml/includes/minixml/docs/genhtml.php diff -N aws_xml/includes/minixml/docs/genhtml.php --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ aws_xml/includes/minixml/docs/genhtml.php 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,134 @@ +createChild('a'); + $ac->attribute('href', $href); + $afontel =& $ac->createChild('font'); + $afontel->attribute('color', '#eeeeee'); + $afontel->text($name); + $parent->text(' '); + return; +} + +$t1NumRows = 3; +$t1NumCols = 3; + +$t2NumRows = 2; +$t2NumCols = 2; + + +$htmlDoc = new MiniXMLDoc(); + +$docRoot =& $htmlDoc->getRoot(); + +$html =& $docRoot->createChild('html'); + + $head =& $html->createChild('head'); + $title =& $head->createChild('title', 'MiniXML Generated HTML page'); + + $style =& $head->createChild('style'); + $style->comment("body,td,a,p,.h{font-family:arial,sans-serif;} .q{text-decoration:none; color:#0000cc;}"); + + $body =& $html->createChild('body'); + $body->attribute('bgcolor', '#ffffff'); + $body->attribute('link', '#0000cc'); + $body->attribute('vlink', '#551a8b'); + + $h =& $body->createChild('h3', 'This page was generated by MiniXML!'); + + /* Note that, when MINIXML_AUTOESCAPE_ENTITIES is set, we can stick in <> tags */ + $p1 =& $body->createChild('p', "It slices, dices and never forgets the ! heh ;) "); + $br =& $p1->createChild('br'); + + $p1->text("View the source of this page to take a look at "); + + $href =& $p1->createChild('a'); + $href->attribute('href', 'http://minixml.psychogenic.com'); + $href->text('MiniXML'); + + $p1->text("'s clean HTML."); + + $p2 =& $body->createChild('p'); + $font =& $p2->createChild('font'); + $font->attribute('size', '-1'); + $font->attribute('color', '#3333cc'); + $font->text('The table below was generated with php - hooray.'); + + + $p =& $body->createChild('p'); + $p->attribute('align', 'center'); + + $t1 =& $p->createChild('table'); + $t1->attribute('cellpadding', 5); + + for ($i=0; $i < $t1NumRows; $i++) + { + $tr =& $t1->createChild('tr'); + for ($j=0; $j < $t1NumCols; $j++) + { + + $td =& $tr->createChild('td'); + $td->attribute('bgcolor', '#542565'); + $ntable =& $td->createChild('table'); + + for ($k = 0; $k < $t2NumRows; $k++) + { + + $ntr =& $ntable->createChild('tr'); + for ($l=0; $l < $t2NumCols; $l++) + { + + $ntd =& $ntr->createChild('td'); + $ntd->attribute('bgcolor', '#401151'); + $nfont =& $ntd->createChild('font'); + $nfont->attribute('color', '#eeeeee'); + $nfont->attribute('size', '-2'); + $nfont->text("This is cell "); + $nfont->createChild('br'); + $nfont->text("($i,$j,$k,$l)"); + } + } + } + } + + $tr =& $t1->createChild('tr'); + $td =& $tr->createChild('td'); + $td->attribute('colspan', $t1NumCols); + $td->attribute('bgcolor', '#542565'); + $td->attribute('align','center'); + $font =& $td->createChild('font'); + $font->attribute('size', '-2'); + $font->attribute('color', '#eeeeee'); + $font->text('Table brought to you by '); + + createHREF($font, 'PHP', 'http://www.php.net'); + createHREF($font,'MiniXML','http://minixml.psychogenic.com'); + createHREF($font,'psychogenic','http://www.psychogenic.com'); + + $font->text('and a bunch of nested loops'); + + + $lastP =& $body->createChild('p'); + $lastP->attribute('align', 'left'); + $lastP->text("============================"); + $lastP->createChild('br'); + + $endtable =& $lastP->createChild('table'); + $endtable->attribute('width', '75%'); + $endtable->attribute('align', 'center'); + + $etr = & $endtable->createChild('tr'); + $etd =& $etr->createChild('td'); + + $etd->createChild('b', "And here is the output of \$htmlDoc->getValue()"); + $etd->createChild('br'); + $etd->text($htmlDoc->getValue()); + +print $htmlDoc->toString(); + +?> Index: aws_xml/includes/minixml/docs/genhtml-fromArray.php =================================================================== RCS file: aws_xml/includes/minixml/docs/genhtml-fromArray.php diff -N aws_xml/includes/minixml/docs/genhtml-fromArray.php --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ aws_xml/includes/minixml/docs/genhtml-fromArray.php 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,88 @@ + array( + + 'head' => array( + 'title' => 'XML::Mini Generated HTML page', + 'style' => 'body,td,a,p,.harray(font-family:arial,sans-serif;) .qarray(text-decoration:none; color:#0000cc;)', + ), + 'body' => array( + 'bgcolor' => '#ffffff', + 'link' => '#0000cc', + 'vlink' => '#551a8b', + 'h3' => 'This page was generated by XML::Mini!', + 'p' => array( + array( + '-content' => 'View the source of this page to take a look at', + 'a' => array( + 'href' => 'http://minixml.psychogenic.com', + '-content' => 'XML::Mini', + ), + ), + array( + 'font' => array( + 'size' => '-1', + 'color' => '#3333cc', + '-content' => 'The table below was generated with php - hooray.', + ), + ), + + array( + 'align' => 'center', + 'table' => array( 'cellpadding' => 5 ), + ), + + array( + 'align' => 'left', + '-content' => '============================', + 'table' => array( + 'width' => '75%', + 'align' => 'center', + 'tr' => array( + array( + 'td' => array( + 'b' => "And here is the output of \$htmlDoc->getValue()", + 'br' => '', + '-content' => $htmlDoc->getValue(), + ), + ), + ), + ), + ) + + ), # end list of

s + ), # end of + ), # end of +); # end of hash + +$options = array( + 'attributes' => array( + 'body' => array('bgcolor', 'link', 'vlink'), + '-all' => array('align', 'color'), + 'a' => 'href', + 'font' => 'size', + 'table' => array('cellpadding', 'cellspacing'), + + ), + ); + +$htmlDoc->fromArray($htmlArray, $options); + +print $htmlDoc->toString(); + +?> Index: aws_xml/includes/minixml/docs/example.php =================================================================== RCS file: aws_xml/includes/minixml/docs/example.php diff -N aws_xml/includes/minixml/docs/example.php --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ aws_xml/includes/minixml/docs/example.php 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,713 @@ + + + + +MiniXML: Overview + + + + + + + +
+ + +

MiniXML API Overview and Demo

+

MiniXML allows you to easily parse and generate XML using PHP. Here is an overview of the API and, below that, a demonstration. I must warn you that the demo program proceeds in a rather roundabout manner as this is example code. And don't worry, it's not really that long, it's just that I'm quite verbose in the comments.

+ + +

Overview

+
+ + + + +
+
+
+The Basics +
+All your interactions with MiniXML begin with a MiniXMLDoc object. +To create one, simply: + + $xmlDoc = new MiniXMLDoc(); + +Now that we have an object, we can use it to parse (read in) existing +XML and/or to create new XML. + +Creating XML. +To generate XML, you get hold of an element (an instance of +MiniXMLElement) and set attributes, add content or child elements. +Since our document is empty, the only available element is the +"root" element. + + $xmlRoot =& $xmlDoc->getRoot(); + +Notice the reference assignment operator, =&. This is to ensure +that we work with the element itself instead of a mere copy. + +Now we can add elements to our document root by creating children: + + $childElement =& $xmlRoot->createChild('achild'); + +Elements can have attributes and content (data or child elements). Here we +set a few attributes and content. + + $childElement->attribute('name', 'annie'); + $childElement->attribute('eyes', '#0000FF'); + $childElement->attribute('hair', '#FF0000'); + + $childElement->text('This element has attributes + and children, such as this'); + + $image =& $childElement->createChild('image'); + $image->attribute('location', + 'http://psychogenic.com/image.png'); + + $childElement->text('image and little'); + +You can also create orphan elements (that have no assigned parents), using the +MiniXMLDoc object: + + $orphan =& $xmlDoc->createElement('song'); + $orphan->text('tomorrow, tomorrow'); + +When you are done, make sure to link the orphan to some parent element (or it +will be lost forever). + + $childElement->appendChild($orphan); + + + +To have a look at the current structure, we can convert our document to an XML +string with + + print $xmlDoc->toString(); + +Which will display:
getRoot();
+	$childElement =& $xmlRoot->createChild('achild');
+	$childElement->attribute('name', 'annie');
+	$childElement->attribute('eyes', '#0000FF');
+	$childElement->attribute('hair', '#FF0000');
+	
+	$childElement->text('This element has attributes and children, such as this');
+	
+	  $image =& $childElement->createChild('image');
+	  $image->attribute('location', 'http://psychogenic.com/image.png');
+	
+	$childElement->text('image and little');
+	 $orphan =& $xmlDoc->createElement('song');
+	 $orphan->text('tomorrow, tomorrow');
+	 $childElement->appendChild($orphan);
+	 
+	print htmlentities($xmlDoc->toString());
+	
+?>
Parsing XML and accessing data +Parsing XML with MiniXML is easy. When you've got a string of XML, you can +initialise a MiniXMLDoc from that string using the aptly named fromString() +method. + +Create a MiniXMLDoc object: + + $parsedDoc = new MiniXMLDoc(); + +Call fromString() + + $parsedDoc->fromString($stringOfXML); + +That's all. Now we can access the elements and their data using appropriate methods. +To access elements, start by getting the root element. + + $rootEl =& $parsedDoc->getRoot(); + +Then use any of these methods: + + +getElement(NAME) +Will return the first child (or subchild) found with name NAME. + + $returnedElement =& $rootEl->getElement('elementName'); + +getElementByPath(PATH) +If you wish to access a particular sub element, getElementByPath() +will return the matching element if found. For instance, with the example +XML generated above we could access the image element from the root element by +calling $returnedElement =& $rootEl->getElementByPath('achild/image'); + + $returnedElement =& $rootEl->getElementByPath('rel/path/to/elementName'); + + +getAllChildren([NAME]) +In cases where an element has many children with the same name and path, you can +access an array of all immediate children, eg + + + $elChildren =& $rootEl->getAllChildren(); + + for($i = 0; $i < $rootEl->numChildren(); $i++) + { + if ($elChildren[$i]->name() == 'aname') + { + /* We've found a child we're looking for */ + /* do stuff... */ + $itsValue = $elChildren[$i]->getValue(); + print "$itsValue\n"; + /* ... */ + } + } + +The optional NAME parameter will return only children with name NAME, +so the if name() == 'aname' step could be skipped by calling + +$rootEl->getAllChildren('aname'); + +
+
+
+ + +

Example code

+ +

The mission

+

You need to communicate with xmlpartsserver.com to query for part numbers and prices. They have set up +a daemon that will accept TCP/IP connections and talks XML.

+ + +

Preparing a request

+

Now you use MiniXML to prepare this request:

+ +
+ + + + +
+ +
+// Use the MiniXML library
+require_once('minixml.inc.php');
+
+
+/* In this example, these are the part numbers we are interested in. */
+$partNumbers = array('DA42', 'D99983FFF', 'ss-839uent');
+
+/*  Create a new MiniXMLDoc object.  This document will be your 
+**  interface to all the XML elements. 
+*/
+$xmlDoc = new MiniXMLDoc();
+
+/* XML is created in a hierarchical manner, like a tree.  To start
+** creating our request, we need this tree's root.
+**
+** NOTICE: That weirdo '=&' is not an ordinary assignment - it's PHP's
+**		way of asking that $xmlRoot be a REFERENCE to the Root Element.
+**		If you don't use =&, you'll be working on a copy and you'll need
+**		to $xmlDoc->setRoot($xmlRoot) when you're done.
+**
+*/
+
+$xmlRoot =& $xmlDoc->getRoot();
+
+/* I've imagined a fictitious structure for this request but 
+** they're usually something like this... 
+**
+** Let's start by adding a partRateRequest element (as a 
+** child of the root element) and then we'll create some
+** children of it's own.
+**
+** Again, note the use of the '=&'.  The alternative is to
+** use '=' and the $parent->appendChild($child) but be 
+** careful as the append is easy to forget...
+*/
+$rateReq =& $xmlRoot->createChild('partRateRequest');
+
+ /* Now we'll create a vendor and a parts list element for the
+ ** request and fill those up.
+ */
+
+ $vendor =& $rateReq->createChild('vendor');
+   
+   $accessid =& $vendor->createChild('accessid');
+   /* Set up a few attributes for this element.
+   ** notice that accessid will have attributes but no
+   ** content (text or whatever) or children.
+   */
+   $accessid->attribute('user', 'myusername');
+   $accessid->attribute('password', 'mypassword');
+ 
+ /* Now we list the parts we are interested.  This element is
+ ** directly under the partRateRequest element.
+ */
+ $partList =& $rateReq->createChild('partList');
+ 
+ /* Now, we add a <partnum>XXX</partnum> element for 
+ ** each part in our array.  
+ **
+ ** Just for fun, here I'm using the createElement/appendChild
+ ** method, instead of $partList->createChild()
+ */
+ for($i=0; $i < count($partNumbers); $i++)
+ {
+ 	/* using MiniXMLDoc's createElement to create
+	** an element with no parent 
+	*/
+ 	$aPart = $xmlDoc->createElement('partNum');
+	
+	/* Set a text value to this element */
+	$aPart->text($partNumbers[$i]);
+	
+	/* Now, don't forget to append this element to a parent
+	** or it will simply dissappear
+	*/
+	$partList->appendChild($aPart);
+}
+
+
+/* OK, we have our request in the xmlDoc.  To pass it along to the
+** server, we stringify it with:
+*/
+
+$xmlString = $xmlDoc->toString();
+
+
+
+
+
+ +

The preceding code will produce an XML document that looks like this: +

+ +setRoot($xmlRoot) when you're done. +** +*/ + +$xmlRoot =& $xmlDoc->getRoot(); + +/* I've imagined a fictitious structure for this request but +** they're usually something like this... +** +** Let's start by adding a partRateRequest element (as a +** child of the root element) and then we'll create it's +** own children. +** +** Again, note the use of the '=&'. The alternative is to +** use '=' and the $parent->appendChild($child) but the +** append is easy to forget... +*/ +$rateReq =& $xmlRoot->createChild('partRateRequest'); + + /* Now we'll create a vendor and a parts list element for the + ** request and fill those up. + */ + + $vendor =& $rateReq->createChild('vendor'); + + $accessid =& $vendor->createChild('accessid'); + /* Set up a few attributes for this element. + ** notice that accessid will have attributes but no + ** content (text or whatever) or children. + */ + $accessid->attribute('user', 'myusername'); + $accessid->attribute('password', 'mypassword'); + + /* Now we list the parts we are interested. This element is + ** directly under the partRateRequest element. + */ + $partList =& $rateReq->createChild('partList'); + + /* Now, we add a XXX element for + ** each part in our array. + ** + ** Just for fun, here I'm using the createElement/appendChild + ** method, instead of $partList->createChild() + */ + for($i=0; $icreateElement('partNum'); + + /* Set a text value to this element */ + $aPart->text($partNumbers[$i]); + + /* Now, don't forget to append this element to a parent + ** or it will simply dissappear + */ + $partList->appendChild($aPart); +} + + +/* OK, we have our request in the xmlDoc. To pass it along to the +** server, we stringify it with: +*/ + +$xmlString = $xmlDoc->toString(); + +/* Here is the output from the toString() call: +*/ +?> + +
+ + + + +
MiniXML toString() output
+
+
+
+ +

Parsing the response

+ +

+Now let's assume we've recieved a valid but messed up reply from the server. It looks like: +

+
+ + + + +
+
+
Ugly XML response from server
+ + 1 + OK + Camshaft end bearing + retention circlip +< +maker id + ="RQ778"> + Ringtown Fasteners Ltd + + + USD + $389.99 + + + + Angle-nosed insertion tool + +is required for the removal and replacement of this item. + + + + Thingamajig for guys with mustaches +< +maker id ="PQSMSM8"> RingWorm Nose Fasteners Inc + + + USD + $292.00 + + + + + + + '; + +print htmlentities($xmlString); + +?>
+
+
+ +

We start by creating a new MiniXMLDoc and setting it up by using fromString() with the received string. +We will then be able to see a cleaned up version (by calling toString() on the document) and will try out the methods associated with fetching elements and their data. +

+ + +
+ + + + +
+ +
+
+
+/* We create a new MiniXMLDoc object */
+$returnedXMLDoc = new MiniXMLDoc();
+
+/* And parse the returned string (assume it was stored in
+** $xmlString
+*/
+$returnedXMLDoc->fromString($xmlString);
+
+/* Now to verify that the document has been initialised from 
+** the string, we use toString() to output an XML document.
+*/
+
+print $returnedXMLDoc->toString();
+
+/* We can also get the data from the XML using the getValue() 
+** method.  This will return all contents but no meta-data
+** (ie strip the tags).
+*/
+
+print $returnedXMLDoc->getValue();
+
+
+
+/* We can now query the document, fetching elements by name 
+** (and path) or as a list of children.
+**
+** Let's start by fetching the partsRateReply element.
+**
+** WARNING:
+** Normally, you'd be verifying that the element was found
+** but in order to keep this light and to make sure nobody 
+** gets into the habit of good error checking, I'll skip
+** it.
+**
+**
+** getElement() returns the first element with a matching name.
+** if there are multiple elements with the same name, use one
+** of the methods below.
+*/
+
+/* Note: the '=&' operator here is optional: since we won't
+** be modifying the response it doesn't matter if we work on
+** a copy.  
+*/
+$rateResp =& $returnedXMLDoc->getElement('partsRateReply');
+
+/* We can now use the rateResponse element to get access 
+** to it's children.
+*/
+$status =& $rateResp->getElement('status');
+
+$statusMessage =& $status->getElement('message');
+
+print "Status message is " . $statusMessage->getValue() ;
+
+
+/* We can also access the elements by 'path' (if it is unique)
+** To do so, use the getElementByPath method on an element.  The parameter
+** is a path relative to this element (ie you may only access this element
+** and any of it children/subchildren).
+**
+**
+** Here we use the MiniXMLDoc object (thus the root element), so we pass
+** the 'full path' as a parameter.
+*/
+$statusCode = $returnedXMLDoc->getElementByPath('partsRateReply/status/code');
+
+print "Status Code is " . $statusCode->getValue();
+
+/* Sometimes, for instance when you have an element with 
+** multiple children with the same name like partNum, it's 
+** best to simply have access to all the children at once.
+*/
+
+/* First get the element */
+$partList =& $returnedXMLDoc->getElementByPath('partsRateReply/partList');
+
+/* Now get the list of children */
+$partListChildren = $partList->getAllChildren();
+
+/* we can use the returned array to play with all the children */
+for($i=0; $i < $partList->numChildren(); $i++)
+{
+	print "+++++++++++++++++++++++++++++++++++\n";
+	
+	$name = $partListChildren[$i]->getElement('name');
+	$maker = $partListChildren[$i]->getElement('maker');
+	$priceAmmount = $partListChildren[$i]->getElementByPath('price/amount');
+	
+	$partNum = $partListChildren[$i]->attribute('num');
+	
+	print "Part $partNum Name: " . $name->getValue();
+	print "Part $partNum Maker:(" . $maker->attribute('id') . ")  " . $maker->getValue() ;
+	print "Part $partNum Cost: " . $priceAmmount->getValue() ;
+	print "\n\n";
+	
+}
+
+
+
+ + + + +

The output from this code is included below.

+ + + + + + +
+ + + + +
+
+
MiniXML output
+ +fromString($xmlString); + +/* Now to verify that the document has been initialised from +** the string, we use toString() to output an XML document. +*/ + +print "Call to : \$returnedXMLDoc->toString() returns:\n"; + +print htmlentities($returnedXMLDoc->toString()); + +print "Call to : \$returnedXMLDoc->getValue() returns:"; +print "\n\n
" . $returnedXMLDoc->getValue() . "
";
+
+/* We can now query the document, fetching elements by name 
+** (and path) or as a list of children.
+**
+** Let's start by fetching the partsRateReply element.
+** Normally, you'd be verifying that the element was found
+** but in order to keep this light and keep everybody from 
+** getting into the habit of good error checking, I'll skip
+** it.
+**
+** getElement() returns the first element with a matching name.
+** if there are multiple elements with the same name, use one
+** of the methods below.
+*/
+
+/* Note: the '=&' operator here is optional: since we won't
+** be modifying the response it doesn't matter if we work on
+** a copy.  
+*/
+$rateResp =& $returnedXMLDoc->getElement('partsRateReply');
+
+/* We can now use the rateResponse element to get access 
+** to it's children.
+*/
+$status =& $rateResp->getElement('status');
+
+$statusMessage =& $status->getElement('message');
+
+print "
Status message is " . $statusMessage->getValue() . "
\n"; + + +/* We can also access the elements by 'path' (if it is unique) +** To do so, use the getElementByPath method on an element. The parameter +** is a path relative to this element (ie you may only access this element +** and any of it children/subchildren). +** +** +** Here we use the MiniXMLDoc object (thus the root element), so we pass +** the 'full path' as a parameter. +*/ +$statusCode = $returnedXMLDoc->getElementByPath('partsRateReply/status/code'); + +print "
Status Code is " . $statusCode->getValue(). "
\n"; + +/* Sometimes, for instance when you have an element with +** multiple children with the same name like partNum, it's +** best to simply have access to all the children at once. +*/ + +/* First get the element */ +$partList =& $returnedXMLDoc->getElementByPath('partsRateReply/partList'); + +/* Now get the list of children */ +$partListChildren = $partList->getAllChildren('part'); + +/* we can use the returned array to play with all the children */ +for($i=0; $i < $partList->numChildren(); $i++) +{ + print "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
\n"; + + $name = $partListChildren[$i]->getElement('name'); + $maker = $partListChildren[$i]->getElement('maker'); + $priceAmmount = $partListChildren[$i]->getElementByPath('price/amount'); + + $partNum = $partListChildren[$i]->attribute('num'); + + print "Part $partNum Name: " . $name->getValue() . "
\n"; + print "Part $partNum Maker:(" . $maker->attribute('id') . ") " . $maker->getValue() . "
\n"; + print "Part $partNum Cost: " . $priceAmmount->getValue() . "
\n"; + print "\n\n

"; + +} + +?>
+
+ + + Index: aws_xml/includes/minixml/minixml.inc.php =================================================================== RCS file: aws_xml/includes/minixml/minixml.inc.php diff -N aws_xml/includes/minixml/minixml.inc.php --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ aws_xml/includes/minixml/minixml.inc.php 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,171 @@ + and < and & in text, 0 to turn it off */ + + + +define("MINIXML_AUTOSETPARENT", 0); /* Set to 1 to automatically register parents elements with children */ + +define("MINIXML_AVOIDLOOPS", 0); /* Set to 1 to set the default behavior of 'avoidLoops' to ON, 0 otherwise */ + +define("MINIXML_IGNOREWHITESPACES", 1); /* Set to 1 to eliminate leading and trailing whitespaces from strings */ + + +/* Lower/upper case attribute names. Choose UPPER or LOWER or neither - not both... UPPER takes precedence */ +define("MINIXML_UPPERCASEATTRIBUTES", 0); /* Set to 1 to UPPERCASE all attributes, 0 otherwise */ +define("MINIXML_LOWERCASEATTRIBUTES", 0); /* Set to 1 to lowercase all attributes, 0 otherwise */ + + +/* fromFile cache. +** If you are using lots of $xmlDoc->fromFile('path/to/file.xml') calls, it is possible to use +** a caching mechanism. This cache will read the file, store a serialized version of the resulting +** object and read in the serialize object on subsequent calls. +** +** If the original XML file is updated, the cache will automatically be refreshed. +** +** To use caching, set MINIXML_USEFROMFILECACHING to 1 and set the +** MINIXML_FROMFILECACHEDIR to a suitable directory in which the cache files will +** be stored (eg, "/tmp") +**/ +define("MINIXML_USEFROMFILECACHING", 0); +define("MINIXML_FROMFILECACHEDIR", "/tmp"); + + +define("MINIXML_DEBUG", 0); /* Set Debug to 1 for more verbose output, 0 otherwise */ + + +/***************************************** end Configuration ***************************************/ + +define("MINIXML_USE_SIMPLE", 0); + +define("MINIXML_VERSION", "1.3.0"); /* Version information */ + +define("MINIXML_NOWHITESPACES", -999); /* Flag that may be passed to the toString() methods */ + + + +$MiniXMLLocation = dirname(__FILE__); +define("MINIXML_CLASSDIR", "$MiniXMLLocation/classes"); +require_once(MINIXML_CLASSDIR . "/doc.inc.php"); + + +/*************************************************************************************************** +**************************************************************************************************** +***** +***** Global Helper functions +***** +**************************************************************************************************** +***************************************************************************************************/ + + +function _MiniXMLLog ($message) +{ + error_log("MiniXML LOG MESSAGE:\n$message\n"); +} + + + + + +function _MiniXMLError ($message) +{ + error_log("MiniXML ERROR:\n$message\n"); + + return NULL; + +} + + +function _MiniXML_NumKeyArray (&$v) +{ + if (! is_array($v)) + { + return NULL; + } + + + $arrayKeys = array_keys($v); + $numKeys = count($arrayKeys); + $totalNumeric = 0; + for($i=0; $i<$numKeys; $i++) + { + if (is_numeric($arrayKeys[$i]) && $arrayKeys[$i] == $i) + { + $totalNumeric++; + } else { + return 0; + } + } + + if ($totalNumeric == $numKeys) + { + // All numeric - assume it is a "straight" array + return 1; + } else { + return 0; + } +} + + + + + + + +?> Index: aws_xml/includes/minixml/LICENSE =================================================================== RCS file: aws_xml/includes/minixml/LICENSE diff -N aws_xml/includes/minixml/LICENSE --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ aws_xml/includes/minixml/LICENSE 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,368 @@ +This license is included in, and applies to, the MiniXML package, including all +elements of both the PHP version and the XML::Mini perl extension, which are + +Copyright (C) 2002-2003 Patrick Deegan, Psychogenic Inc. +All rights reserved. + + + + + +***README***README***README***README***README***README***README***README***README*** + +Programs that use this code are bound to these terms and conditions - if you wish +to include these modules with or use them within programs released under a different +license (ie not GPL), you need to get a separate commercial license from the authors +at http://www.psychogenic.com + + +***README***README***README***README***README***README***README***README***README*** + + + + + + + + + + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) 19yy + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) 19yy name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. Index: aws_xml/includes/minixml/CHANGELOG =================================================================== RCS file: aws_xml/includes/minixml/CHANGELOG diff -N aws_xml/includes/minixml/CHANGELOG --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ aws_xml/includes/minixml/CHANGELOG 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,18 @@ +Tue Mar 1 03:33:38 EST 2005 + - Major changes to the PHP parser code, fixing important bugs and allow MiniXML + to parse complex docs like NewsML feeds + - Changes to the toArray() function to allow for more complex data to be output + in a rational way + +Mon Mar 31 17:59:56 EST 2003 + - Brought PHP version more up to date with XML::Mini (Perl) implementation + - Split the source into seperate files to aid in maintenance (see the classes directory) + - Created the fromArray()/toArray() functions. This allows for super easy XML creation + and parsing + +Sun Dec 15 12:56:59 EST 2002 - + - Update to Perl version to make XML::Mini more compatible with older Perl installs, + thanks to Nigel Wetters from rivalsdm.com + - Fixes to getElement (inability to fetch nested tags of same name) + - Added the ability to removeChild() and removeAllChildren() for Element objects + - Added the ability to prependChild() and insertChild(CHILD, INDEX) Index: aws_xml/includes/minixml/docs/rsstest.php =================================================================== RCS file: aws_xml/includes/minixml/docs/rsstest.php diff -N aws_xml/includes/minixml/docs/rsstest.php --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ aws_xml/includes/minixml/docs/rsstest.php 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,18 @@ +fromFile('./rsstest.xml'); + +print_r($xmlDoc->toArray()); + +?> Index: aws_xml/aws_xml.info =================================================================== RCS file: aws_xml/aws_xml.info diff -N aws_xml/aws_xml.info --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ aws_xml/aws_xml.info 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,4 @@ +; $Id$ +name = AWS XML API +package = Amazon Web Services +description = Provides a simple API for manipulating XML sent back from Amazon Web Services Index: aws_xml/includes/minixml/docs/README =================================================================== RCS file: aws_xml/includes/minixml/docs/README diff -N aws_xml/includes/minixml/docs/README --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ aws_xml/includes/minixml/docs/README 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,56 @@ +*********************************************************************** +*********************************************************************** +***** +***** MiniXML - PHP classes for generating and parsing XML. +***** +***** Copyright (C) 2002 Patrick Deegan, Psychogenic.com +***** All rights reserved. +***** +***** http://minixml.psychogenic.com +***** +***** This program is free software; you can redistribute +***** it and/or modify it under the terms of the GNU +***** General Public License as published by the Free +***** Software Foundation; either version 2 of the +***** License, or (at your option) any later version. +***** +***** This program is distributed in the hope that it will +***** be useful, but WITHOUT ANY WARRANTY; without even +***** the implied warranty of MERCHANTABILITY or FITNESS +***** FOR A PARTICULAR PURPOSE. See the GNU General +***** Public License for more details. +***** +***** You should have received a copy of the GNU General +***** Public License along with this program; if not, +***** write to the Free Software Foundation, Inc., 675 +***** Mass Ave, Cambridge, MA 02139, USA. +***** +***** +***** You may contact the author, Pat Deegan, through the +***** contact section at http://www.psychogenic.com +***** +***** Much more information on using this API can be found on the +***** official MiniXML website - http://minixml.psychogenic.com +***** +*********************************************************************** +*********************************************************************** + +MiniXML provides a simple API to generating and parsing XML with 2 implementations: +- a 100% PHP implementation +- a set of Perl modules. + +Either of the implementations may be used seperately. + +It's advantages are ease-of-use and the fact that no additional libraries +are required (a single "include"/"use" is all you need). + +MiniXML provides classes for XML documents and elements. + +There is some example PHP and Perl code in the docs directory but the full API, +an overview and example code are all available on the official website at: + +http://minixml.psychogenic.com + +Regards, +Pat Deegan + Index: aws_xml/includes/minixml/docs/test.xml =================================================================== RCS file: aws_xml/includes/minixml/docs/test.xml diff -N aws_xml/includes/minixml/docs/test.xml --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ aws_xml/includes/minixml/docs/test.xml 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,243 @@ + + + + + 20040602T085510Z + + + + + afp.com + 20040602 + 040602085459.e508mtfk + 1 + urn:newsml:afp.com:20040602:040602085459.e508mtfk:1 + + Iraq-US + + + + 20040602T085459Z + 20040602T085459Z + + + + + Iraqi cabinet readies for transition, draft UN resolution boosts sovereignty + + BAGHDAD (AFP) + © 2004 AFP + + + + + + + + + + + + + + + + + + + +

The newly-appointed Iraqi government began preparing for full sovereignty handover from US-led occupation authorities at the end of the month, and received a boost from a new US-British UN resolution draft giving it increased security control.

+ +

While coalition officials hailed the diversity of the line-up presented Tuesday by prime minister Iyad Allawi, some Iraqis were dismissive of a cabinet consisting chiefly of former exiles.

+

UN envoy Lakhdar Brahimi, who had been entrusted with the nomination process and came under pressure from all sides, fell short of his plan to select a government which would be both popular and at the same time willing to work closely with the coalition.

+

UN chief Kofi Annan could not disguise his displeasure that Brahimi was frozen out of the process by Iraqi and US officials opposed to his vision for a technocratic government.

+

"We all have to recognise that the process wasn't perfect," Annan said Tuesday.

+

Brahimi himself stressed on Wednesday at a press conference that the leaders were not elected and would have their work cut out to gain legitimacy. "It will not be easy for them to prove the sceptics wrong," he said.

+

Kurdish leaders took plum posts in the government and tribal leader Ghazi al-Yawar was named president after elder statesman Adnan Pachachi refused the post.

+

The US-backed Allawi hailed the nomination of the new government as an historic step towards sovereignty but showed no sign of rushing to ease the coalition out of Iraq.

+ + + +

"We Iraqis are just like the rest of the peoples in the world. We don't want our country to remain under occupation," he said but then went on to stress that Baghdad would still rely heavily on the US-led coalition.

+ +

"We are seeking to be able to deal in the best possible way with the terrorism and security threats by ourselves but because of the situation prevailing it appears to be impossible and we will need the help and support of the multinational forces to defeat the enemies of Iraq, who don't want stability, freedom and prosperity for us," he explained.

+

At the United Nations, changes were made to a UN Security Council resolution sponsored by Britain and the United States after an outcry from other council nations about sending a clear signal that Iraq will gain full sovereignty when the US-led occupation on June 30 hands power to the interim government.

+

Under the new draft, obtained by AFP, the mandate of US-led troops who will remain in Iraq after this month would expire "upon completion of the political process" to create a constitutionally elected Iraqi government.

+

But with that expected to take until late 2005 or even early 2006, it was not immediately clear if the changes would satisfy opposition to the first text led by China, France and Germany.

+

And the draft still fails to clarify the level of sovereignty the Iraqi leadership will enjoy after June 30, in the run-up to elections next year.

+ + + +

Iraq's interim foreign minister Hoshyar Zebari who flew to New York on Tuesday was expected to meet Security Council members on Thursday.

+ +

The new government was greeted Tuesday by a new surge of violence on the ground, with car bombs in Baghdad and the northern town of Bayji killing a total of 14.

+

Fresh fighting broke out between members of radical Shiite cleric Moqtada Sadr's militia and US forces, leaving eight Iraqi fighters dead and 23 wounded, medical sources said.

+

One was killed and 12 wounded near a US base in Najaf, while five were killed and 11 wounded in the twin city of Kufa.

+

In the Baghdad neighbourhood of Sadr City, two militiamen were also killed by US troops, Sadr's office said.

+

The renewed bloodshed came a day after the governor of Najaf announced 72-hour truce between the two sides.

+

Meanwhile, three coalition soldiers were wounded near the town of Kish, south of Baghdad, when gunmen ambushed a group of soldiers on their way to the inauguration of a local school, said the Polish command in the region.

+
+
+
+ + + Iraqis stand on a pavement in Baghdad to read headlines about the new government + + + + + + + + + + + + + + + +

Iraqis stand on a pavement in Baghdad reading the newspaper headlines a day after the first post-Saddam Hussein era government was unveiled

+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + Iraqi's at a Baghdad coffee shop watch the installing of the new government + + + + + + + + + + + + + + + +

An Iraqi man points at the television in a Baghdad coffee shop showing the new President of Iraq Sheikh Ghazi al-Yawar speaking during the official ceremony installing a new interim government. The US-led occupation force in Iraq dissolved the Governing Council which it set up after toppling Saddam Hussein 14 months ago and installed a new interim government as the UN Security Council prepared to debate a resolution on the country's future

+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + Fighter of radical Shiite Muslim cleric Moqtada Sadr's Mehdi Army runs down a street during clashes with US troops + + + + + + + + + + + + + + + +

A fighter of radical Shiite Muslim cleric Moqtada Sadr's Mehdi Army runs down a street during clashes with US troops in the town of Kufa, a few kilometers away from the holy city of Najaf south of Baghdad

+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
Index: aws_xml/includes/minixml/classes/element.inc.php =================================================================== RCS file: aws_xml/includes/minixml/classes/element.inc.php diff -N aws_xml/includes/minixml/classes/element.inc.php --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ aws_xml/includes/minixml/classes/element.inc.php 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,1759 @@ + 0) +**/ + +class MiniXMLElement extends MiniXMLTreeComponent { + + + var $xname; + var $xattributes; + var $xchildren; + var $xnumChildren; + var $xnumElementChildren; + + var $xavoidLoops = MINIXML_AVOIDLOOPS; + + + /* MiniXMLElement NAME + ** Creates and inits a new MiniXMLElement + */ + function MiniXMLElement ($name=NULL) + { + $this->MiniXMLTreeComponent(); + $this->xname = NULL; + $this->xattributes = array(); + $this->xchildren = array(); + $this->xnumChildren = 0; + $this->xnumElementChildren = 0; + if ($name) + { + $this->name($name); + } else { + return _MiniXMLError("MiniXMLElement Constructor: must pass a name to constructor"); + } + } /* end method MiniXMLElement */ + + + /**************** Get/set methods for MiniXMLElement data *****************/ + + + /* name [NEWNAME] + ** + ** If a NEWNAME string is passed, the MiniXMLElement's name is set + ** to NEWNAME. + ** + ** Returns the element's name. + */ + function name ($setTo=NULL) + { + if (! is_null($setTo)) + { + if (! is_string($setTo)) + { + return _MiniXMLError("MiniXMLElement::name() Must pass a STRING to method to set name"); + } + + $this->xname = $setTo; + } + + return $this->xname; + + } /* end method name */ + + + + /* attribute NAME [SETTO [SETTOALT]] + ** + ** The attribute() method is used to get and set the + ** MiniXMLElement's attributes (ie the name/value pairs contained + ** within the tag, ) + ** + ** If SETTO is passed, the attribute's value is set to SETTO. + ** + ** If the optional SETTOALT is passed and SETTO is false, the + ** attribute's value is set to SETTOALT. This is usefull in cases + ** when you wish to set the attribute to a default value if no SETTO is + ** present, eg $myelement->attribute('href', $theHref, 'http://psychogenic.com') + ** will default to 'http://psychogenic.com'. + ** + ** Note: if the MINIXML_LOWERCASEATTRIBUTES define is > 0, all attribute names + ** will be lowercased (while setting and during retrieval) + ** + ** Returns the value associated with attribute NAME. + ** + */ + function attribute ($name, $primValue=NULL, $altValue=NULL) + { + $value = (is_null($primValue) ? $altValue : $primValue ); + + + if (MINIXML_UPPERCASEATTRIBUTES > 0) + { + $name = strtoupper($name); + } elseif (MINIXML_LOWERCASEATTRIBUTES > 0) + { + $name = strtolower($name); + } + + if (! is_null($value)) + { + + $this->xattributes[$name] = $value; + } + + if (! is_null($this->xattributes[$name])) + { + return $this->xattributes[$name]; + } else { + return NULL; + } + + } /* end method attribute */ + + + /* text [SETTO [SETTOALT]] + ** + ** The text() method is used to get or append text data to this + ** element (it is appended to the child list as a new MiniXMLNode object). + ** + ** If SETTO is passed, a new node is created, filled with SETTO + ** and appended to the list of this element's children. + ** + ** If the optional SETTOALT is passed and SETTO is false, the + ** new node's value is set to SETTOALT. See the attribute() method + ** for an example use. + ** + ** Returns a string composed of all child MiniXMLNodes' contents. + ** + ** Note: all the children MiniXMLNodes' contents - including numeric + ** nodes are included in the return string. + */ + function text ($setToPrimary = NULL, $setToAlternate=NULL) + { + $setTo = ($setToPrimary ? $setToPrimary : $setToAlternate); + + if (! is_null($setTo)) + { + $this->createNode($setTo); + } + + $retString = ''; + + /* Extract text from all child nodes */ + for($i=0; $i< $this->xnumChildren; $i++) + { + if ($this->isNode($this->xchildren[$i])) + { + $nodeTxt = $this->xchildren[$i]->getValue(); + if (! is_null($nodeTxt)) + { + $retString .= "$nodeTxt "; + + } /* end if text returned */ + + } /* end if this is a MiniXMLNode */ + + } /* end loop over all children */ + + return $retString; + + } /* end method text */ + + + + /* numeric [SETTO [SETTOALT]] + ** + ** The numeric() method is used to get or append numeric data to + ** this element (it is appended to the child list as a MiniXMLNode object). + ** + ** If SETTO is passed, a new node is created, filled with SETTO + ** and appended to the list of this element's children. + ** + ** If the optional SETTOALT is passed and SETTO is false, the + ** new node's value is set to SETTOALT. See the attribute() method + ** for an example use. + ** + ** Returns a space seperated string composed all child MiniXMLNodes' + ** numeric contents. + ** + ** Note: ONLY numerical contents are included from the list of child MiniXMLNodes. + ** + */ + function numeric ($setToPrimary = NULL, $setToAlternate=NULL) + { + $setTo = (is_null($setToPrimary) ? $setToAlternate : $setToPrimary); + + if (! is_null($setTo)) + { + $this->createNode($setTo); + } + + } /* end method numeric */ + + + /* comment CONTENTS + ** + ** The comment() method allows you to add a new MiniXMLElementComment to this + ** element's list of children. + ** + ** Comments will return a string when the element's toString() + ** method is called. + ** + ** Returns a reference to the newly appended MiniXMLElementComment + ** + */ + function & comment ($contents) + { + $newEl = new MiniXMLElementComment(); + + $appendedComment =& $this->appendChild($newEl); + $appendedComment->text($contents); + + return $appendedComment; + + } /* end method comment */ + + + + + + + + /* + ** docType DEFINITION + ** + ** Append a new element as a child of this + ** element. + ** + ** Returns the appended DOCTYPE element. You will normally use the returned + ** element to add ENTITY elements, like + + ** $newDocType =& $xmlRoot->docType('spec SYSTEM "spec.dtd"'); + ** $newDocType->entity('doc.audience', 'public review and discussion'); + */ + + function & docType ($definition) + { + + $newElement = new MiniXMLElementDocType($definition); + $appendedElement =& $this->appendChild($newElement); + + return $appendedElement; + } + /* + ** entity NAME VALUE + ** + ** Append a new element as a child of this + ** element. + + ** Returns the appended ENTITY element. + */ + function & entity ($name,$value) + { + + $newElement = new MiniXMLElementEntity($name, $value); + $appendedEl =& $this->appendChild($newElement); + + return $appendedEl; + } + + + /* + ** cdata CONTENTS + ** + ** Append a new element as a child of this element. + ** Returns the appended CDATA element. + ** + */ + + function & cdata ($contents) + { + $newElement = new MiniXMLElementCData($contents); + $appendedChild =& $this->appendChild($newElement); + + return $appendedChild; + } + + + /* getValue + ** + ** Returns a string containing the value of all the element's + ** child MiniXMLNodes (and all the MiniXMLNodes contained within + ** it's child MiniXMLElements, recursively). + ** + ** Note: the seperator parameter remains officially undocumented + ** since I'm not sure it will remain part of the API + */ + function getValue ($seperator=' ') + { + $retStr = ''; + $valArray = array(); + for($i=0; $i < $this->xnumChildren; $i++) + { + $value = $this->xchildren[$i]->getValue(); + if (! is_null($value)) + { + array_push($valArray, $value); + } + } + if (count($valArray)) + { + $retStr = implode($seperator, $valArray); + } + return $retStr; + + } /* end method getValue */ + + + + /* getElement NAME + ** Searches the element and it's children for an element with name NAME. + ** + ** Returns a reference to the first MiniXMLElement with name NAME, + ** if found, NULL otherwise. + ** + ** NOTE: The search is performed like this, returning the first + ** element that matches: + ** + ** - Check this element for a match + ** - Check this element's immediate children (in order) for a match. + ** - Ask each immediate child (in order) to MiniXMLElement::getElement() + ** (each child will then proceed similarly, checking all it's immediate + ** children in order and then asking them to getElement()) + */ + function &getElement ($name) + { + + if (MINIXML_DEBUG > 0) + { + $elname = $this->name(); + _MiniXMLLog("MiniXMLElement::getElement() called for $name on $elname."); + } + if (is_null($name)) + { + return _MiniXMLError("MiniXMLElement::getElement() Must Pass Element name."); + } + + + /** Must only check children as checking $this results in an inability to + *** fetch nested objects with the same name + *** + *** + *** + *** Can't get here from tag or from the first 'nested' + *** + *** + *** + if (MINIXML_CASESENSITIVE > 0) + { + if (strcmp($this->xname, $name) == 0) + { + /* This element is it * / + return $this; + } + } else { + + if (strcasecmp($this->xname,$name) == 0) + { + return $this; + } + } + + ***** end commented out section **** + */ + + if (! $this->xnumChildren ) + { + /* Not match here and and no kids - not found... */ + return NULL; + } + + /* Try each child (immediate children take priority) */ + for ($i = 0; $i < $this->xnumChildren; $i++) + { + $childname = $this->xchildren[$i]->name(); + if ($childname) + { + if (MINIXML_CASESENSITIVE > 0) + { + /* case sensitive matches only */ + if (strcmp($name, $childname) == 0) + { + return $this->xchildren[$i]; + } + } else { + /* case INsensitive matching */ + if (strcasecmp($name, $childname) == 0) + { + return $this->xchildren[$i]; + } + } /* end if case sensitive */ + } /* end if child has a name */ + + } /* end loop over all my children */ + + /* Use beautiful recursion, daniel san */ + for ($i = 0; $i < $this->xnumChildren; $i++) + { + $theelement =& $this->xchildren[$i]->getElement($name); + if ($theelement) + { + if (MINIXML_DEBUG > 0) + { + _MiniXMLLog("MiniXMLElement::getElement() returning element $theelement"); + } + return $theelement; + } + } + + /* Not found */ + return NULL; + + + } /* end method getElement */ + + + /* getElementByPath PATH + ** Attempts to return a reference to the (first) element at PATH + ** where PATH is the path in the structure (relative to this element) to + ** the requested element. + ** + ** For example, in the document represented by: + ** + ** + ** + ** + ** + ** + ** + ** DA42 + ** + ** + ** D99983FFF + ** + ** + ** ss-839uent + ** + ** + ** + ** + ** $partRate =& $xmlDocument->getElement('partRateRequest'); + ** + ** $accessid =& $partRate->getElementByPath('vendor/accessid'); + ** + ** Will return what you expect (the accessid element with attributes user = "myusername" + ** and password = "mypassword"). + ** + ** BUT be careful: + ** $accessid =& $partRate->getElementByPath('partList/partNum'); + ** + ** will return the partNum element with the value "DA42". Other partNums are + ** inaccessible by getElementByPath() - Use MiniXMLElement::getAllChildren() instead. + ** + ** Returns the MiniXMLElement reference if found, NULL otherwise. + */ + function &getElementByPath($path) + { + $names = split ("/", $path); + + $element = $this; + foreach ($names as $elementName) + { + if ($element && $elementName) /* Make sure we didn't hit a dead end and that we have a name*/ + { + /* Ask this element to get the next child in path */ + $element =& $element->getElement($elementName); + } + } + + return $element; + + } /* end method getElementByPath */ + + + + /* numChildren [NAMED] + ** + ** Returns the number of immediate children for this element + ** + ** If the optional NAMED parameter is passed, returns only the + ** number of immediate children named NAMED. + */ + function numChildren ($named=NULL) + { + if (is_null($named)) + { + return $this->xnumElementChildren; + } + + /* We require only children named '$named' */ + $allkids =& $this->getAllChildren($named); + + return count($allkids); + + + } + + + /* getAllChildren [NAME] + ** + ** Returns a reference to an array of all this element's MiniXMLElement children + ** + ** Note: although the MiniXMLElement may contain MiniXMLNodes as children, these are + ** not part of the returned list. + **/ + function &getAllChildren ($name=NULL) + { + $retArray = array(); + $count = 0; + + if (is_null($name)) + { + /* Return all element children */ + for($i=0; $i < $this->xnumChildren; $i++) + { + if (method_exists($this->xchildren[$i], 'MiniXMLElement')) + { + $retArray[$count++] =& $this->xchildren[$i]; + } + } + } else { + /* Return only element children with name $name */ + + for($i=0; $i < $this->xnumChildren; $i++) + { + if (method_exists($this->xchildren[$i], 'MiniXMLElement')) + { + if (MINIXML_CASESENSITIVE > 0) + { + if ($this->xchildren[$i]->name() == $name) + { + $retArray[$count++] =& $this->xchildren[$i]; + } + } else { + if (strcasecmp($this->xchildren[$i]->name(), $name) == 0) + { + $retArray[$count++] =& $this->xchildren[$i]; + } + } /* end if case sensitive */ + + } /* end if child is a MiniXMLElement object */ + + } /* end loop over all children */ + + } /* end if specific name was requested */ + + return $retArray; + + } /* end method getAllChildren */ + + + + function &insertChild (&$child, $idx=0) + { + + + + if (! $this->_validateChild($child)) + { + return; + } + + /* Set the parent for the child element to this element if + ** avoidLoops or MINIXML_AUTOSETPARENT is set + */ + if ($this->xavoidLoops || (MINIXML_AUTOSETPARENT > 0) ) + { + if ($this->xparent == $child) + { + + $cname = $child->name(); + return _MiniXMLError("MiniXMLElement::insertChild() Tryng to append parent $cname as child of " + . $this->xname ); + } + $child->parent($this); + } + + + $nextIdx = $this->xnumChildren; + $lastIdx = $nextIdx - 1; + if ($idx > $lastIdx) + { + + if ($idx > $nextIdx) + { + $idx = $lastIdx + 1; + } + $this->xchildren[$idx] = $child; + $this->xnumChildren++; + if ($this->isElement($child)) + { + $this->xnumElementChildren++; + } + + } elseif ($idx >= 0) + { + + $removed = array_splice($this->xchildren, $idx); + array_push($this->xchildren, $child); + $numRemoved = count($removed); + + for($i=0; $i<$numRemoved; $i++) + { + + array_push($this->xchildren, $removed[$i]); + } + $this->xnumChildren++; + if ($this->isElement($child)) + { + $this->xnumElementChildren++; + } + + + } else { + $revIdx = (-1 * $idx) % $this->xnumChildren; + $newIdx = $this->xnumChildren - $revIdx; + + if ($newIdx < 0) + { + return _MiniXMLError("Element::insertChild() Ended up with a negative index? ($newIdx)"); + } + + return $this->insertChild($child, $newIdx); + } + + return $child; + } + + + /* appendChild CHILDELEMENT + ** + ** appendChild is used to append an existing MiniXMLElement object to + ** this element's list. + ** + ** Returns a reference to the appended child element. + ** + ** NOTE: Be careful not to create loops in the hierarchy, eg + ** $parent->appendChild($child); + ** $child->appendChild($subChild); + ** $subChild->appendChild($parent); + ** + ** If you want to be sure to avoid loops, set the MINIXML_AVOIDLOOPS define + ** to 1 or use the avoidLoops() method (will apply to all children added with createChild()) + */ + function &appendChild (&$child) + { + + if (! $this->_validateChild($child)) + { + _MiniXMLLog("MiniXMLElement::appendChild() Could not validate child, aborting append"); + return NULL; + } + + /* Set the parent for the child element to this element if + ** avoidLoops or MINIXML_AUTOSETPARENT is set + */ + if ($this->xavoidLoops || (MINIXML_AUTOSETPARENT > 0) ) + { + if ($this->xparent == $child) + { + + $cname = $child->name(); + return _MiniXMLError("MiniXMLElement::appendChild() Tryng to append parent $cname as child of " + . $this->xname ); + } + $child->parent($this); + } + + + $this->xnumElementChildren++; /* Note that we're addind a MiniXMLElement child */ + + /* Add the child to the list */ + $idx = $this->xnumChildren++; + $this->xchildren[$idx] =& $child; + + return $this->xchildren[$idx]; + + } /* end method appendChild */ + + + /* prependChild CHILDELEMENT + ** + ** prependChild is used to prepend an existing MiniXMLElement object to + ** this element's list. The child will be positioned at the begining of + ** the elements child list, thus it will be output first in the resulting XML. + ** + ** Returns a reference to the prepended child element. + */ + function &prependChild ($child) + { + + + if (! $this->_validateChild($child)) + { + _MiniXMLLog("MiniXMLElement::prependChild - Could not validate child, aborting."); + return NULL; + } + + /* Set the parent for the child element to this element if + ** avoidLoops or MINIXML_AUTOSETPARENT is set + */ + if ($this->xavoidLoops || (MINIXML_AUTOSETPARENT > 0) ) + { + if ($this->xparent == $child) + { + + $cname = $child->name(); + return _MiniXMLError("MiniXMLElement::prependChild() Tryng to append parent $cname as child of " + . $this->xname ); + } + $child->parent($this); + } + + + $this->xnumElementChildren++; /* Note that we're adding a MiniXMLElement child */ + + /* Add the child to the list */ + $idx = $this->xnumChildren++; + array_unshift($this->xchildren, $child); + return $this->xchildren[0]; + + } /* end method prependChild */ + + function _validateChild (&$child) + { + + if (is_null($child)) + { + return _MiniXMLError("MiniXMLElement::_validateChild() need to pass a non-NULL MiniXMLElement child."); + } + + if (! method_exists($child, 'MiniXMLElement')) + { + return _MiniXMLError("MiniXMLElement::_validateChild() must pass a MiniXMLElement object to _validateChild."); + } + + /* Make sure element is named */ + $cname = $child->name(); + if (is_null($cname)) + { + _MiniXMLLog("MiniXMLElement::_validateChild() children must be named"); + return 0; + } + + + /* Check for loops */ + if ($child == $this) + { + _MiniXMLLog("MiniXMLElement::_validateChild() Trying to append self as own child!"); + return 0; + } elseif ( $this->xavoidLoops && $child->parent()) + { + _MiniXMLLog("MiniXMLElement::_validateChild() Trying to append a child ($cname) that already has a parent set " + . "while avoidLoops is on - aborting"); + return 0; + } + + return 1; + } + /* createChild ELEMENTNAME [VALUE] + ** + ** Creates a new MiniXMLElement instance and appends it to the list + ** of this element's children. + ** The new child element's name is set to ELEMENTNAME. + ** + ** If the optional VALUE (string or numeric) parameter is passed, + ** the new element's text/numeric content will be set using VALUE. + ** + ** Returns a reference to the new child element + ** + ** Note: don't forget to use the =& (reference assignment) operator + ** when calling createChild: + ** + ** $newChild =& $myElement->createChild('newChildName'); + ** + */ + function & createChild ($name, $value=NULL) + { + if (! $name) + { + return _MiniXMLError("MiniXMLElement::createChild() Must pass a NAME to createChild."); + } + + if (! is_string($name)) + { + return _MiniXMLError("MiniXMLElement::createChild() Name of child must be a STRING"); + } + + $child = new MiniXMLElement($name); + + $appendedChild =& $this->appendChild($child); + + if (! $appendedChild ) + { + _MiniXMLLog("MiniXMLElement::createChild() '$name' child NOT appended."); + return NULL; + } + + if (! is_null($value)) + { + if (is_numeric($value)) + { + $appendedChild->numeric($value); + } elseif (is_string($value)) + { + $appendedChild->text($value); + } + } + + $appendedChild->avoidLoops($this->xavoidLoops); + + return $appendedChild; + + } /* end method createChild */ + + + + /* removeChild CHILD + ** Removes CHILD from this element's list of children. + ** + ** Returns the removed child, if found, NULL otherwise. + */ + + function &removeChild (&$child) + { + if (! $this->xnumChildren) + { + if (MINIXML_DEBUG > 0) + { + _MiniXMLLog("Element::removeChild() called for element without any children.") ; + } + return NULL; + } + + $foundChild = NULL; + $idx = 0; + while ($idx < $this->xnumChildren && ! $foundChild) + { + if ($this->xchildren[$idx] == $child) + { + $foundChild =& $this->xchildren[$idx]; + } else { + $idx++; + } + } + + if (! $foundChild) + { + if (MINIXML_DEBUG > 0) + { + _MiniXMLLog("Element::removeChild() No matching child found.") ; + } + return NULL; + } + + array_splice($this->xchildren, $idx, 1); + + $this->xnumChildren--; + if ($this->isElement($foundChild)) + { + $this->xnumElementChildren--; + } + + unset ($foundChild->xparent) ; + return $foundChild; + } + + + /* removeAllChildren + ** Removes all children of this element. + ** + ** Returns an array of the removed children (which may be empty) + */ + function &removeAllChildren () + { + $emptyArray = array(); + + if (! $this->xnumChildren) + { + return $emptyArray; + } + + $retList =& $this->xchildren; + + $idx = 0; + while ($idx < $this->xnumChildren) + { + unset ($retList[$idx++]->xparent); + } + + $this->xchildren = array(); + $this->xnumElementChildren = 0; + $this->xnumChildren = 0; + + + return $retList; + } + + + function & remove () + { + $parent =& $this->parent(); + + if (!$parent) + { + _MiniXMLLog("XML::Mini::Element::remove() called for element with no parent set. Aborting."); + return NULL; + } + + $removed =& $parent->removeChild($this); + + return $removed; + } + + + + /* parent NEWPARENT + ** + ** The parent() method is used to get/set the element's parent. + ** + ** If the NEWPARENT parameter is passed, sets the parent to NEWPARENT + ** (NEWPARENT must be an instance of MiniXMLElement) + ** + ** Returns a reference to the parent MiniXMLElement if set, NULL otherwise. + ** + ** Note: This method is mainly used internally and you wouldn't normally need + ** to use it. + ** It get's called on element appends when MINIXML_AUTOSETPARENT or + ** MINIXML_AVOIDLOOPS or avoidLoops() > 1 + ** + */ + function &parent (&$setParent) + { + if (! is_null($setParent)) + { + /* Parents can only be MiniXMLElement objects */ + if (! $this->isElement($setParent)) + { + return _MiniXMLError("MiniXMLElement::parent(): Must pass an instance of MiniXMLElement to set."); + } + $this->xparent = $setParent; + } + + return $this->xparent; + + } /* end method parent */ + + + /* avoidLoops SETTO + ** + ** The avoidLoops() method is used to get or set the avoidLoops flag for this element. + ** + ** When avoidLoops is true, children with parents already set can NOT be appended to any + ** other elements. This is overkill but it is a quick and easy way to avoid infinite loops + ** in the heirarchy. + ** + ** The avoidLoops default behavior is configured with the MINIXML_AVOIDLOOPS define but can be + ** set on individual elements (and automagically all the element's children) with the + ** avoidLoops() method. + ** + ** Returns the current value of the avoidLoops flag for the element. + ** + */ + function avoidLoops ($setTo = NULL) + { + if (! is_null($setTo)) + { + $this->xavoidLoops = $setTo; + } + + return $this->xavoidLoops; + } + + + /* toString [SPACEOFFSET] + ** + ** toString returns an XML string based on the element's attributes, + ** and content (recursively doing the same for all children) + ** + ** The optional SPACEOFFSET parameter sets the number of spaces to use + ** after newlines for elements at this level (adding 1 space per level in + ** depth). SPACEOFFSET defaults to 0. + ** + ** If SPACEOFFSET is passed as MINIXML_NOWHITESPACES. + ** no \n or whitespaces will be inserted in the xml string + ** (ie it will all be on a single line with no spaces between the tags. + ** + ** Returns the XML string. + ** + ** + ** Note: Since the toString() method recurses into child elements and because + ** of the MINIXML_NOWHITESPACES and our desire to avoid testing for this value + ** on every element (as it does not change), here we split up the toString method + ** into 2 subs: toStringWithWhiteSpaces(DEPTH) and toStringNoWhiteSpaces(). + ** + ** Each of these methods, which are to be considered private (?), in turn recurses + ** calling the appropriate With/No WhiteSpaces toString on it's children - thereby + ** avoiding the test on SPACEOFFSET + */ + + function toString ($depth=0) + { + if ($depth == MINIXML_NOWHITESPACES) + { + return $this->toStringNoWhiteSpaces(); + } else { + return $this->toStringWithWhiteSpaces($depth); + } + } + + function toStringWithWhiteSpaces ($depth=0) + { + $attribString = ''; + $elementName = $this->xname; + $spaces = $this->_spaceStr($depth) ; + + $retString = "$spaces<$elementName"; + + + foreach ($this->xattributes as $attrname => $attrvalue) + { + $attribString .= "$attrname=\"$attrvalue\" "; + } + + + if ($attribString) + { + $attribString = rtrim($attribString); + $retString .= " $attribString"; + } + + if (! $this->xnumChildren) + { + /* No kids -> no sub-elements, no text, nothing - consider a element */ + $retString .= " />\n"; + + return $retString; + } + + + + /* If we've gotten this far, the element has + ** kids or text - consider a otherstuff element + */ + + $onlyTxtChild = 0; + if ($this->xnumChildren == 1 && ! $this->xnumElementChildren) + { + $onlyTxtChild = 1; + } + + + + if ($onlyTxtChild) + { + $nextDepth = 0; + $retString .= "> "; + } else { + $nextDepth = $depth+1; + $retString .= ">\n"; + } + + + + for ($i=0; $i < $this->xnumChildren ; $i++) + { + if (method_exists($this->xchildren[$i], 'toStringWithWhiteSpaces') ) + { + + $newStr = $this->xchildren[$i]->toStringWithWhiteSpaces($nextDepth); + + + if (! is_null($newStr)) + { + if (! ( preg_match("/\n\$/", $newStr) || $onlyTxtChild) ) + { + $newStr .= "\n"; + } + + $retString .= $newStr; + } + + } else { + _MiniXMLLog("Invalid child found in $elementName ". $this->xchildren[$i]->name() ); + + } /* end if has a toString method */ + + } /* end loop over all children */ + + /* add the indented closing tag */ + if ($onlyTxtChild) + { + $retString .= " \n"; + } else { + $retString .= "$spaces\n"; + } + return $retString; + + } /* end method toString */ + + + + + function toStringNoWhiteSpaces () + { + $retString = ''; + $attribString = ''; + $elementName = $this->xname; + + foreach ($this->xattributes as $attrname => $attrvalue) + { + $attribString .= "$attrname=\"$attrvalue\" "; + } + + $retString = "<$elementName"; + + + if ($attribString) + { + $attribString = rtrim($attribString); + $retString .= " $attribString"; + } + + if (! $this->xnumChildren) + { + /* No kids -> no sub-elements, no text, nothing - consider a element */ + + $retString .= " />"; + return $retString; + } + + + /* If we've gotten this far, the element has + ** kids or text - consider a otherstuff element + */ + $retString .= ">"; + + /* Loop over all kids, getting associated strings */ + for ($i=0; $i < $this->xnumChildren ; $i++) + { + if (method_exists($this->xchildren[$i], 'toStringNoWhiteSpaces') ) + { + $newStr = $this->xchildren[$i]->toStringNoWhiteSpaces(); + + if (! is_null($newStr)) + { + $retString .= $newStr; + } + + } else { + _MiniXMLLog("Invalid child found in $elementName"); + + } /* end if has a toString method */ + + } /* end loop over all children */ + + /* add the indented closing tag */ + $retString .= ""; + + return $retString; + + } /* end method toStringNoWhiteSpaces */ + + + /* toStructure + ** + ** Converts an element to a structure - either an array or a simple string. + ** + ** This method is used by MiniXML documents to perform their toArray() magic. + */ + function & toStructure () + { + + $retHash = array(); + $contents = ""; + $numAdded = 0; + + + + for($i=0; $i< $this->xnumChildren; $i++) + { + if ($this->isElement($this->xchildren[$i])) + { + $name = $this->xchildren[$i]->name(); + + if (array_key_exists($name, $retHash)) + + { + if (! (is_array($retHash[$name]) && array_key_exists('_num', $retHash[$name])) ) + { + $retHash[$name] = array($retHash[$name], + $this->xchildren[$i]->toStructure()); + + $retHash[$name]['_num'] = 2; + } else { + array_push($retHash[$name], $this->xchildren[$i]->toStructure() ); + + $retHash[$name]['_num']++; + } + } else { + $retHash[$name] = $this->xchildren[$i]->toStructure(); + } + + $numAdded++; + } else { + $contents .= $this->xchildren[$i]->getValue(); + } + + + } + + + foreach ($this->xattributes as $attrname => $attrvalue) + { + #array_push($retHash, array($attrname => $attrvalue)); + $retHash["_attributes"][$attrname] = $attrvalue; + $numAdded++; + } + + + if ($numAdded) + { + if (! empty($contents)) + { + $retHash['_content'] = $contents; + } + + return $retHash; + } else { + return $contents; + } + + } // end toStructure() method + + + + + + /* isElement ELEMENT + ** Returns a true value if ELEMENT is an instance of MiniXMLElement, + ** false otherwise. + ** + ** Note: Used internally. + */ + function isElement (&$testme) + { + if (is_null($testme)) + { + return 0; + } + + return method_exists($testme, 'MiniXMLElement'); + } + + + /* isNode NODE + ** Returns a true value if NODE is an instance of MiniXMLNode, + ** false otherwise. + ** + ** Note: used internally. + */ + function isNode (&$testme) + { + if (is_null($testme)) + { + return 0; + } + + return method_exists($testme, 'MiniXMLNode'); + } + + + /* createNode NODEVALUE [ESCAPEENTITIES] + ** + ** Private (?) + ** + ** Creates a new MiniXMLNode instance and appends it to the list + ** of this element's children. + ** The new child node's value is set to NODEVALUE. + ** + ** Returns a reference to the new child node. + ** + ** Note: You don't need to use this method normally - it is used + ** internally when appending text() and such data. + ** + */ + function & createNode (&$value, $escapeEntities=NULL) + { + + $newNode = new MiniXMLNode($value, $escapeEntities); + + $appendedNode =& $this->appendNode($newNode); + + return $appendedNode; + } + + + /* appendNode CHILDNODE + ** + ** appendNode is used to append an existing MiniXMLNode object to + ** this element's list. + ** + ** Returns a reference to the appended child node. + ** + ** + ** Note: You don't need to use this method normally - it is used + ** internally when appending text() and such data. + */ + function &appendNode (&$node) + { + if (is_null($node)) + { + return _MiniXMLError("MiniXMLElement::appendNode() need to pass a non-NULL MiniXMLNode."); + } + + + if (! method_exists($node, 'MiniXMLNode')) + { + return _MiniXMLError("MiniXMLElement::appendNode() must pass a MiniXMLNode object to appendNode."); + } + + if (MINIXML_AUTOSETPARENT) + { + if ($this->xparent == $node) + { + return _MiniXMLError("MiniXMLElement::appendnode() Tryng to append parent $cname as node of " + . $this->xname ); + } + $node->parent($this); + } + + + $idx = $this->xnumChildren++; + $this->xchildren[$idx] = $node; + + return $this->xchildren[$idx]; + + + } + + /* Destructor to keep things clean -- patch by Ilya */ + function __destruct() + { + for ($i = 0; $i < count($this->xchildren); ++$i) + $this->xchildren[$i]->xparent = null; + } + + +} /* end MiniXMLElement class definition */ + + + + + + +/*************************************************************************************************** +**************************************************************************************************** +***** +***** MiniXMLElementComment +***** +**************************************************************************************************** +***************************************************************************************************/ + +/* The MiniXMLElementComment class is a specific extension of the MiniXMLElement class. +** +** It is used to create the special tags and an instance in created when calling +** $elementObject->comment('this is a comment'); +** +** It's methods are the same as for MiniXMLElement - see those for documentation. +**/ + +class MiniXMLElementComment extends MiniXMLElement { + + function MiniXMLElementComment ($name=NULL) + { + $this->MiniXMLElement('!--'); + } + + + function toString ($depth=0) + { + if ($depth == MINIXML_NOWHITESPACES) + { + return $this->toStringNoWhiteSpaces(); + } else { + return $this->toStringWithWhiteSpaces($depth); + } + } + + + function toStringWithWhiteSpaces ($depth=0) + { + + $spaces = $this->_spaceStr($depth) ; + + $retString = "$spaces\n"; + + return $retString; + } + + /* If we get here, the element does have children... get their contents */ + + $nextDepth = $depth+1; + + for ($i=0; $i < $this->xnumChildren ; $i++) + { + $retString .= $this->xchildren[$i]->toStringWithWhiteSpaces($nextDepth); + } + + $retString .= "\n$spaces -->\n"; + + + return $retString; + } + + + function toStringNoWhiteSpaces () + { + $retString = ''; + + $retString = ""; + return $retString; + } + + + /* If we get here, the element does have children... get their contents */ + for ($i=0; $i < $this->xnumChildren ; $i++) + { + $retString .= $this->xchildren[$i]->toStringNoWhiteSpaces(); + } + + $retString .= " -->"; + + + return $retString; + } + + +} + + + + +/*************************************************************************************************** +**************************************************************************************************** +***** +***** MiniXMLElementCData +***** +**************************************************************************************************** +***************************************************************************************************/ + +/* The MiniXMLElementCData class is a specific extension of the MiniXMLElement class. +** +** It is used to create the special tags and an instance in created when calling +** $elementObject->cdata('data'); +** +** It's methods are the same as for MiniXMLElement - see those for documentation. +**/ + +class MiniXMLElementCData extends MiniXMLElement { + + + + + function MiniXMLElementCData ($contents) + { + + $this->MiniXMLElement('CDATA'); + if (! is_null($contents)) + { + $this->createNode($contents, 0) ; + } + } + + + function toStringNoWhiteSpaces () + { + return $this->toString(MINIXML_NOWHITESPACES); + } + + function toStringWithWhiteSpaces ($depth=0) + { + return $this->toString($depth); + } + + function toString ($depth=0) + { + $spaces = ''; + if ($depth != MINIXML_NOWHITESPACES) + { + $spaces = $this->_spaceStr($depth); + } + + $retString = "$spacesxnumChildren) + { + $retString .= "]]>\n"; + return $retString; + } + + for ( $i=0; $i < $this->xnumChildren; $i++) + { + $retString .= $this->xchildren[$i]->getValue(); + + } + + $retString .= " ]]>\n"; + + return $retString; + } + + + +} + +/*************************************************************************************************** +**************************************************************************************************** +***** +***** MiniXMLElementDocType +***** +**************************************************************************************************** +***************************************************************************************************/ + +/* The MiniXMLElementDocType class is a specific extension of the MiniXMLElement class. +** +** It is used to create the special tags and an instance in created when calling +** $elementObject->comment(''); +** +** It's methods are the same as for MiniXMLElement - see those for documentation. +**/ + +class MiniXMLElementDocType extends MiniXMLElement { + + var $dtattr; + + function MiniXMLElementDocType ($attr) + { + $this->MiniXMLElement('DOCTYPE'); + $this->dtattr = $attr; + } + function toString ($depth) + { + if ($depth == MINIXML_NOWHITESPACES) + { + return $this->toStringNoWhiteSpaces(); + } else { + return $this->toStringWithWhiteSpaces($depth); + } + } + + + function toStringWithWhiteSpaces ($depth=0) + { + + $spaces = $this->_spaceStr($depth); + + $retString = "$spacesdtattr . " [\n"; + + if (! $this->xnumChildren) + { + $retString .= "]>\n"; + return $retString; + } + + $nextDepth = $depth + 1; + + for ( $i=0; $i < $this->xnumChildren; $i++) + { + + $retString .= $this->xchildren[$i]->toStringWithWhiteSpaces($nextDepth); + + } + + $retString .= "\n$spaces]>\n"; + + return $retString; + } + + + function toStringNoWhiteSpaces () + { + + $retString = "dtattr . " [ "; + + if (! $this->xnumChildren) + { + $retString .= "]>\n"; + return $retString; + } + + for ( $i=0; $i < $this->xnumChildren; $i++) + { + + $retString .= $this->xchildren[$i]->toStringNoWhiteSpaces(); + + } + + $retString .= " ]>\n"; + + return $retString; + } + + +} + + +/*************************************************************************************************** +**************************************************************************************************** +***** +***** MiniXMLElementEntity +***** +**************************************************************************************************** +***************************************************************************************************/ + +/* The MiniXMLElementEntity class is a specific extension of the MiniXMLElement class. +** +** It is used to create the special tags and an instance in created when calling +** $elementObject->comment(''); +** +** It's methods are the same as for MiniXMLElement - see those for documentation. +**/ + +class MiniXMLElementEntity extends MiniXMLElement { + + + + function MiniXMLElementEntity ($name, $value=NULL) + { + + $this->MiniXMLElement($name); + + if (! is_null ($value)) + { + $this->createNode($value, 0); + } + + } + + function toString ($depth = 0) + { + + $spaces = ''; + if ($depth != MINIXML_NOWHITESPACES) + { + $spaces = $this->_spaceStr($depth); + } + + $retString = "$spacesname(); + + if (! $this->xnumChildren) + { + $retString .= ">\n"; + return $retString; + } + + $nextDepth = ($depth == MINIXML_NOWHITESPACES) ? MINIXML_NOWHITESPACES + : $depth + 1; + $retString .= '"'; + for ( $i=0; $i < $this->xnumChildren; $i++) + { + + $retString .= $this->xchildren[$i]->toString(MINIXML_NOWHITESPACES); + + } + $retString .= '"'; + $retString .= " >\n"; + + return $retString; + } + + + function toStringNoWhiteSpaces () + { + return $this->toString(MINIXML_NOWHITESPACES); + } + + function toStringWithWhiteSpaces ($depth=0) + { + return $this->toString($depth); + } + + +} + + Index: aws_xml/includes/minixml/docs/fromArray.php =================================================================== RCS file: aws_xml/includes/minixml/docs/fromArray.php diff -N aws_xml/includes/minixml/docs/fromArray.php --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ aws_xml/includes/minixml/docs/fromArray.php 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,103 @@ + element to hold our team + "spies" => array( + + // Make a list of SPY people + "spy" => array( + array( + 'id' => '007', + 'type' => 'SuperSpy', + 'name' => 'James Bond', + 'email' => 'mi5@london.uk', + 'address' => 'Wherever he is needed most', + ), + + array( + 'id' => '6', + 'type' => 'RetiredSpy', + 'name' => 'Number 6', + 'email' => array( + 'type' => 'private', + '-content' => 'mi6@london.uk', + 'location' => 'office'), + 'address' => '123 Island Prison Lane', + ), + array( + 'name' => 'Inspector Gadget', + 'id' => '13', + 'type' => 'NotReallyASpy', + 'email' => 'lost@aol.com', + 'friends' => array( + + 'friend' => array( + // Gadget's first friend + array( + 'name' => array( + 'first' => 'little', + 'last' => 'girl'), + 'age' => 12, + + 'hair' => array( + 'color' => 'brown', + 'length'=> 'long', + ), + ), + + // Gadget's only other friend + array( + 'name' => array( + 'first' => 'smelly', + 'last' => 'dog'), + 'age' => 14, + + 'hair' => array( + 'color' => 'dirtry blond', + 'length'=> 'short', + ), + ), + + ) // end of list of Gadget's individual FRIENDs + + ) // end of the 'friends' element + + ), // end description of SPY "Inspector Gadget" + + ), // end list of individual spies + + ), // end spies element + ); + + + +$arrayOptions = array( + 'attributes' => array( + '-all' => array('type', 'color'), + 'spy' => 'id', + 'email' => array('location'), + 'hair' => 'length', + ), + ); + + + +$xmlDoc->fromArray($xmlStructure, $arrayOptions); + +print "\n\n\nParsed ARRAY looks like this:\n"; +var_dump($xmlDoc->toArray()); + +print "\n\nOUTPUT of fromArray() *with* OPTIONAL 'attributes' options set (for spy:id, email:location, hair:length, type, color)\n"; + +print $xmlDoc->toString(); + + + + +?> Index: aws_xml/includes/minixml/classes/node.inc.php =================================================================== RCS file: aws_xml/includes/minixml/classes/node.inc.php diff -N aws_xml/includes/minixml/classes/node.inc.php --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ aws_xml/includes/minixml/classes/node.inc.php 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,320 @@ +this text is bold +** Would be represented as a MiniXMLElement named 'B' with a single +** child, a MiniXMLNode object which contains the string 'this text +** is bold'. +** +** a MiniXMLNode has +** - a parent +** - data (text OR numeric) +*/ + +class MiniXMLNode extends MiniXMLTreeComponent { + + + var $xtext; + var $xnumeric; + + /* MiniXMLNode [CONTENTS] + ** Constructor. Creates a new MiniXMLNode object. + ** + */ + function MiniXMLNode ($value=NULL, $escapeEntities=NULL) + { + $this->MiniXMLTreeComponent(); + $this->xtext = NULL; + $this->xnumeric = NULL; + + /* If we were passed a value, save it as the + ** appropriate type + */ + if (! is_null($value)) + { + if (is_numeric($value)) + { + if (MINIXML_DEBUG > 0) + { + _MiniXMLLog("Setting numeric value of node to '$value'"); + } + + $this->xnumeric = $value; + } else { + if (MINIXML_IGNOREWHITESPACES > 0) + { + $value = trim($value); + $value = rtrim($value); + } + + if (! is_null($escapeEntities)) + { + if ($escapeEntities) + { + $value = htmlentities($value); + } + } elseif (MINIXML_AUTOESCAPE_ENTITIES > 0) { + $value = htmlentities($value); + } + + if (MINIXML_DEBUG > 0) + { + _MiniXMLLog("Setting text value of node to '$value'"); + } + + $this->xtext = $value; + + + } /* end if value numeric */ + + } /* end if value passed */ + + } /* end MiniXMLNode constructor */ + + /* getValue + ** + ** Returns the text or numeric value of this Node. + */ + function getValue () + { + $retStr = NULL; + if (! is_null($this->xtext) ) + { + $retStr = $this->xtext; + } elseif (! is_null($this->xnumeric)) + { + $retStr = "$this->xnumeric"; + } + + if (MINIXML_DEBUG > 0) + { + _MiniXMLLog("MiniXMLNode::getValue returning '$retStr'"); + } + + return $retStr; + } + + + /* text [SETTO [SETTOALT]] + ** + ** The text() method is used to get or set text data for this node. + ** + ** If SETTO is passed, the node's content is set to the SETTO string. + ** + ** If the optional SETTOALT is passed and SETTO is false, the + ** node's value is set to SETTOALT. + ** + ** Returns this node's text, if set or NULL + ** + */ + function text ($setToPrimary = NULL, $setToAlternate=NULL) + { + $setTo = ($setToPrimary ? $setToPrimary : $setToAlternate); + + if (! is_null($setTo)) + { + if (! is_null($this->xnumeric) ) + { + return _MiniXMLError("MiniXMLNode::text() Can't set text for element with numeric set."); + + } elseif (! is_string($setTo) && ! is_numeric($setTo) ) { + + return _MiniXMLError("MiniXMLNode::text() Must pass a STRING value to set text for element ('$setTo')."); + } + + if (MINIXML_IGNOREWHITESPACES > 0) + { + $setTo = trim($setTo); + $setTo = rtrim($setTo); + } + + + if (MINIXML_AUTOESCAPE_ENTITIES > 0) + { + $setTo = htmlentities($setTo); + } + + + if (MINIXML_DEBUG > 0) + { + _MiniXMLLog("Setting text value of node to '$setTo'"); + } + + $this->xtext = $setTo; + + } + + return $this->xtext; + } + + /* numeric [SETTO [SETTOALT]] + ** + ** The numeric() method is used to get or set numerical data for this node. + ** + ** If SETTO is passed, the node's content is set to the SETTO string. + ** + ** If the optional SETTOALT is passed and SETTO is NULL, the + ** node's value is set to SETTOALT. + ** + ** Returns this node's text, if set or NULL + ** + */ + function numeric ($setToPrim = NULL, $setToAlt = NULL) + { + $setTo = is_null($setToPrim) ? $setToAlt : $setToPrim; + + if (! is_null($setTo)) + { + if (! is_null($this->xtext)) { + + return _MiniXMLError("MiniXMLElement::numeric() Can't set numeric for element with text."); + + } elseif (! is_numeric($setTo)) + { + return _MiniXMLError("MiniXMLElement::numeric() Must pass a NUMERIC value to set numeric for element."); + } + + if (MINIXML_DEBUG > 0) + { + _MiniXMLLog("Setting numeric value of node to '$setTo'"); + } + $this->xnumeric = $setTo; + } + + return $this->xnumeric; + } + + + + /* toString [DEPTH] + ** + ** Returns this node's contents as a string. + ** + ** + ** Note: Nodes have only a single value, no children. It is + ** therefore pointless to use the same toString() method split as + ** in the MiniXMLElement class. + ** + */ + + function toString ($depth=0) + { + if ($depth == MINIXML_NOWHITESPACES) + { + return $this->toStringNoWhiteSpaces(); + } + + if (MINIXML_DEBUG > 0) + { + _MiniXMLLog("MiniXMLNode::toString() call with depth $depth"); + } + + $spaces = $this->_spaceStr($depth); + $retStr = $spaces; + + if (! is_null($this->xtext) ) + { + /* a text element */ + $retStr .= $this->xtext; + } elseif (! is_null($this->xnumeric)) { + /* a numeric element */ + $retStr .= $this->xnumeric; + } + + /* indent all parts of the string correctly */ + $retStr = preg_replace("/\n\s*/sm", "\n$spaces", $retStr); + + return $retStr; + } + + + function toStringWithWhiteSpaces ($depth=0) + { + return $this->toString($depth); + } + + function toStringNoWhiteSpaces () + { + + if (MINIXML_DEBUG > 0) + { + _MiniXMLLog("MiniXMLNode::toStringNoWhiteSpaces() call with depth $depth"); + } + + if (! is_null($this->xtext) ) + { + /* a text element */ + $retStr = $this->xtext; + } elseif (! is_null($this->xnumeric)) { + /* a numeric element */ + $retStr = $this->xnumeric; + } + + return $retStr; + } + + +} /* end class definition */ + + + Index: aws_xml/includes/minixml/docs/toarray.php =================================================================== RCS file: aws_xml/includes/minixml/docs/toarray.php diff -N aws_xml/includes/minixml/docs/toarray.php --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ aws_xml/includes/minixml/docs/toarray.php 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,20 @@ +fromFile('./test.xml'); + +print_r($xmlDoc->toArray()); + +?>