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