PageRenderTime 49ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/administrator/components/com_jce/helpers/xml.php

https://github.com/cavila/Astica
PHP | 68 lines | 47 code | 9 blank | 12 comment | 11 complexity | 03270533d0247666a8e10672d0bdf5db MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0, Apache-2.0, BSD-3-Clause
  1. <?php
  2. /**
  3. * @version $Id: xml.php 201 2011-05-08 16:27:15Z happy_noodle_boy $
  4. * @package JCE
  5. * @copyright Copyright Š 2009-2011 Ryan Demmer. All rights reserved.
  6. * @copyright Copyright Š 2005 - 2007 Open Source Matters. All rights reserved.
  7. * @license GNU/GPL 2 or later
  8. * This version may have been modified pursuant
  9. * to the GNU General Public License, and as distributed it includes or
  10. * is derivative of works licensed under the GNU General Public License or
  11. * other free or open source software licenses.
  12. */
  13. class WFXMLHelper
  14. {
  15. function getElement($xml, $name, $default = '')
  16. {
  17. if (is_a($xml, 'JSimpleXML')) {
  18. $element = $xml->document->getElementByPath($name);
  19. return $element ? $element->data() : $default;
  20. } else {
  21. return (string)$xml->$name;
  22. }
  23. }
  24. function getElements($xml, $name)
  25. {
  26. if (is_a($xml, 'JSimpleXML')) {
  27. $element = $xml->document->getElementByPath($name);
  28. if (is_a($element, 'JSimpleXMLElement') && count($element->children())) {
  29. return $element;
  30. }
  31. } else {
  32. return $xml->$name;
  33. }
  34. return array();
  35. }
  36. function getAttribute($xml, $name, $default = '')
  37. {
  38. if (is_a($xml, 'JSimpleXML')) {
  39. $value = (string) $xml->document->attributes($name);
  40. } else {
  41. $value = (string)$xml->attributes()->$name;
  42. }
  43. return $value ? $value : $default;
  44. }
  45. function getXML($file)
  46. {
  47. // use JSimpleXML
  48. if (!method_exists('JFactory', 'getXML')) {
  49. $xml = JFactory::getXMLParser('Simple');
  50. if (!$xml->loadFile($file)) {
  51. unset($xml);
  52. return false;
  53. }
  54. } else {
  55. $xml = WFXMLElement::getXML($file);
  56. }
  57. return $xml;
  58. }
  59. }