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