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