/** * Builder::_addArray2Node() * Internal use only. * Add array to the specified node. Node will be DOMnode only. * "#text" index will be translated as content of the node, not as child node. * If an index of the element is integer the element will be added as "item" node with attribute "_key" set to element index. * If asItem set to TRUE - all elements will be added as "item" in any case. * Array indexes listed in attrs will be transformed to attributes not to nodes. * * @param array $array - array to be added. * @param DOMnode $node - node that array will be added to. * @param bool $asItems - if TRUE all elements will be added as "item" tags with "_key" attribute set to array index. * @param array $attrs - list of index that will be traslated to attributes not to nodes. * @return DOMnode node - node that array added into (tha same as $node on input). */ private function _addArray2Node($array, $node, $asItems = false, $attrs = array()) { if (!empty($array['#text'])) { $t = $this->doc->createTextNode($array['#text']); unset($array['#text']); $node->appendChild($t); } foreach ($array as $idx => $value) { $attr_list = array(); if (is_integer($idx) || $asItems) { $attr_list[BUILDER_KEY_WORD] = $idx; $idx = BUILDER_ITEM_WORD; } // if if (is_array($value)) { $new = $this->doc->createElement($idx); foreach ($value as $attr => $avalue) { if (in_array($attr, $attrs, true)) { unset($value[$attr]); $attr_list[$attr] = $avalue; } } // foreach $this->_addArray2Node($value, $new, $asItems, $attrs); } else { //-------------------------------------------------------------------------------- // FIX: unterminated entity reference // // $new = $this->doc->createElement($idx, $value); //-------------------------------------------------------------------------------- $new = $this->doc->createElement($idx); if ($idx == 'xml') { $new = $this->createXMLNode('<xml>' . $value . '</xml>'); } else { $new->nodeValue = trim(htmlspecialchars($value, ENT_QUOTES, 'UTF-8')); } //-------------------------------------------------------------------------------- } // if foreach ($attr_list as $attr => $avalue) { $new->setAttribute($attr, $avalue); } // foreach if (!empty($attr_list['id'])) { $new->setIdAttribute('id', true); } // if $node->appendChild($new); } // foreach return $node; }
/** * Builder::_addArray2Node() * Internal use only. * Add array to the specified node. Node will be DOMnode only. * "#text" index will be translated as content of the node, not as child node. * If an index of the element is integer the element will be added as "item" node with attribute "_key" set to element index. * If asItem set to TRUE - all elements will be added as "item" in any case. * Array indexes listed in attrs will be transformed to attributes not to nodes. * * @param array $array - array to be added. * @param DOMnode $node - node that array will be added to. * @param bool $asItems - if TRUE all elements will be added as "item" tags with "_key" attribute set to array index. * @param array $attrs - list of index that will be traslated to attributes not to nodes. * @return DOMnode node - node that array added into (tha same as $node on input). */ private function _addArray2Node($array, $node, $asItems = false, $attrs = array(), $child_cdata = false) { if (!empty($array['#text'])) { $t = $this->doc->createTextNode($array['#text']); unset($array['#text']); $node->appendChild($t); } foreach ($array as $idx => $value) { $attr_list = array(); if (is_integer($idx) || $asItems) { $attr_list[BUILDER_KEY_WORD] = $idx; $idx = BUILDER_ITEM_WORD; } // if if (is_array($value)) { $new = $this->doc->createElement($idx); foreach ($value as $attr => $avalue) { if (in_array($attr, $attrs, true)) { unset($value[$attr]); $attr_list[$attr] = $avalue; } } // foreach $this->_addArray2Node($value, $new, $asItems, $attrs, $idx == 'cells' ? true : false); } else { //-------------------------------------------------------------------------------- // FIX: unterminated entity reference // // $new = $this->doc->createElement($idx, $value); //-------------------------------------------------------------------------------- $new = $this->doc->createElement($idx); if (preg_match("|<\\!\\[CDATA\\[(.*)\\]\\]>|", $value, $matches)) { $cd = $this->doc->createCDATASection($matches[1]); $new->appendChild($cd); } else { $new->nodeValue = trim(htmlspecialchars($value, ENT_QUOTES, 'UTF-8')); } //-------------------------------------------------------------------------------- } // if foreach ($attr_list as $attr => $avalue) { $new->setAttribute($attr, $avalue); } // foreach if (!empty($attr_list['id'])) { $new->setIdAttribute('id', true); } // if $node->appendChild($new); } // foreach return $node; }