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

/lib/minixml/element.inc.php

http://wowroster.googlecode.com/
PHP | 1771 lines | 856 code | 391 blank | 524 comment | 165 complexity | 08a872fcdef22cff32f17e17b4305514 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /**
  3. * WoWRoster.net WoWRoster
  4. *
  5. * MiniXML Library
  6. *
  7. *
  8. * @copyright 2002-2011 WoWRoster.net
  9. * @license http://www.gnu.org/licenses/gpl.html Licensed under the GNU General Public License v3.
  10. * @version SVN: $Id: element.inc.php 2222 2010-12-05 10:05:37Z c.treyce@gmail.com $
  11. * @link http://www.wowroster.net
  12. * @since File available since Release 1.8.0
  13. * @package WoWRoster
  14. * @subpackage MiniXML
  15. */
  16. /***************************************************************************************************
  17. ****************************************************************************************************
  18. *****
  19. ***** MiniXML - PHP class library for generating and parsing XML.
  20. *****
  21. ***** Copyright (C) 2002-2005 Patrick Deegan, Psychogenic.com
  22. ***** All rights reserved.
  23. *****
  24. ***** http://minixml.psychogenic.com
  25. *****
  26. ***** This program is free software; you can redistribute
  27. ***** it and/or modify it under the terms of the GNU
  28. ***** General Public License as published by the Free
  29. ***** Software Foundation; either version 2 of the
  30. ***** License, or (at your option) any later version.
  31. *****
  32. ***** This program is distributed in the hope that it will
  33. ***** be useful, but WITHOUT ANY WARRANTY; without even
  34. ***** the implied warranty of MERCHANTABILITY or FITNESS
  35. ***** FOR A PARTICULAR PURPOSE. See the GNU General
  36. ***** Public License for more details.
  37. *****
  38. ***** You should have received a copy of the GNU General
  39. ***** Public License along with this program; if not,
  40. ***** write to the Free Software Foundation, Inc., 675
  41. ***** Mass Ave, Cambridge, MA 02139, USA.
  42. *****
  43. *****
  44. ***** You may contact the author, Pat Deegan, through the
  45. ***** contact section at http://www.psychogenic.com
  46. *****
  47. ***** Much more information on using this API can be found on the
  48. ***** official MiniXML website - http://minixml.psychogenic.com
  49. ***** or within the Perl version (XML::Mini) available through CPAN
  50. *****
  51. ****************************************************************************************************
  52. ***************************************************************************************************/
  53. require_once(MINIXML_CLASSDIR . "/treecomp.inc.php");
  54. require_once(MINIXML_CLASSDIR . "/node.inc.php");
  55. /***************************************************************************************************
  56. ****************************************************************************************************
  57. *****
  58. ***** MiniXMLElement
  59. *****
  60. ****************************************************************************************************
  61. ***************************************************************************************************/
  62. /* class MiniXMLElement (MiniXMLTreeComponent)
  63. **
  64. ** Although the main handle to the xml document is the MiniXMLDoc object,
  65. ** much of the functionality and manipulation involves interaction with
  66. ** MiniXMLElement objects.
  67. **
  68. ** A MiniXMLElement
  69. ** has:
  70. ** - a name
  71. ** - a list of 0 or more attributes (which have a name and a value)
  72. ** - a list of 0 or more children (MiniXMLElement or MiniXMLNode objects)
  73. ** - a parent (optional, only if MINIXML_AUTOSETPARENT > 0)
  74. **/
  75. class MiniXMLElement extends MiniXMLTreeComponent {
  76. var $xname;
  77. var $xattributes;
  78. var $xchildren;
  79. var $xnumChildren;
  80. var $xnumElementChildren;
  81. var $xavoidLoops = MINIXML_AVOIDLOOPS;
  82. /* MiniXMLElement NAME
  83. ** Creates and inits a new MiniXMLElement
  84. */
  85. function MiniXMLElement ($name=NULL)
  86. {
  87. $this->MiniXMLTreeComponent();
  88. $this->xname = NULL;
  89. $this->xattributes = array();
  90. $this->xchildren = array();
  91. $this->xnumChildren = 0;
  92. $this->xnumElementChildren = 0;
  93. if ($name)
  94. {
  95. $this->name($name);
  96. } else {
  97. return _MiniXMLError("MiniXMLElement Constructor: must pass a name to constructor");
  98. }
  99. } /* end method MiniXMLElement */
  100. /**************** Get/set methods for MiniXMLElement data *****************/
  101. /* name [NEWNAME]
  102. **
  103. ** If a NEWNAME string is passed, the MiniXMLElement's name is set
  104. ** to NEWNAME.
  105. **
  106. ** Returns the element's name.
  107. */
  108. function name ($setTo=NULL)
  109. {
  110. if (! is_null($setTo))
  111. {
  112. if (! is_string($setTo))
  113. {
  114. return _MiniXMLError("MiniXMLElement::name() Must pass a STRING to method to set name");
  115. }
  116. $this->xname = $setTo;
  117. }
  118. return $this->xname;
  119. } /* end method name */
  120. /* attribute NAME [SETTO [SETTOALT]]
  121. **
  122. ** The attribute() method is used to get and set the
  123. ** MiniXMLElement's attributes (ie the name/value pairs contained
  124. ** within the tag, <tagname attrib1="value1" attrib2="value2">)
  125. **
  126. ** If SETTO is passed, the attribute's value is set to SETTO.
  127. **
  128. ** If the optional SETTOALT is passed and SETTO is false, the
  129. ** attribute's value is set to SETTOALT. This is usefull in cases
  130. ** when you wish to set the attribute to a default value if no SETTO is
  131. ** present, eg $myelement->attribute('href', $theHref, 'http://psychogenic.com')
  132. ** will default to 'http://psychogenic.com'.
  133. **
  134. ** Note: if the MINIXML_LOWERCASEATTRIBUTES define is > 0, all attribute names
  135. ** will be lowercased (while setting and during retrieval)
  136. **
  137. ** Returns the value associated with attribute NAME.
  138. **
  139. */
  140. function attribute ($name, $primValue=NULL, $altValue=NULL)
  141. {
  142. $value = (is_null($primValue) ? $altValue : $primValue );
  143. if (MINIXML_UPPERCASEATTRIBUTES > 0)
  144. {
  145. $name = strtoupper($name);
  146. } elseif (MINIXML_LOWERCASEATTRIBUTES > 0)
  147. {
  148. $name = strtolower($name);
  149. }
  150. if (! is_null($value))
  151. {
  152. $this->xattributes[$name] = $value;
  153. }
  154. if (! is_null($this->xattributes[$name]))
  155. {
  156. return $this->xattributes[$name];
  157. } else {
  158. return NULL;
  159. }
  160. } /* end method attribute */
  161. /* text [SETTO [SETTOALT]]
  162. **
  163. ** The text() method is used to get or append text data to this
  164. ** element (it is appended to the child list as a new MiniXMLNode object).
  165. **
  166. ** If SETTO is passed, a new node is created, filled with SETTO
  167. ** and appended to the list of this element's children.
  168. **
  169. ** If the optional SETTOALT is passed and SETTO is false, the
  170. ** new node's value is set to SETTOALT. See the attribute() method
  171. ** for an example use.
  172. **
  173. ** Returns a string composed of all child MiniXMLNodes' contents.
  174. **
  175. ** Note: all the children MiniXMLNodes' contents - including numeric
  176. ** nodes are included in the return string.
  177. */
  178. function text ($setToPrimary = NULL, $setToAlternate=NULL)
  179. {
  180. $setTo = ($setToPrimary ? $setToPrimary : $setToAlternate);
  181. if (! is_null($setTo))
  182. {
  183. $this->createNode($setTo);
  184. }
  185. $retString = '';
  186. /* Extract text from all child nodes */
  187. for($i=0; $i< $this->xnumChildren; $i++)
  188. {
  189. if ($this->isNode($this->xchildren[$i]))
  190. {
  191. $nodeTxt = $this->xchildren[$i]->getValue();
  192. if (! is_null($nodeTxt))
  193. {
  194. $retString .= "$nodeTxt ";
  195. } /* end if text returned */
  196. } /* end if this is a MiniXMLNode */
  197. } /* end loop over all children */
  198. return $retString;
  199. } /* end method text */
  200. /* numeric [SETTO [SETTOALT]]
  201. **
  202. ** The numeric() method is used to get or append numeric data to
  203. ** this element (it is appended to the child list as a MiniXMLNode object).
  204. **
  205. ** If SETTO is passed, a new node is created, filled with SETTO
  206. ** and appended to the list of this element's children.
  207. **
  208. ** If the optional SETTOALT is passed and SETTO is false, the
  209. ** new node's value is set to SETTOALT. See the attribute() method
  210. ** for an example use.
  211. **
  212. ** Returns a space seperated string composed all child MiniXMLNodes'
  213. ** numeric contents.
  214. **
  215. ** Note: ONLY numerical contents are included from the list of child MiniXMLNodes.
  216. **
  217. */
  218. function numeric ($setToPrimary = NULL, $setToAlternate=NULL)
  219. {
  220. $setTo = (is_null($setToPrimary) ? $setToAlternate : $setToPrimary);
  221. if (! is_null($setTo))
  222. {
  223. $this->createNode($setTo);
  224. }
  225. } /* end method numeric */
  226. /* comment CONTENTS
  227. **
  228. ** The comment() method allows you to add a new MiniXMLElementComment to this
  229. ** element's list of children.
  230. **
  231. ** Comments will return a <!-- CONTENTS --> string when the element's toString()
  232. ** method is called.
  233. **
  234. ** Returns a reference to the newly appended MiniXMLElementComment
  235. **
  236. */
  237. function & comment ($contents)
  238. {
  239. $newEl = new MiniXMLElementComment();
  240. $appendedComment =& $this->appendChild($newEl);
  241. $appendedComment->text($contents);
  242. return $appendedComment;
  243. } /* end method comment */
  244. /*
  245. ** docType DEFINITION
  246. **
  247. ** Append a new <!DOCTYPE DEFINITION [ ...]> element as a child of this
  248. ** element.
  249. **
  250. ** Returns the appended DOCTYPE element. You will normally use the returned
  251. ** element to add ENTITY elements, like
  252. ** $newDocType =& $xmlRoot->docType('spec SYSTEM "spec.dtd"');
  253. ** $newDocType->entity('doc.audience', 'public review and discussion');
  254. */
  255. function & docType ($definition)
  256. {
  257. $newElement = new MiniXMLElementDocType($definition);
  258. $appendedElement =& $this->appendChild($newElement);
  259. return $appendedElement;
  260. }
  261. /*
  262. ** entity NAME VALUE
  263. **
  264. ** Append a new <!ENTITY NAME "VALUE"> element as a child of this
  265. ** element.
  266. ** Returns the appended ENTITY element.
  267. */
  268. function & entity ($name,$value)
  269. {
  270. $newElement = new MiniXMLElementEntity($name, $value);
  271. $appendedEl =& $this->appendChild($newElement);
  272. return $appendedEl;
  273. }
  274. /*
  275. ** cdata CONTENTS
  276. **
  277. ** Append a new <![CDATA[ CONTENTS ]]> element as a child of this element.
  278. ** Returns the appended CDATA element.
  279. **
  280. */
  281. function & cdata ($contents)
  282. {
  283. $newElement = new MiniXMLElementCData($contents);
  284. $appendedChild =& $this->appendChild($newElement);
  285. return $appendedChild;
  286. }
  287. /* getValue
  288. **
  289. ** Returns a string containing the value of all the element's
  290. ** child MiniXMLNodes (and all the MiniXMLNodes contained within
  291. ** it's child MiniXMLElements, recursively).
  292. **
  293. ** Note: the seperator parameter remains officially undocumented
  294. ** since I'm not sure it will remain part of the API
  295. */
  296. function getValue ($seperator=' ')
  297. {
  298. $retStr = '';
  299. $valArray = array();
  300. for($i=0; $i < $this->xnumChildren; $i++)
  301. {
  302. $value = $this->xchildren[$i]->getValue();
  303. if (! is_null($value))
  304. {
  305. array_push($valArray, $value);
  306. }
  307. }
  308. if (count($valArray))
  309. {
  310. $retStr = implode($seperator, $valArray);
  311. }
  312. return $retStr;
  313. } /* end method getValue */
  314. /* getElement NAME
  315. ** Searches the element and it's children for an element with name NAME.
  316. **
  317. ** Returns a reference to the first MiniXMLElement with name NAME,
  318. ** if found, NULL otherwise.
  319. **
  320. ** NOTE: The search is performed like this, returning the first
  321. ** element that matches:
  322. **
  323. ** - Check this element for a match
  324. ** - Check this element's immediate children (in order) for a match.
  325. ** - Ask each immediate child (in order) to MiniXMLElement::getElement()
  326. ** (each child will then proceed similarly, checking all it's immediate
  327. ** children in order and then asking them to getElement())
  328. */
  329. function &getElement ($name)
  330. {
  331. if (MINIXML_DEBUG > 0)
  332. {
  333. $elname = $this->name();
  334. _MiniXMLLog("MiniXMLElement::getElement() called for $name on $elname.");
  335. }
  336. if (is_null($name))
  337. {
  338. return _MiniXMLError("MiniXMLElement::getElement() Must Pass Element name.");
  339. }
  340. /** Must only check children as checking $this results in an inability to
  341. *** fetch nested objects with the same name
  342. *** <tag>
  343. *** <nested>
  344. *** <nested>
  345. *** Can't get here from tag or from the first 'nested'
  346. *** </nested>
  347. *** </nested>
  348. *** </tag>
  349. if (MINIXML_CASESENSITIVE > 0)
  350. {
  351. if (strcmp($this->xname, $name) == 0)
  352. {
  353. /* This element is it * /
  354. return $this;
  355. }
  356. } else {
  357. if (strcasecmp($this->xname,$name) == 0)
  358. {
  359. return $this;
  360. }
  361. }
  362. ***** end commented out section ****
  363. */
  364. if (! $this->xnumChildren )
  365. {
  366. /* Not match here and and no kids - not found... */
  367. return NULL;
  368. }
  369. /* Try each child (immediate children take priority) */
  370. for ($i = 0; $i < $this->xnumChildren; $i++)
  371. {
  372. $childname = $this->xchildren[$i]->name();
  373. if ($childname)
  374. {
  375. if (MINIXML_CASESENSITIVE > 0)
  376. {
  377. /* case sensitive matches only */
  378. if (strcmp($name, $childname) == 0)
  379. {
  380. return $this->xchildren[$i];
  381. }
  382. } else {
  383. /* case INsensitive matching */
  384. if (strcasecmp($name, $childname) == 0)
  385. {
  386. return $this->xchildren[$i];
  387. }
  388. } /* end if case sensitive */
  389. } /* end if child has a name */
  390. } /* end loop over all my children */
  391. /* Use beautiful recursion, daniel san */
  392. for ($i = 0; $i < $this->xnumChildren; $i++)
  393. {
  394. $theelement =& $this->xchildren[$i]->getElement($name);
  395. if ($theelement)
  396. {
  397. if (MINIXML_DEBUG > 0)
  398. {
  399. _MiniXMLLog("MiniXMLElement::getElement() returning element $theelement");
  400. }
  401. return $theelement;
  402. }
  403. }
  404. /* Not found */
  405. return NULL;
  406. } /* end method getElement */
  407. /* getElementByPath PATH
  408. ** Attempts to return a reference to the (first) element at PATH
  409. ** where PATH is the path in the structure (relative to this element) to
  410. ** the requested element.
  411. **
  412. ** For example, in the document represented by:
  413. **
  414. ** <partRateRequest>
  415. ** <vendor>
  416. ** <accessid user="myusername" password="mypassword" />
  417. ** </vendor>
  418. ** <partList>
  419. ** <partNum>
  420. ** DA42
  421. ** </partNum>
  422. ** <partNum>
  423. ** D99983FFF
  424. ** </partNum>
  425. ** <partNum>
  426. ** ss-839uent
  427. ** </partNum>
  428. ** </partList>
  429. ** </partRateRequest>
  430. **
  431. ** $partRate =& $xmlDocument->getElement('partRateRequest');
  432. **
  433. ** $accessid =& $partRate->getElementByPath('vendor/accessid');
  434. **
  435. ** Will return what you expect (the accessid element with attributes user = "myusername"
  436. ** and password = "mypassword").
  437. **
  438. ** BUT be careful:
  439. ** $accessid =& $partRate->getElementByPath('partList/partNum');
  440. **
  441. ** will return the partNum element with the value "DA42". Other partNums are
  442. ** inaccessible by getElementByPath() - Use MiniXMLElement::getAllChildren() instead.
  443. **
  444. ** Returns the MiniXMLElement reference if found, NULL otherwise.
  445. */
  446. function &getElementByPath($path)
  447. {
  448. $names = split ("/", $path);
  449. $element = $this;
  450. foreach ($names as $elementName)
  451. {
  452. if ($element && $elementName) /* Make sure we didn't hit a dead end and that we have a name*/
  453. {
  454. /* Ask this element to get the next child in path */
  455. $element =& $element->getElement($elementName);
  456. }
  457. }
  458. return $element;
  459. } /* end method getElementByPath */
  460. /* numChildren [NAMED]
  461. **
  462. ** Returns the number of immediate children for this element
  463. **
  464. ** If the optional NAMED parameter is passed, returns only the
  465. ** number of immediate children named NAMED.
  466. */
  467. function numChildren ($named=NULL)
  468. {
  469. if (is_null($named))
  470. {
  471. return $this->xnumElementChildren;
  472. }
  473. /* We require only children named '$named' */
  474. $allkids =& $this->getAllChildren($named);
  475. return count($allkids);
  476. }
  477. /* getAllChildren [NAME]
  478. **
  479. ** Returns a reference to an array of all this element's MiniXMLElement children
  480. **
  481. ** Note: although the MiniXMLElement may contain MiniXMLNodes as children, these are
  482. ** not part of the returned list.
  483. **/
  484. function &getAllChildren ($name=NULL)
  485. {
  486. $retArray = array();
  487. $count = 0;
  488. if (is_null($name))
  489. {
  490. /* Return all element children */
  491. for($i=0; $i < $this->xnumChildren; $i++)
  492. {
  493. if (method_exists($this->xchildren[$i], 'MiniXMLElement'))
  494. {
  495. $retArray[$count++] =& $this->xchildren[$i];
  496. }
  497. }
  498. } else {
  499. /* Return only element children with name $name */
  500. for($i=0; $i < $this->xnumChildren; $i++)
  501. {
  502. if (method_exists($this->xchildren[$i], 'MiniXMLElement'))
  503. {
  504. if (MINIXML_CASESENSITIVE > 0)
  505. {
  506. if ($this->xchildren[$i]->name() == $name)
  507. {
  508. $retArray[$count++] =& $this->xchildren[$i];
  509. }
  510. } else {
  511. if (strcasecmp($this->xchildren[$i]->name(), $name) == 0)
  512. {
  513. $retArray[$count++] =& $this->xchildren[$i];
  514. }
  515. } /* end if case sensitive */
  516. } /* end if child is a MiniXMLElement object */
  517. } /* end loop over all children */
  518. } /* end if specific name was requested */
  519. return $retArray;
  520. } /* end method getAllChildren */
  521. function &insertChild (&$child, $idx=0)
  522. {
  523. if (! $this->_validateChild($child))
  524. {
  525. return;
  526. }
  527. /* Set the parent for the child element to this element if
  528. ** avoidLoops or MINIXML_AUTOSETPARENT is set
  529. */
  530. if ($this->xavoidLoops || (MINIXML_AUTOSETPARENT > 0) )
  531. {
  532. if ($this->xparent == $child)
  533. {
  534. $cname = $child->name();
  535. return _MiniXMLError("MiniXMLElement::insertChild() Tryng to append parent $cname as child of "
  536. . $this->xname );
  537. }
  538. $child->parent($this);
  539. }
  540. $nextIdx = $this->xnumChildren;
  541. $lastIdx = $nextIdx - 1;
  542. if ($idx > $lastIdx)
  543. {
  544. if ($idx > $nextIdx)
  545. {
  546. $idx = $lastIdx + 1;
  547. }
  548. $this->xchildren[$idx] = $child;
  549. $this->xnumChildren++;
  550. if ($this->isElement($child))
  551. {
  552. $this->xnumElementChildren++;
  553. }
  554. } elseif ($idx >= 0)
  555. {
  556. $removed = array_splice($this->xchildren, $idx);
  557. array_push($this->xchildren, $child);
  558. $numRemoved = count($removed);
  559. for($i=0; $i<$numRemoved; $i++)
  560. {
  561. array_push($this->xchildren, $removed[$i]);
  562. }
  563. $this->xnumChildren++;
  564. if ($this->isElement($child))
  565. {
  566. $this->xnumElementChildren++;
  567. }
  568. } else {
  569. $revIdx = (-1 * $idx) % $this->xnumChildren;
  570. $newIdx = $this->xnumChildren - $revIdx;
  571. if ($newIdx < 0)
  572. {
  573. return _MiniXMLError("Element::insertChild() Ended up with a negative index? ($newIdx)");
  574. }
  575. return $this->insertChild($child, $newIdx);
  576. }
  577. return $child;
  578. }
  579. /* appendChild CHILDELEMENT
  580. **
  581. ** appendChild is used to append an existing MiniXMLElement object to
  582. ** this element's list.
  583. **
  584. ** Returns a reference to the appended child element.
  585. **
  586. ** NOTE: Be careful not to create loops in the hierarchy, eg
  587. ** $parent->appendChild($child);
  588. ** $child->appendChild($subChild);
  589. ** $subChild->appendChild($parent);
  590. **
  591. ** If you want to be sure to avoid loops, set the MINIXML_AVOIDLOOPS define
  592. ** to 1 or use the avoidLoops() method (will apply to all children added with createChild())
  593. */
  594. function &appendChild (&$child)
  595. {
  596. if (! $this->_validateChild($child))
  597. {
  598. _MiniXMLLog("MiniXMLElement::appendChild() Could not validate child, aborting append");
  599. return NULL;
  600. }
  601. /* Set the parent for the child element to this element if
  602. ** avoidLoops or MINIXML_AUTOSETPARENT is set
  603. */
  604. if ($this->xavoidLoops || (MINIXML_AUTOSETPARENT > 0) )
  605. {
  606. if ($this->xparent == $child)
  607. {
  608. $cname = $child->name();
  609. return _MiniXMLError("MiniXMLElement::appendChild() Tryng to append parent $cname as child of "
  610. . $this->xname );
  611. }
  612. $child->parent($this);
  613. }
  614. $this->xnumElementChildren++; /* Note that we're addind a MiniXMLElement child */
  615. /* Add the child to the list */
  616. $idx = $this->xnumChildren++;
  617. $this->xchildren[$idx] =& $child;
  618. return $this->xchildren[$idx];
  619. } /* end method appendChild */
  620. /* prependChild CHILDELEMENT
  621. **
  622. ** prependChild is used to prepend an existing MiniXMLElement object to
  623. ** this element's list. The child will be positioned at the begining of
  624. ** the elements child list, thus it will be output first in the resulting XML.
  625. **
  626. ** Returns a reference to the prepended child element.
  627. */
  628. function &prependChild ($child)
  629. {
  630. if (! $this->_validateChild($child))
  631. {
  632. _MiniXMLLog("MiniXMLElement::prependChild - Could not validate child, aborting.");
  633. return NULL;
  634. }
  635. /* Set the parent for the child element to this element if
  636. ** avoidLoops or MINIXML_AUTOSETPARENT is set
  637. */
  638. if ($this->xavoidLoops || (MINIXML_AUTOSETPARENT > 0) )
  639. {
  640. if ($this->xparent == $child)
  641. {
  642. $cname = $child->name();
  643. return _MiniXMLError("MiniXMLElement::prependChild() Tryng to append parent $cname as child of "
  644. . $this->xname );
  645. }
  646. $child->parent($this);
  647. }
  648. $this->xnumElementChildren++; /* Note that we're adding a MiniXMLElement child */
  649. /* Add the child to the list */
  650. $idx = $this->xnumChildren++;
  651. array_unshift($this->xchildren, $child);
  652. return $this->xchildren[0];
  653. } /* end method prependChild */
  654. function _validateChild (&$child)
  655. {
  656. if (is_null($child))
  657. {
  658. return _MiniXMLError("MiniXMLElement::_validateChild() need to pass a non-NULL MiniXMLElement child.");
  659. }
  660. if (! method_exists($child, 'MiniXMLElement'))
  661. {
  662. return _MiniXMLError("MiniXMLElement::_validateChild() must pass a MiniXMLElement object to _validateChild.");
  663. }
  664. /* Make sure element is named */
  665. $cname = $child->name();
  666. if (is_null($cname))
  667. {
  668. _MiniXMLLog("MiniXMLElement::_validateChild() children must be named");
  669. return 0;
  670. }
  671. /* Check for loops */
  672. if ($child == $this)
  673. {
  674. _MiniXMLLog("MiniXMLElement::_validateChild() Trying to append self as own child!");
  675. return 0;
  676. } elseif ( $this->xavoidLoops && $child->parent())
  677. {
  678. _MiniXMLLog("MiniXMLElement::_validateChild() Trying to append a child ($cname) that already has a parent set "
  679. . "while avoidLoops is on - aborting");
  680. return 0;
  681. }
  682. return 1;
  683. }
  684. /* createChild ELEMENTNAME [VALUE]
  685. **
  686. ** Creates a new MiniXMLElement instance and appends it to the list
  687. ** of this element's children.
  688. ** The new child element's name is set to ELEMENTNAME.
  689. **
  690. ** If the optional VALUE (string or numeric) parameter is passed,
  691. ** the new element's text/numeric content will be set using VALUE.
  692. **
  693. ** Returns a reference to the new child element
  694. **
  695. ** Note: don't forget to use the =& (reference assignment) operator
  696. ** when calling createChild:
  697. **
  698. ** $newChild =& $myElement->createChild('newChildName');
  699. **
  700. */
  701. function & createChild ($name, $value=NULL)
  702. {
  703. if (! $name)
  704. {
  705. return _MiniXMLError("MiniXMLElement::createChild() Must pass a NAME to createChild.");
  706. }
  707. if (! is_string($name))
  708. {
  709. return _MiniXMLError("MiniXMLElement::createChild() Name of child must be a STRING");
  710. }
  711. $child = new MiniXMLElement($name);
  712. $appendedChild =& $this->appendChild($child);
  713. if (! $appendedChild )
  714. {
  715. _MiniXMLLog("MiniXMLElement::createChild() '$name' child NOT appended.");
  716. return NULL;
  717. }
  718. if (! is_null($value))
  719. {
  720. if (is_numeric($value))
  721. {
  722. $appendedChild->numeric($value);
  723. } elseif (is_string($value))
  724. {
  725. $appendedChild->text($value);
  726. }
  727. }
  728. $appendedChild->avoidLoops($this->xavoidLoops);
  729. return $appendedChild;
  730. } /* end method createChild */
  731. /* removeChild CHILD
  732. ** Removes CHILD from this element's list of children.
  733. **
  734. ** Returns the removed child, if found, NULL otherwise.
  735. */
  736. function &removeChild (&$child)
  737. {
  738. if (! $this->xnumChildren)
  739. {
  740. if (MINIXML_DEBUG > 0)
  741. {
  742. _MiniXMLLog("Element::removeChild() called for element without any children.") ;
  743. }
  744. return NULL;
  745. }
  746. $foundChild = NULL;
  747. $idx = 0;
  748. while ($idx < $this->xnumChildren && ! $foundChild)
  749. {
  750. if ($this->xchildren[$idx] == $child)
  751. {
  752. $foundChild =& $this->xchildren[$idx];
  753. } else {
  754. $idx++;
  755. }
  756. }
  757. if (! $foundChild)
  758. {
  759. if (MINIXML_DEBUG > 0)
  760. {
  761. _MiniXMLLog("Element::removeChild() No matching child found.") ;
  762. }
  763. return NULL;
  764. }
  765. array_splice($this->xchildren, $idx, 1);
  766. $this->xnumChildren--;
  767. if ($this->isElement($foundChild))
  768. {
  769. $this->xnumElementChildren--;
  770. }
  771. unset ($foundChild->xparent) ;
  772. return $foundChild;
  773. }
  774. /* removeAllChildren
  775. ** Removes all children of this element.
  776. **
  777. ** Returns an array of the removed children (which may be empty)
  778. */
  779. function &removeAllChildren ()
  780. {
  781. $emptyArray = array();
  782. if (! $this->xnumChildren)
  783. {
  784. return $emptyArray;
  785. }
  786. $retList =& $this->xchildren;
  787. $idx = 0;
  788. while ($idx < $this->xnumChildren)
  789. {
  790. unset ($retList[$idx++]->xparent);
  791. }
  792. $this->xchildren = array();
  793. $this->xnumElementChildren = 0;
  794. $this->xnumChildren = 0;
  795. return $retList;
  796. }
  797. function & remove ()
  798. {
  799. $parent =& $this->parent();
  800. if (!$parent)
  801. {
  802. _MiniXMLLog("XML::Mini::Element::remove() called for element with no parent set. Aborting.");
  803. return NULL;
  804. }
  805. $removed =& $parent->removeChild($this);
  806. return $removed;
  807. }
  808. /* parent NEWPARENT
  809. **
  810. ** The parent() method is used to get/set the element's parent.
  811. **
  812. ** If the NEWPARENT parameter is passed, sets the parent to NEWPARENT
  813. ** (NEWPARENT must be an instance of MiniXMLElement)
  814. **
  815. ** Returns a reference to the parent MiniXMLElement if set, NULL otherwise.
  816. **
  817. ** Note: This method is mainly used internally and you wouldn't normally need
  818. ** to use it.
  819. ** It get's called on element appends when MINIXML_AUTOSETPARENT or
  820. ** MINIXML_AVOIDLOOPS or avoidLoops() > 1
  821. **
  822. */
  823. function &parent (&$setParent)
  824. {
  825. if (! is_null($setParent))
  826. {
  827. /* Parents can only be MiniXMLElement objects */
  828. if (! $this->isElement($setParent))
  829. {
  830. return _MiniXMLError("MiniXMLElement::parent(): Must pass an instance of MiniXMLElement to set.");
  831. }
  832. $this->xparent = $setParent;
  833. }
  834. return $this->xparent;
  835. } /* end method parent */
  836. /* avoidLoops SETTO
  837. **
  838. ** The avoidLoops() method is used to get or set the avoidLoops flag for this element.
  839. **
  840. ** When avoidLoops is true, children with parents already set can NOT be appended to any
  841. ** other elements. This is overkill but it is a quick and easy way to avoid infinite loops
  842. ** in the heirarchy.
  843. **
  844. ** The avoidLoops default behavior is configured with the MINIXML_AVOIDLOOPS define but can be
  845. ** set on individual elements (and automagically all the element's children) with the
  846. ** avoidLoops() method.
  847. **
  848. ** Returns the current value of the avoidLoops flag for the element.
  849. **
  850. */
  851. function avoidLoops ($setTo = NULL)
  852. {
  853. if (! is_null($setTo))
  854. {
  855. $this->xavoidLoops = $setTo;
  856. }
  857. return $this->xavoidLoops;
  858. }
  859. /* toString [SPACEOFFSET]
  860. **
  861. ** toString returns an XML string based on the element's attributes,
  862. ** and content (recursively doing the same for all children)
  863. **
  864. ** The optional SPACEOFFSET parameter sets the number of spaces to use
  865. ** after newlines for elements at this level (adding 1 space per level in
  866. ** depth). SPACEOFFSET defaults to 0.
  867. **
  868. ** If SPACEOFFSET is passed as MINIXML_NOWHITESPACES.
  869. ** no \n or whitespaces will be inserted in the xml string
  870. ** (ie it will all be on a single line with no spaces between the tags.
  871. **
  872. ** Returns the XML string.
  873. **
  874. **
  875. ** Note: Since the toString() method recurses into child elements and because
  876. ** of the MINIXML_NOWHITESPACES and our desire to avoid testing for this value
  877. ** on every element (as it does not change), here we split up the toString method
  878. ** into 2 subs: toStringWithWhiteSpaces(DEPTH) and toStringNoWhiteSpaces().
  879. **
  880. ** Each of these methods, which are to be considered private (?), in turn recurses
  881. ** calling the appropriate With/No WhiteSpaces toString on it's children - thereby
  882. ** avoiding the test on SPACEOFFSET
  883. */
  884. function toString ($depth=0)
  885. {
  886. if ($depth == MINIXML_NOWHITESPACES)
  887. {
  888. return $this->toStringNoWhiteSpaces();
  889. } else {
  890. return $this->toStringWithWhiteSpaces($depth);
  891. }
  892. }
  893. function toStringWithWhiteSpaces ($depth=0)
  894. {
  895. $attribString = '';
  896. $elementName = $this->xname;
  897. $spaces = $this->_spaceStr($depth) ;
  898. $retString = "$spaces<$elementName";
  899. foreach ($this->xattributes as $attrname => $attrvalue)
  900. {
  901. $attribString .= "$attrname=\"$attrvalue\" ";
  902. }
  903. if ($attribString)
  904. {
  905. $attribString = rtrim($attribString);
  906. $retString .= " $attribString";
  907. }
  908. if (! $this->xnumChildren)
  909. {
  910. /* No kids -> no sub-elements, no text, nothing - consider a <unary/> element */
  911. $retString .= " />\n";
  912. return $retString;
  913. }
  914. /* If we've gotten this far, the element has
  915. ** kids or text - consider a <binary>otherstuff</binary> element
  916. */
  917. $onlyTxtChild = 0;
  918. if ($this->xnumChildren == 1 && ! $this->xnumElementChildren)
  919. {
  920. $onlyTxtChild = 1;
  921. }
  922. if ($onlyTxtChild)
  923. {
  924. $nextDepth = 0;
  925. $retString .= "> ";
  926. } else {
  927. $nextDepth = $depth+1;
  928. $retString .= ">\n";
  929. }
  930. for ($i=0; $i < $this->xnumChildren ; $i++)
  931. {
  932. if (method_exists($this->xchildren[$i], 'toStringWithWhiteSpaces') )
  933. {
  934. $newStr = $this->xchildren[$i]->toStringWithWhiteSpaces($nextDepth);
  935. if (! is_null($newStr))
  936. {
  937. if (! ( preg_match("/\n\$/", $newStr) || $onlyTxtChild) )
  938. {
  939. $newStr .= "\n";
  940. }
  941. $retString .= $newStr;
  942. }
  943. } else {
  944. _MiniXMLLog("Invalid child found in $elementName ". $this->xchildren[$i]->name() );
  945. } /* end if has a toString method */
  946. } /* end loop over all children */
  947. /* add the indented closing tag */
  948. if ($onlyTxtChild)
  949. {
  950. $retString .= " </$elementName>\n";
  951. } else {
  952. $retString .= "$spaces</$elementName>\n";
  953. }
  954. return $retString;
  955. } /* end method toString */
  956. function toStringNoWhiteSpaces ()
  957. {
  958. $retString = '';
  959. $attribString = '';
  960. $elementName = $this->xname;
  961. foreach ($this->xattributes as $attrname => $attrvalue)
  962. {
  963. $attribString .= "$attrname=\"$attrvalue\" ";
  964. }
  965. $retString = "<$elementName";
  966. if ($attribString)
  967. {
  968. $attribString = rtrim($attribString);
  969. $retString .= " $attribString";
  970. }
  971. if (! $this->xnumChildren)
  972. {
  973. /* No kids -> no sub-elements, no text, nothing - consider a <unary/> element */
  974. $retString .= " />";
  975. return $retString;
  976. }
  977. /* If we've gotten this far, the element has
  978. ** kids or text - consider a <binary>otherstuff</binary> element
  979. */
  980. $retString .= ">";
  981. /* Loop over all kids, getting associated strings */
  982. for ($i=0; $i < $this->xnumChildren ; $i++)
  983. {
  984. if (method_exists($this->xchildren[$i], 'toStringNoWhiteSpaces') )
  985. {
  986. $newStr = $this->xchildren[$i]->toStringNoWhiteSpaces();
  987. if (! is_null($newStr))
  988. {
  989. $retString .= $newStr;
  990. }
  991. } else {
  992. _MiniXMLLog("Invalid child found in $elementName");
  993. } /* end if has a toString method */
  994. } /* end loop over all children */
  995. /* add the indented closing tag */
  996. $retString .= "</$elementName>";
  997. return $retString;
  998. } /* end method toStringNoWhiteSpaces */
  999. /* toStructure
  1000. **
  1001. ** Converts an element to a structure - either an array or a simple string.
  1002. **
  1003. ** This method is used by MiniXML documents to perform their toArray() magic.
  1004. */
  1005. function & toStructure ()
  1006. {
  1007. $retHash = array();
  1008. $contents = "";
  1009. $numAdded = 0;
  1010. for($i=0; $i< $this->xnumChildren; $i++)
  1011. {
  1012. if ($this->isElement($this->xchildren[$i]))
  1013. {
  1014. $name = $this->xchildren[$i]->name();
  1015. if (array_key_exists($name, $retHash))
  1016. {
  1017. if (! (is_array($retHash[$name]) && array_key_exists('_num', $retHash[$name])) )
  1018. {
  1019. $retHash[$name] = array($retHash[$name],
  1020. $this->xchildren[$i]->toStructure());
  1021. $retHash[$name]['_num'] = 2;
  1022. } else {
  1023. array_push($retHash[$name], $this->xchildren[$i]->toStructure() );
  1024. $retHash[$name]['_num']++;
  1025. }
  1026. } else {
  1027. $retHash[$name] = $this->xchildren[$i]->toStructure();
  1028. }
  1029. $numAdded++;
  1030. } else {
  1031. $contents .= $this->xchildren[$i]->getValue();
  1032. }
  1033. }
  1034. foreach ($this->xattributes as $attrname => $attrvalue)
  1035. {
  1036. #array_push($retHash, array($attrname => $attrvalue));
  1037. $retHash["_attributes"][$attrname] = $attrvalue;
  1038. $numAdded++;
  1039. }
  1040. if ($numAdded)
  1041. {
  1042. if (! empty($contents))
  1043. {
  1044. $retHash['_content'] = $contents;
  1045. }
  1046. return $retHash;
  1047. } else {
  1048. return $contents;
  1049. }
  1050. } // end toStructure() method
  1051. /* isElement ELEMENT
  1052. ** Returns a true value if ELEMENT is an instance of MiniXMLElement,
  1053. ** false otherwise.
  1054. **
  1055. ** Note: Used internally.
  1056. */
  1057. function isElement (&$testme)
  1058. {
  1059. if (is_null($testme))
  1060. {
  1061. return 0;
  1062. }
  1063. return method_exists($testme, 'MiniXMLElement');
  1064. }
  1065. /* isNode NODE
  1066. ** Returns a true value if NODE is an instance of MiniXMLNode,
  1067. ** false otherwise.
  1068. **
  1069. ** Note: used internally.
  1070. */
  1071. function isNode (&$testme)
  1072. {
  1073. if (is_null($testme))
  1074. {
  1075. return 0;
  1076. }
  1077. return method_exists($testme, 'MiniXMLNode');
  1078. }
  1079. /* createNode NODEVALUE [ESCAPEENTITIES]
  1080. **
  1081. ** Private (?)
  1082. **
  1083. ** Creates a new MiniXMLNode instance and appends it to the list
  1084. ** of this element's children.
  1085. ** The new child node's value is set to NODEVALUE.
  1086. **
  1087. ** Returns a reference to the new child node.
  1088. **
  1089. ** Note: You don't need to use this method normally - it is used
  1090. ** internally when appending text() and such data.
  1091. **
  1092. */
  1093. function & createNode (&$value, $escapeEntities=NULL)
  1094. {
  1095. $newNode = new MiniXMLNode($value, $escapeEntities);
  1096. $appendedNode =& $this->appendNode($newNode);
  1097. return $appendedNode;
  1098. }
  1099. /* appendNode CHILDNODE
  1100. **
  1101. ** appendNode is used to append an existing MiniXMLNode object to
  1102. ** this element's list.
  1103. **
  1104. ** Returns a reference to the appended child node.
  1105. **
  1106. **
  1107. ** Note: You don't need to use this method normally - it is used
  1108. ** internally when appending text() and such data.
  1109. */
  1110. function &appendNode (&$node)
  1111. {
  1112. if (is_null($node))
  1113. {
  1114. return _MiniXMLError("MiniXMLElement::appendNode() need to pass a non-NULL MiniXMLNode.");
  1115. }
  1116. if (! method_exists($node, 'MiniXMLNode'))
  1117. {
  1118. return _MiniXMLError("MiniXMLElement::appendNode() must pass a MiniXMLNode object to appendNode.");
  1119. }
  1120. if (MINIXML_AUTOSETPARENT)
  1121. {
  1122. if ($this->xparent == $node)
  1123. {
  1124. return _MiniXMLError("MiniXMLElement::appendnode() Tryng to append parent $cname as node of "
  1125. . $this->xname );
  1126. }
  1127. $node->parent($this);
  1128. }
  1129. $idx = $this->xnumChildren++;
  1130. $this->xchildren[$idx] = $node;
  1131. return $this->xchildren[$idx];
  1132. }
  1133. /* Destructor to keep things clean -- patch by Ilya */
  1134. function __destruct()
  1135. {
  1136. for ($i = 0; $i < count($this->xchildren); ++$i)
  1137. $this->xchildren[$i]->xparent = null;
  1138. }
  1139. } /* end MiniXMLElement class definition */
  1140. /***************************************************************************************************
  1141. ****************************************************************************************************
  1142. *****
  1143. ***** MiniXMLElementComment
  1144. *****
  1145. ****************************************************************************************************
  1146. ***************************************************************************************************/
  1147. /* The MiniXMLElementComment class is a specific extension of the MiniXMLElement class.
  1148. **
  1149. ** It is used to create the special <!-- comment --> tags and an instance in created when calling
  1150. ** $elementObject->comment('this is a comment');
  1151. **
  1152. ** It's methods are the same as for MiniXMLElement - see those for documentation.
  1153. **/
  1154. class MiniXMLElementComment extends MiniXMLElement {
  1155. function MiniXMLElementComment ($name=NULL)
  1156. {
  1157. $this->MiniXMLElement('!--');
  1158. }
  1159. function toString ($depth=0)
  1160. {
  1161. if ($depth == MINIXML_NOWHITESPACES)
  1162. {
  1163. return $this->toStringNoWhiteSpaces();
  1164. } else {
  1165. return $this->toStringWithWhiteSpaces($depth);
  1166. }
  1167. }
  1168. function toStringWithWhiteSpaces ($depth=0)
  1169. {
  1170. $spaces = $this->_spaceStr($depth) ;
  1171. $retString = "$spaces<!-- \n";
  1172. if (! $this->xnumChildren)
  1173. {
  1174. /* No kids, no text - consider a <unary/> element */
  1175. $retString .= " -->\n";
  1176. return $retString;
  1177. }
  1178. /* If we get here, the element does have children... get their contents */
  1179. $nextDepth = $depth+1;
  1180. for ($i=0; $i < $this->xnumChildren ; $i++)
  1181. {
  1182. $retString .= $this->xchildren[$i]->toStringWithWhiteSpaces($nextDepth);
  1183. }
  1184. $retString .= "\n$spaces -->\n";
  1185. return $retString;
  1186. }
  1187. function toStringNoWhiteSpaces ()
  1188. {
  1189. $retString = '';
  1190. $retString = "<!-- ";
  1191. if (! $this->xnumChildren)
  1192. {
  1193. /* No kids, no text - consider a <unary/> element */
  1194. $retString .= " -->";
  1195. return $retString;
  1196. }
  1197. /* If we get here, the element does have children... get their contents */
  1198. for ($i=0; $i < $this->xnumChildren ; $i++)
  1199. {
  1200. $retString .= $this->xchildren[$i]->toStringNoWhiteSpaces();
  1201. }
  1202. $retString .= " -->";
  1203. return $retString;
  1204. }
  1205. }
  1206. /***************************************************************************************************
  1207. ****************************************************************************************************
  1208. *****
  1209. ***** MiniXMLElementCData
  1210. *****
  1211. ****************************************************************************************************
  1212. ***************************************************************************************************/
  1213. /* The MiniXMLElementCData class is a specific extension of the MiniXMLElement class.
  1214. **
  1215. ** It is used to create the special <![CDATA [ data ]]> tags and an instance in created when calling
  1216. ** $elementObject->cdata('data');
  1217. **
  1218. ** It's methods are the same as for MiniXMLElement - see those for documentation.
  1219. **/
  1220. class MiniXMLElementCData extends MiniXMLElement {
  1221. function MiniXMLElementCData ($contents)
  1222. {
  1223. $this->MiniXMLElement('CDATA');
  1224. if (! is_null($contents))
  1225. {
  1226. $this->createNode($contents, 0) ;
  1227. }
  1228. }
  1229. function toStringNoWhiteSpaces ()
  1230. {
  1231. return $this->toString(MINIXML_NOWHITESPACES);
  1232. }
  1233. function toStringWithWhiteSpaces ($depth=0)
  1234. {
  1235. return $this->toString($depth);
  1236. }
  1237. function toString ($depth=0)
  1238. {
  1239. $spaces = '';
  1240. if ($depth != MINIXML_NOWHITESPACES)
  1241. {
  1242. $spaces = $this->_spaceStr($depth);
  1243. }
  1244. $retString = "$spaces<![CDATA[ ";
  1245. if (! $this->xnumChildren)
  1246. {
  1247. $retString .= "]]>\n";
  1248. return $retString;
  1249. }
  1250. for ( $i=0; $i < $this->xnumChildren; $i++)
  1251. {
  1252. $retString .= $this->xchildren[$i]->getValue();
  1253. }
  1254. $retString .= " ]]>\n";
  1255. return $retString;
  1256. }
  1257. }
  1258. /***************************************************************************************************
  1259. ****************************************************************************************************
  1260. *****
  1261. ***** MiniXMLElementDocType
  1262. *****
  1263. ****************************************************************************************************
  1264. ***************************************************************************************************/
  1265. /* The MiniXMLElementDocType class is a specific extension of the MiniXMLElement class.
  1266. **
  1267. ** It is used to create the special <!DOCTYPE def [...]> tags and an instance in created when calling
  1268. ** $elementObject->comment('');
  1269. **
  1270. ** It's methods are the same as for MiniXMLElement - see those for documentation.
  1271. **/
  1272. class MiniXMLElementDocType extends MiniXMLElement {
  1273. var $dtattr;
  1274. function MiniXMLElementDocType ($attr)
  1275. {
  1276. $this->MiniXMLElement('DOCTYPE');
  1277. $this->dtattr = $attr;
  1278. }
  1279. function toString ($depth)
  1280. {
  1281. if ($depth == MINIXML_NOWHITESPACES)
  1282. {
  1283. return $this->toStringNoWhiteSpaces();
  1284. } else {
  1285. return $this->toStringWithWhiteSpaces($depth);
  1286. }
  1287. }
  1288. function toStringWithWhiteSpaces ($depth=0)
  1289. {
  1290. $spaces = $this->_spaceStr($depth);
  1291. $retString = "$spaces<!DOCTYPE " . $this->dtattr . " [\n";
  1292. if (! $this->xnumChildren)
  1293. {
  1294. $retString .= "]>\n";
  1295. return $retString;
  1296. }
  1297. $nextDepth = $depth + 1;
  1298. for ( $i=0; $i < $this->xnumChildren; $i++)
  1299. {
  1300. $retString .= $this->xchildren[$i]->toStringWithWhiteSpaces($nextDepth);
  1301. }
  1302. $retString .= "\n$spaces]>\n";
  1303. return $retString;
  1304. }
  1305. function toStringNoWhiteSpaces ()
  1306. {
  1307. $retString = "<!DOCTYPE " . $this->dtattr . " [ ";
  1308. if (! $this->xnumChildren)
  1309. {
  1310. $retString .= "]>\n";
  1311. return $retString;
  1312. }
  1313. for ( $i=0; $i < $this->xnumChildren; $i++)
  1314. {
  1315. $retString .= $this->xchildren[$i]->toStringNoWhiteSpaces();
  1316. }
  1317. $retString .= " ]>\n";
  1318. return $retString;
  1319. }
  1320. }
  1321. /***************************************************************************************************
  1322. ****************************************************************************************************
  1323. *****
  1324. ***** MiniXMLElementEntity
  1325. *****
  1326. ****************************************************************************************************
  1327. ***************************************************************************************************/
  1328. /* The MiniXMLElementEntity class is a specific extension of the MiniXMLElement class.
  1329. **
  1330. ** It is used to create the special <!ENTITY name "val"> tags and an instance in created when calling
  1331. ** $elementObject->comment('');
  1332. **
  1333. ** It's methods are the same as for MiniXMLElement - see those for documentation.
  1334. **/
  1335. class MiniXMLElementEntity extends MiniXMLElement {
  1336. function MiniXMLElementEntity ($name, $value=NULL)
  1337. {
  1338. $this->MiniXMLElement($name);
  1339. if (! is_null ($value))
  1340. {
  1341. $this->createNode($value, 0);
  1342. }
  1343. }
  1344. function toString ($depth = 0)
  1345. {
  1346. $spaces = '';
  1347. if ($depth != MINIXML_NOWHITESPACES)
  1348. {
  1349. $spaces = $this->_spaceStr($depth);
  1350. }
  1351. $retString = "$spaces<!ENTITY " . $this->name();
  1352. if (! $this->xnumChildren)
  1353. {
  1354. $retString .= ">\n";
  1355. return $retString;
  1356. }
  1357. $nextDepth = ($depth == MINIXML_NOWHITESPACES) ? MINIXML_NOWHITESPACES
  1358. : $depth + 1;
  1359. $retString .= '"';
  1360. for ( $i=0; $i < $this->xnumChildren; $i++)
  1361. {
  1362. $retString .= $this->xchildren[$i]->toString(MINIXML_NOWHITESPACES);
  1363. }
  1364. $retString .= '"';
  1365. $retString .= " >\n";
  1366. return $retString;
  1367. }
  1368. function toStringNoWhiteSpaces ()
  1369. {
  1370. return $this->toString(MINIXML_NOWHITESPACES);
  1371. }
  1372. function toStringWithWhiteSpaces ($depth=0)
  1373. {
  1374. return $this->toString($depth);
  1375. }
  1376. }