50 if (!empty($this->_parent)) {
53 $arr = $this->xpath(
'..');
54 if (!isset($arr[0])) {
55 throw new \InvalidArgumentException(
'Root node could not be unset.');
70 if (!$this->children()) {
75 foreach ($this->children() as $k => $child) {
89 $attrs = $this->attributes();
90 return isset($attrs[
$name]) ? (string)$attrs[
$name] :
null;
105 # $node = $this->xpath($path); 107 if (is_array(
$path)) {
113 if (strpos(
$path,
"@") ===
false) {
114 $pathArr = explode(
'/',
$path);
116 $regex =
"#([^@/\\\"]+(?:@[^=/]+=(?:\\\"[^\\\"]*\\\"|[^/]*))?)/?#";
117 $pathArr = $pathMatches = [];
118 if (preg_match_all($regex,
$path, $pathMatches)) {
119 $pathArr = $pathMatches[1];
124 foreach ($pathArr as $nodeName) {
125 if (strpos($nodeName,
'@') !==
false) {
126 $a = explode(
'@', $nodeName);
127 $b = explode(
'=', $a[1]);
129 $attributeName = $b[0];
130 $attributeValue = $b[1];
134 $attributeValue = trim($attributeValue,
'"');
136 foreach ($desc->{$nodeName} as $subdesc) {
137 if ((
string)$subdesc[$attributeName] === $attributeValue) {
147 $desc = $desc->{$nodeName};
165 if (!isset($this->attributes()[
$name])) {
179 return $this->_asArray();
188 return $this->_asArray(
true);
202 foreach ($this->attributes() as $attributeName =>
$attribute) {
209 if ($this->hasChildren()) {
210 foreach ($this->children() as $childName => $child) {
211 $result[$childName] = $child->_asArray($isCanonical);
236 if (is_numeric($level)) {
237 $pad = str_pad(
'', $level * 3,
' ', STR_PAD_LEFT);
244 $out = $pad .
'<' . $this->getName();
249 $out .=
' ' . $key .
'="' . str_replace(
'"',
'\"', (
string)
$value) .
'"';
256 $out .=
' xsi:' . $key .
'="' . str_replace(
'"',
'\"', (
string)
$value) .
'"';
260 if ($this->hasChildren()) {
262 $value = trim((
string)$this);
264 $out .= $this->xmlentities(
$value);
267 foreach ($this->children() as $child) {
268 $out .= $child->asNiceXml(
'', is_numeric($level) ? $level + 1 :
true);
270 $out .= $pad .
'</' . $this->getName() .
'>' . $nl;
274 $out .=
'>' . $this->xmlentities(
$value) .
'</' . $this->getName() .
'>' . $nl;
280 if ((0 === $level ||
false === $level) && !empty($filename)) {
296 foreach ($this->children() as $child) {
297 $out .= $child->asNiceXml($level);
316 [
'&',
'"',
"'",
'<',
'>'],
317 [
'&',
'"',
''',
'<',
'>'],
333 $child = $this->addChild(
$source->getName());
335 $child = $this->addChild(
$source->getName(), $this->xmlentities(
$source));
337 $child->setParent($this);
341 $child->addAttribute($key, $this->xmlentities(
$value));
344 foreach (
$source->children() as $sourceChild) {
345 $child->appendChild($sourceChild);
366 foreach (
$source->children() as $child) {
367 $this->extendChild($child, $overwrite);
388 $sourceName =
$source->getName();
391 $sourceChildren =
$source->children();
395 if (isset($this->{$sourceName})) {
397 if ($this->{$sourceName}->hasChildren()) {
401 unset($this->{$sourceName});
407 $targetChild = $this->addChild($sourceName,
$source->xmlentities());
408 $targetChild->setParent($this);
410 $targetChild->addAttribute($key, $this->xmlentities(
$value));
415 if (isset($this->{$sourceName})) {
416 $targetChild = $this->{$sourceName};
419 if ($targetChild ===
null) {
421 $targetChild = $this->addChild($sourceName);
422 $targetChild->setParent($this);
424 $targetChild->addAttribute($key, $this->xmlentities(
$value));
429 foreach ($sourceChildren as $childKey => $childNode) {
430 $targetChild->extendChild($childNode, $overwrite);
446 $arr1 = explode(
'/',
$path);
448 foreach ($arr1 as $v) {
453 $last =
sizeof($arr) - 1;
455 foreach ($arr as
$i => $nodeName) {
457 if (!isset($node->{$nodeName}) || $overwrite) {
458 $node->{$nodeName} =
$value;
461 if (!isset($node->{$nodeName})) {
462 $node = $node->addChild($nodeName);
464 $node = $node->{$nodeName};
479 $uniqueId = uniqid();
480 $this[
'_unique_id'] = $uniqueId;
481 $children = $this->getParent()->xpath(
'*');
483 if (
$children[
$i - 1][0][
'_unique_id'] == $uniqueId) {
setAttribute($name, $value)
setNode($path, $value, $overwrite=true)
_asArray($isCanonical=false)
extend($source, $overwrite=false)
asNiceXml($filename='', $level=0)
extendChild($source, $overwrite=false)
if(!isset($_GET['name'])) $name