PageRenderTime 47ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/administrator/components/com_virtuemart/classes/shipping/minixml/classes/doc.inc.php

https://bitbucket.org/dgough/annamaria-daneswood-25102012
PHP | 877 lines | 466 code | 196 blank | 215 comment | 63 complexity | 5b65a9193de8884eab063c3efeed9002 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. /***************************************************************************************************
  3. ****************************************************************************************************
  4. *****
  5. ***** MiniXML - PHP class library for generating and parsing XML.
  6. *****
  7. ***** Copyright (C) 2002,2003 Patrick Deegan, Psychogenic.com
  8. ***** All rights reserved.
  9. *****
  10. ***** http://minixml.psychogenic.com
  11. *****
  12. ***** This program is free software; you can redistribute
  13. ***** it and/or modify it under the terms of the GNU
  14. ***** General Public License as published by the Free
  15. ***** Software Foundation; either version 2 of the
  16. ***** License, or (at your option) any later version.
  17. *****
  18. ***** This program is distributed in the hope that it will
  19. ***** be useful, but WITHOUT ANY WARRANTY; without even
  20. ***** the implied warranty of MERCHANTABILITY or FITNESS
  21. ***** FOR A PARTICULAR PURPOSE. See the GNU General
  22. ***** Public License for more details.
  23. *****
  24. ***** You should have received a copy of the GNU General
  25. ***** Public License along with this program; if not,
  26. ***** write to the Free Software Foundation, Inc., 675
  27. ***** Mass Ave, Cambridge, MA 02139, USA.
  28. *****
  29. *****
  30. ***** You may contact the author, Pat Deegan, through the
  31. ***** contact section at http://www.psychogenic.com
  32. *****
  33. ***** Much more information on using this API can be found on the
  34. ***** official MiniXML website - http://minixml.psychogenic.com
  35. ***** or within the Perl version (XML::Mini) available through CPAN
  36. *****
  37. ****************************************************************************************************
  38. ***************************************************************************************************/
  39. define("MINIXML_COMPLETE_REGEX",'/<\s*([^\s>]+)([^>]+)?>(.*?)<\s*\/\\1\s*>\s*([^<]+)?(.*)|\s*<!--(.+?)-->\s*|^\s*<\s*([^\s>]+)([^>]*)\/\s*>\s*([^<>]+)?|<!\[CDATA\s*\[(.*?)\]\]\s*>|<!DOCTYPE\s*([^\[]*)\[(.*?)\]\s*>|<!ENTITY\s*([^"\'>]+)\s*(["\'])([^\14]+)\14\s*>|^([^<]+)(.*)/smi');
  40. // 10 11 12 13 14 15 16 17
  41. define("MINIXML_SIMPLE_REGEX",
  42. // 1 2 3 4 5 6 7 8 9 10 11
  43. '/\s*<\s*([^\s>]+)([^>]+)?>(.*?)<\s*\/\\1\s*>\s*([^<]+)?(.*)|\s*<!--(.+?)-->\s*|\s*<\s*([^\s>]+)([^>]*)\/\s*>\s*([^<>]+)?|^([^<]+)(.*)/smi');
  44. require_once(MINIXML_CLASSDIR . "/element.inc.php");
  45. /***************************************************************************************************
  46. ****************************************************************************************************
  47. *****
  48. ***** MiniXMLDoc
  49. *****
  50. ****************************************************************************************************
  51. ***************************************************************************************************/
  52. /* MiniXMLDoc class
  53. **
  54. ** The MiniXMLDoc class is the programmer's handle to MiniXML functionality.
  55. **
  56. ** A MiniXMLDoc instance is created in every program that uses MiniXML.
  57. ** With the MiniXMLDoc object, you can access the root MiniXMLElement,
  58. ** find/fetch/create elements and read in or output XML strings.
  59. **/
  60. class MiniXMLDoc {
  61. var $xxmlDoc;
  62. var $xuseSimpleRegex;
  63. var $xRegexIndex;
  64. /* MiniXMLDoc [XMLSTRING]
  65. ** Constructor, create and init a MiniXMLDoc object.
  66. **
  67. ** If the optional XMLSTRING is passed, the document will be initialised with
  68. ** a call to fromString using the XMLSTRING.
  69. **
  70. */
  71. function MiniXMLDoc ($string=NULL)
  72. {
  73. /* Set up the root element - note that it's name get's translated to a
  74. ** <?php xml version="1.0" ?> string.
  75. */
  76. $this->xxmlDoc = new MiniXMLElement("PSYCHOGENIC_ROOT_ELEMENT");
  77. $this->xuseSimpleRegex = MINIXML_USE_SIMPLE;
  78. if (! is_null($string))
  79. {
  80. $this->fromString($string);
  81. }
  82. }
  83. function init ()
  84. {
  85. $this->xxmlDoc = new MiniXMLElement("PSYCHOGENIC_ROOT_ELEMENT");
  86. }
  87. /* getRoot
  88. ** Returns a reference the this document's root element
  89. ** (an instance of MiniXMLElement)
  90. */
  91. function &getRoot ()
  92. {
  93. return $this->xxmlDoc;
  94. }
  95. /* setRoot NEWROOT
  96. ** Set the document root to the NEWROOT MiniXMLElement object.
  97. **/
  98. function setRoot (&$root)
  99. {
  100. if ($this->isElement($root))
  101. {
  102. $this->xxmlDoc = $root;
  103. } else {
  104. return _MiniXMLError("MiniXMLDoc::setRoot(): Trying to set non-MiniXMLElement as root");
  105. }
  106. }
  107. /* isElement ELEMENT
  108. ** Returns a true value if ELEMENT is an instance of MiniXMLElement,
  109. ** false otherwise.
  110. */
  111. function isElement (&$testme)
  112. {
  113. if (is_null($testme))
  114. {
  115. return 0;
  116. }
  117. return method_exists($testme, 'MiniXMLElement');
  118. }
  119. /* isNode NODE
  120. ** Returns a true value if NODE is an instance of MiniXMLNode,
  121. ** false otherwise.
  122. */
  123. function isNode (&$testme)
  124. {
  125. if (is_null($testme))
  126. {
  127. return 0;
  128. }
  129. return method_exists($testme, 'MiniXMLNode');
  130. }
  131. /* createElement NAME [VALUE]
  132. ** Creates a new MiniXMLElement with name NAME.
  133. ** This element is an orphan (has no assigned parent)
  134. ** and will be lost unless it is appended (MiniXMLElement::appendChild())
  135. ** to an element at some point.
  136. **
  137. ** If the optional VALUE (string or numeric) parameter is passed,
  138. ** the new element's text/numeric content will be set using VALUE.
  139. **
  140. ** Returns a reference to the newly created element (use the =& operator)
  141. */
  142. function &createElement ($name=NULL, $value=NULL)
  143. {
  144. $newElement = new MiniXMLElement($name);
  145. if (! is_null($value))
  146. {
  147. if (is_numeric($value))
  148. {
  149. $newElement->numeric($value);
  150. } elseif (is_string($value))
  151. {
  152. $newElement->text($value);
  153. }
  154. }
  155. return $newElement;
  156. }
  157. /* getElement NAME
  158. ** Searches the document for an element with name NAME.
  159. **
  160. ** Returns a reference to the first MiniXMLElement with name NAME,
  161. ** if found, NULL otherwise.
  162. **
  163. ** NOTE: The search is performed like this, returning the first
  164. ** element that matches:
  165. **
  166. ** - Check the Root Element's immediate children (in order) for a match.
  167. ** - Ask each immediate child (in order) to MiniXMLElement::getElement()
  168. ** (each child will then proceed similarly, checking all it's immediate
  169. ** children in order and then asking them to getElement())
  170. */
  171. function &getElement ($name)
  172. {
  173. $element = $this->xxmlDoc->getElement($name);
  174. if (MINIXML_DEBUG > 0)
  175. {
  176. _MiniXMLLog("MiniXMLDoc::getElement(): Returning element $element");
  177. }
  178. return $element;
  179. }
  180. /* getElementByPath PATH
  181. ** Attempts to return a reference to the (first) element at PATH
  182. ** where PATH is the path in the structure from the root element to
  183. ** the requested element.
  184. **
  185. ** For example, in the document represented by:
  186. **
  187. ** <partRateRequest>
  188. ** <vendor>
  189. ** <accessid user="myusername" password="mypassword" />
  190. ** </vendor>
  191. ** <partList>
  192. ** <partNum>
  193. ** DA42
  194. ** </partNum>
  195. ** <partNum>
  196. ** D99983FFF
  197. ** </partNum>
  198. ** <partNum>
  199. ** ss-839uent
  200. ** </partNum>
  201. ** </partList>
  202. ** </partRateRequest>
  203. **
  204. ** $accessid =& $xmlDocument->getElementByPath('partRateRequest/vendor/accessid');
  205. **
  206. ** Will return what you expect (the accessid element with attributes user = "myusername"
  207. ** and password = "mypassword").
  208. **
  209. ** BUT be careful:
  210. ** $accessid =& $xmlDocument->getElementByPath('partRateRequest/partList/partNum');
  211. **
  212. ** will return the partNum element with the value "DA42". Other partNums are
  213. ** inaccessible by getElementByPath() - Use MiniXMLElement::getAllChildren() instead.
  214. **
  215. ** Returns the MiniXMLElement reference if found, NULL otherwise.
  216. */
  217. function &getElementByPath ($path)
  218. {
  219. $element = $this->xxmlDoc->getElementByPath($path);
  220. if (MINIXML_DEBUG > 0)
  221. {
  222. _MiniXMLLog("Returning element $element");
  223. }
  224. return $element;
  225. }
  226. function fromFile ($filename)
  227. {
  228. $modified = stat($filename);
  229. if (! is_array($modified))
  230. {
  231. _MiniXMLError("Can't stat '$filename'");
  232. return NULL;
  233. }
  234. if (MINIXML_USEFROMFILECACHING > 0)
  235. {
  236. $tmpName = MINIXML_FROMFILECACHEDIR . '/' . 'minixml-' . md5($filename);
  237. if (MINIXML_DEBUG > 0)
  238. {
  239. _MiniXMLLog("Trying to open cach file $tmpName (for '$filename')");
  240. }
  241. $cacheFileStat = stat($tmpName);
  242. if (is_array($cacheFileStat) && $cacheFileStat[9] > $modified[9])
  243. {
  244. $fp = @fopen($tmpName,"r");
  245. if ($fp)
  246. {
  247. if (MINIXML_DEBUG > 0)
  248. {
  249. _MiniXMLLog("Reading file '$filename' from object cache instead ($tmpName)");
  250. }
  251. $tmpFileSize = filesize($tmpName);
  252. $tmpFileContents = fread($fp, $tmpFileSize);
  253. $serializedObj = unserialize($tmpFileContents);
  254. $sRoot =& $serializedObj->getRoot();
  255. if ($sRoot)
  256. {
  257. if (MINIXML_DEBUG > 0)
  258. {
  259. _MiniXMLLog("Restoring object from cache file $tmpName");
  260. }
  261. $this->setRoot($sRoot);
  262. /* Return immediately, such that we don't refresh the cache */
  263. return $this->xxmlDoc->numChildren();
  264. } /* end if we got a root element from unserialized object */
  265. } /* end if we sucessfully opened the file */
  266. if($fp)
  267. fclose($fp);
  268. } /* end if cache file exists and is more recent */
  269. }
  270. ob_start();
  271. readfile($filename);
  272. $filecontents = ob_get_contents();
  273. ob_end_clean();
  274. $retVal = $this->fromString($filecontents);
  275. if (MINIXML_USEFROMFILECACHING > 0)
  276. {
  277. $this->saveToCache($filename);
  278. }
  279. return $retVal;
  280. }
  281. function saveToCache ($filename)
  282. {
  283. $tmpName = MINIXML_FROMFILECACHEDIR . '/' . 'minixml-' . md5($filename);
  284. $fp = @fopen($tmpName, "w");
  285. if (MINIXML_DEBUG > 0)
  286. {
  287. _MiniXMLLog("Saving object to cache as '$tmpName'");
  288. }
  289. if ($fp)
  290. {
  291. $serialized = serialize($this);
  292. fwrite($fp, $serialized);
  293. fclose($fp);
  294. } else {
  295. _MiniXMLError("Could not open $tmpName for write in MiniXMLDoc::saveToCache()");
  296. }
  297. }
  298. /* fromString XMLSTRING
  299. **
  300. ** Initialise the MiniXMLDoc (and it's root MiniXMLElement) using the
  301. ** XML string XMLSTRING.
  302. **
  303. ** Returns the number of immediate children the root MiniXMLElement now
  304. ** has.
  305. */
  306. function fromString (&$XMLString)
  307. {
  308. $useSimpleFlag = $this->xuseSimpleRegex;
  309. //if ($this->xuseSimpleRegex && ! preg_match('/<!DOCTYPE|<!ENTITY|<!\[CDATA/smi', $XMLString))
  310. // Bug fix for template manager - needs tesing for all CMT functions
  311. if ($this->xuseSimpleRegex || ! preg_match('/<!DOCTYPE|<!ENTITY|<!\[CDATA/smi', $XMLString))
  312. {
  313. $this->xuseSimpleRegex = 1;
  314. $this->xRegexIndex = array(
  315. 'biname' => 1,
  316. 'biattr' => 2,
  317. 'biencl' => 3,
  318. 'biendtxt' => 4,
  319. 'birest' => 5,
  320. 'comment' => 6,
  321. 'uname' => 7,
  322. 'uattr' => 8,
  323. 'uendtxt' => 9,
  324. 'plaintxt' => 10,
  325. 'plainrest' => 11
  326. );
  327. $regex = MINIXML_SIMPLE_REGEX;
  328. } else {
  329. $this->xRegexIndex = array(
  330. 'biname' => 1,
  331. 'biattr' => 2,
  332. 'biencl' => 3,
  333. 'biendtxt' => 4,
  334. 'birest' => 5,
  335. 'comment' => 6,
  336. 'uname' => 7,
  337. 'uattr' => 8,
  338. 'uendtxt' => 9,
  339. 'cdata' => 10,
  340. 'doctypedef' => 11,
  341. 'doctypecont' => 12,
  342. 'entityname' => 13,
  343. 'entitydef' => 15,
  344. 'plaintxt' => 16,
  345. 'plainrest' => 17
  346. );
  347. $regex = MINIXML_COMPLETE_REGEX;
  348. }
  349. // $this->time('fromString');
  350. $this->fromSubString($this->xxmlDoc, $XMLString, $regex);
  351. // $this->time('fromString DONE');
  352. $this->xuseSimpleRegex = $useSimpleFlag;
  353. return $this->xxmlDoc->numChildren();
  354. }
  355. function fromArray (&$init, $params=NULL)
  356. {
  357. $this->init();
  358. if (! is_array($init) )
  359. {
  360. return _MiniXMLError("MiniXMLDoc::fromArray(): Must Pass an ARRAY to initialize from");
  361. }
  362. if (! is_array($params) )
  363. {
  364. $params = array();
  365. }
  366. if ( $params["attributes"] && is_array($params["attributes"]) )
  367. {
  368. $attribs = array();
  369. foreach ($params["attributes"] as $attribName => $value)
  370. {
  371. if (! is_array($attribs[$attribName]) )
  372. {
  373. $attribs[$attribName] = array();
  374. }
  375. if (is_array($value))
  376. {
  377. foreach ($value as $v)
  378. {
  379. $attribs[$attribName][$v]++;
  380. }
  381. } else {
  382. $attribs[$attribName][$value]++;
  383. }
  384. }
  385. // completely replace old attributes by our optimized array
  386. $params["attributes"] = $attribs;
  387. } else {
  388. $params["attributes"] = array();
  389. }
  390. foreach ($init as $keyname => $value)
  391. {
  392. $sub = $this->_fromArray_getExtractSub($value);
  393. $this->$sub($keyname, $value, $this->xxmlDoc, $params);
  394. }
  395. return $this->xxmlDoc->numChildren();
  396. }
  397. function _fromArray_getExtractSub ($v)
  398. {
  399. // is it a string, a numerical array or an associative array?
  400. $sub = "_fromArray_extract";
  401. if (is_array($v))
  402. {
  403. if (_MiniXML_NumKeyArray($v))
  404. {
  405. // All numeric - assume it is a "straight" array
  406. $sub .= "ARRAY";
  407. } else {
  408. $sub .= "AssociativeARRAY";
  409. }
  410. } else {
  411. $sub .= "STRING";
  412. }
  413. return $sub;
  414. }
  415. function _fromArray_extractAssociativeARRAY ($name, &$value, &$parent, &$params)
  416. {
  417. $thisElement =& $parent->createChild($name);
  418. foreach ($value as $key => $val)
  419. {
  420. $sub = $this->_fromArray_getExtractSub($val);
  421. $this->$sub($key, $val, $thisElement, $params);
  422. }
  423. return;
  424. }
  425. function _fromArray_extractARRAY ($name, &$value, &$parent, &$params)
  426. {
  427. foreach ($value as $val)
  428. {
  429. $sub = $this->_fromArray_getExtractSub($val);
  430. $this->$sub($name, $val, $parent, $params);
  431. }
  432. return;
  433. }
  434. function _fromArray_extractSTRING ($name, $value="", &$parent, &$params)
  435. {
  436. $pname = $parent->name();
  437. if (
  438. ( is_array($params['attributes'][$pname]) && $params['attributes'][$pname][$name])
  439. || ( is_array($params['attributes']['-all']) && $params['attributes']['-all'][$name])
  440. )
  441. {
  442. $parent->attribute($name, $value);
  443. } elseif ($name == '-content') {
  444. $parent->text($value);
  445. } else {
  446. $parent->createChild($name, $value);
  447. }
  448. return;
  449. }
  450. function time ($msg)
  451. {
  452. error_log("\nMiniXML msg '$msg', time: ". time() . "\n");
  453. }
  454. // fromSubString PARENTMINIXMLELEMENT XMLSUBSTRING
  455. // private method, called recursively to parse the XMLString in little sub-chunks.
  456. function fromSubString (&$parentElement, &$XMLString, &$regex)
  457. {
  458. //$this->time('fromSubStr');
  459. if (is_null($parentElement) || preg_match('/^\s*$/', $XMLString))
  460. {
  461. return;
  462. }
  463. if (MINIXML_DEBUG > 0)
  464. {
  465. _MiniXMLLog("Called fromSubString() with parent '" . $parentElement->name() . "'\n");
  466. }
  467. $matches = array();
  468. if (preg_match_all( $regex, $XMLString, $matches))
  469. {
  470. // $this->time('a match');
  471. $mcp = $matches;
  472. $numMatches = count($mcp[0]);
  473. _MiniXMLLog ("Got $numMatches parsing regex matches: ". $mcp[0][0]);
  474. for($i=0; $i < $numMatches; $i++)
  475. {
  476. _MiniXMLLog ("Got $numMatches CHEKKING: ". $mcp[0][$i] . "\n");
  477. // $this->time('a match');
  478. $uname = $mcp[$this->xRegexIndex['uname']][$i];
  479. $comment = $mcp[$this->xRegexIndex['comment']][$i];
  480. if ($this->xuseSimpleRegex)
  481. {
  482. $cdata = NULL;
  483. $doctypecont = NULL;
  484. $entityname = NULL;
  485. } else {
  486. $cdata = $mcp[$this->xRegexIndex['cdata']][$i];
  487. $doctypecont = $mcp[$this->xRegexIndex['doctypecont']][$i];
  488. $entityname = $mcp[$this->xRegexIndex['entityname']][$i];
  489. }
  490. $plaintext = $mcp[$this->xRegexIndex['plaintxt']][$i];
  491. if ($uname)
  492. {
  493. _MiniXMLLog ("Got unary $uname");
  494. $ufinaltxt = $mcp[$this->xRegexIndex['uendtxt']][$i];
  495. $newElement =& $parentElement->createChild($uname);
  496. $this->_extractAttributesFromString($newElement, $mcp[$this->xRegexIndex['uattr']][$i]);
  497. if ($ufinaltxt)
  498. {
  499. $parentElement->createNode($ufinaltxt);
  500. }
  501. } elseif ($comment) {
  502. //_MiniXMLLog ("Got comment $comment");
  503. $parentElement->comment($comment);
  504. } elseif ($cdata) {
  505. //_MiniXMLLog ("Got cdata $cdata");
  506. $newElement = new MiniXMLElementCData($cdata);
  507. $parentElement->appendChild($newElement);
  508. } elseif ($doctypecont) {
  509. //_MiniXMLLog ("Got doctype $doctypedef '" . $mcp[11][$i] . "'");
  510. $newElement = new MiniXMLElementDocType($mcp[$this->xRegexIndex['doctypedef']][$i]);
  511. $appendedChild =& $parentElement->appendChild($newElement);
  512. $this->fromSubString($appendedChild, $doctypecont, $regex);
  513. } elseif ($entityname ) {
  514. //_MiniXMLLog ("Got entity $entityname");
  515. $newElement = new MiniXMLElementEntity ($entityname, $mcp[$this->xRegexIndex['entitydef']][$i]);
  516. $parentElement->appendChild($newElement);
  517. } elseif ($plaintext) {
  518. //_MiniXMLLog ("Got $plaintext plaintext");
  519. $afterTxt = $mcp[$this->xRegexIndex['plainrest']][$i];
  520. if (! preg_match('/^\s+$/', $plaintext))
  521. {
  522. $parentElement->createNode($plaintext);
  523. }
  524. if ($afterTxt && ! preg_match('/^\s*$/', $afterTxt))
  525. {
  526. $this->fromSubString($parentElement, $afterTxt, $regex);
  527. }
  528. } elseif($mcp[$this->xRegexIndex['biname']]) {
  529. $nencl = $mcp[$this->xRegexIndex['biencl']][$i];
  530. $finaltxt = $mcp[$this->xRegexIndex['biendtxt']][$i];
  531. $otherTags = $mcp[$this->xRegexIndex['birest']][$i];
  532. $newElement =& $parentElement->createChild($mcp[$this->xRegexIndex['biname']][$i]);
  533. $this->_extractAttributesFromString($newElement, $mcp[$this->xRegexIndex['biattr']][$i]);
  534. $plaintxtMatches = array();
  535. if (preg_match("/^\s*([^\s<][^<]*)/", $nencl, $plaintxtMatches))
  536. {
  537. $txt = $plaintxtMatches[1];
  538. $newElement->createNode($txt);
  539. $nencl = preg_replace("/^\s*([^<]+)/", "", $nencl);
  540. }
  541. if ($nencl && !preg_match('/^\s*$/', $nencl))
  542. {
  543. $this->fromSubString($newElement, $nencl, $regex);
  544. }
  545. if ($finaltxt)
  546. {
  547. $parentElement->createNode($finaltxt);
  548. }
  549. if ($otherTags && !preg_match('/^\s*$/',$otherTags))
  550. {
  551. $this->fromSubString($parentElement, $otherTags, $regex);
  552. }
  553. } /* end switch over type of match */
  554. } /* end loop over all matches */
  555. } /* end if there was a match */
  556. } /* end method fromSubString */
  557. /* toString [DEPTH]
  558. ** Converts this MiniXMLDoc object to a string and returns it.
  559. **
  560. ** The optional DEPTH may be passed to set the space offset for the
  561. ** first element.
  562. **
  563. ** If the optional DEPTH is set to MINIXML_NOWHITESPACES.
  564. ** When it is, no \n or whitespaces will be inserted in the xml string
  565. ** (ie it will all be on a single line with no spaces between the tags.
  566. **
  567. ** Returns a string of XML representing the document.
  568. */
  569. function toString ($depth=0)
  570. {
  571. $retString = $this->xxmlDoc->toString($depth);
  572. if ($depth == MINIXML_NOWHITESPACES)
  573. {
  574. $xmlhead = "<?xml version=\"1.0\"\\1?>";
  575. } else {
  576. $xmlhead = "<?xml version=\"1.0\"\\1?>\n ";
  577. }
  578. $search = array("/<PSYCHOGENIC_ROOT_ELEMENT([^>]*)>\s*/smi",
  579. "/<\/PSYCHOGENIC_ROOT_ELEMENT>/smi");
  580. $replace = array($xmlhead,
  581. "");
  582. $retString = preg_replace($search, $replace, $retString);
  583. if (MINIXML_DEBUG > 0)
  584. {
  585. _MiniXMLLog("MiniXML::toString() Returning XML:\n$retString\n\n");
  586. }
  587. return $retString;
  588. }
  589. /* toArray
  590. **
  591. ** Transforms the XML structure currently represented by the MiniXML Document object
  592. ** into an array.
  593. **
  594. ** More docs to come - for the moment, use var_dump($miniXMLDoc->toArray()) to see
  595. ** what's going on :)
  596. */
  597. function & toArray ()
  598. {
  599. $retVal = $this->xxmlDoc->toStructure();
  600. if (is_array($retVal))
  601. {
  602. return $retVal;
  603. }
  604. $retArray = array(
  605. '-content' => $retVal,
  606. );
  607. return $retArray;
  608. }
  609. /* getValue()
  610. ** Utility function, call the root MiniXMLElement's getValue()
  611. */
  612. function getValue ()
  613. {
  614. return $this->xxmlDoc->getValue();
  615. }
  616. /* dump
  617. ** Debugging aid, dump returns a nicely formatted dump of the current structure of the
  618. ** MiniXMLDoc object.
  619. */
  620. function dump ()
  621. {
  622. return serialize($this);
  623. }
  624. // _extractAttributesFromString
  625. // private method for extracting and setting the attributs from a
  626. // ' a="b" c = "d"' string
  627. function _extractAttributesFromString (&$element, &$attrString)
  628. {
  629. if (! $attrString)
  630. {
  631. return NULL;
  632. }
  633. $count = 0;
  634. $attribs = array();
  635. // Set the attribs
  636. preg_match_all('/([^\s]+)\s*=\s*([\'"])([^\2]+?)\2/sm', $attrString, $attribs);
  637. for ($i = 0; $i < count($attribs[0]); $i++)
  638. {
  639. $attrname = $attribs[1][$i];
  640. $attrval = $attribs[3][$i];
  641. if ($attrname)
  642. {
  643. $element->attribute($attrname, $attrval, '');
  644. $count++;
  645. }
  646. }
  647. return $count;
  648. }
  649. }
  650. /***************************************************************************************************
  651. ****************************************************************************************************
  652. *****
  653. ***** MiniXML
  654. *****
  655. ****************************************************************************************************
  656. ***************************************************************************************************/
  657. /* class MiniXML (MiniXMLDoc)
  658. **
  659. ** Avoid using me - I involve needless overhead.
  660. **
  661. ** Utility class - this is just an name aliase for the
  662. ** MiniXMLDoc class as I keep repeating the mistake of
  663. ** trying to create
  664. **
  665. ** $xml = new MiniXML();
  666. **
  667. */
  668. class MiniXML extends MiniXMLDoc {
  669. function MiniXML ()
  670. {
  671. $this->MiniXMLDoc();
  672. }
  673. }
  674. ?>