Joomla Platform  13.1
Documentation des API du framework Joomla Platform
 Tout Classes Espaces de nommage Fichiers Fonctions Variables Pages
xmlelement.php
Aller à la documentation de ce fichier.
1 <?php
2 /**
3  * @package Joomla.Legacy
4  * @subpackage Utilities
5  *
6  * @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
7  * @license GNU General Public License version 2 or later; see LICENSE
8  */
9 
10 defined('JPATH_PLATFORM') or die;
11 
12 JLog::add('JXMLElement is deprecated. Use SimpleXMLElement.', JLog::WARNING, 'deprecated');
13 
14 /**
15  * Wrapper class for php SimpleXMLElement.
16  *
17  * @package Joomla.Legacy
18  * @subpackage Utilities
19  * @since 11.1
20  * @deprecated 13.3 (Platform) & 4.0 (CMS) - Use SimpleXMLElement instead.
21  */
22 class JXMLElement extends SimpleXMLElement
23 {
24  /**
25  * Get the name of the element.
26  *
27  * @return string
28  *
29  * @since 11.1
30  * @deprecated 13.3 Use SimpleXMLElement::getName() instead.
31  */
32  public function name()
33  {
34  JLog::add('JXMLElement::name() is deprecated, use SimpleXMLElement::getName() instead.', JLog::WARNING, 'deprecated');
35  return (string) $this->getName();
36  }
37 
38  /**
39  * Return a well-formed XML string based on SimpleXML element
40  *
41  * @param boolean $compressed Should we use indentation and newlines ?
42  * @param string $indent Indention character.
43  * @param integer $level The level within the document which informs the indentation.
44  *
45  * @return string
46  *
47  * @since 11.1
48  * @deprecated 13.3 Use SimpleXMLElement::asXML() instead.
49  */
50  public function asFormattedXML($compressed = false, $indent = "\t", $level = 0)
51  {
52  JLog::add('JXMLElement::asFormattedXML() is deprecated, use SimpleXMLElement::asXML() instead.', JLog::WARNING, 'deprecated');
53  $out = '';
54 
55  // Start a new line, indent by the number indicated in $level
56  $out .= ($compressed) ? '' : "\n" . str_repeat($indent, $level);
57 
58  // Add a <, and add the name of the tag
59  $out .= '<' . $this->getName();
60 
61  // For each attribute, add attr="value"
62  foreach ($this->attributes() as $attr)
63  {
64  $out .= ' ' . $attr->getName() . '="' . htmlspecialchars((string) $attr, ENT_COMPAT, 'UTF-8') . '"';
65  }
66 
67  // If there are no children and it contains no data, end it off with a />
68  if (!count($this->children()) && !(string) $this)
69  {
70  $out .= " />";
71  }
72  else
73  {
74  // If there are children
75  if (count($this->children()))
76  {
77  // Close off the start tag
78  $out .= '>';
79 
80  $level++;
81 
82  // For each child, call the asFormattedXML function (this will ensure that all children are added recursively)
83  foreach ($this->children() as $child)
84  {
85  $out .= $child->asFormattedXML($compressed, $indent, $level);
86  }
87 
88  $level--;
89 
90  // Add the newline and indentation to go along with the close tag
91  $out .= ($compressed) ? '' : "\n" . str_repeat($indent, $level);
92 
93  }
94  elseif ((string) $this)
95  {
96  // If there is data, close off the start tag and add the data
97  $out .= '>' . htmlspecialchars((string) $this, ENT_COMPAT, 'UTF-8');
98  }
99 
100  // Add the end tag
101  $out .= '</' . $this->getName() . '>';
102  }
103 
104  return $out;
105  }
106 }