/** * Generates a string representation of the node and its children * @param boolean True if HTML readable output is desired * @param boolean True if illegal xml characters should be converted to entities * @return string The string representation */ function toString($htmlSafe = false, $subEntities = false) { require_once DOMIT_INCLUDE_PATH . 'xml_domit_utilities.php'; global $DOMIT_defined_entities_flip; $result = $subEntities ? DOMIT_Utilities::convertEntities($this->nodeValue, $DOMIT_defined_entities_flip) : $this->nodeValue; if ($htmlSafe) { $result = $this->forHTML($result); } return $result; }
/** * Gets a normalized (formatted for readability) representation of the current element * @param Object The node to be normalized * @param string The current normalized text * @param int The level in the DOM hierarchy where the node is located * @param boolean True if illegal xml characters in text nodes and attributes should be converted to entities * @param array User defined translation table for entities * @return string The normalized string representation */ public static function getNormalizedElementString(&$node, $response, $node_level, $subEntities, $definedEntities) { $response .= '<' . $node->nodeName; //get attributes text if (is_object($node->attributes)) { //DOMIT $response .= $node->attributes->toString(false, $subEntities); /* if ($node->ownerDocument->isNamespaceAware) { foreach ($node->namespaceURIMap as $key => $value) { $response .= ' xmlns:' . $value . '="' . $key . '"'; } } */ } else { //DOMIT_Lite foreach ($node->attributes as $key => $value) { $response .= ' ' . $key . '="'; $response .= $subEntities ? DOMIT_Utilities::convertEntities($value, $definedEntities) : $value; $response .= '"'; } } $node_level++; //if node is childless if ($node->childCount == 0) { if ($node->ownerDocument->doExpandEmptyElementTags) { if (in_array($node->nodeName, $node->ownerDocument->expandEmptyElementExceptions)) { $response .= ' />'; } else { $response .= '></' . $node->nodeName . '>'; } } else { if (in_array($node->nodeName, $node->ownerDocument->expandEmptyElementExceptions)) { $response .= '></' . $node->nodeName . '>'; } else { $response .= ' />'; } } } else { $response .= '>'; //get children $myNodes =& $node->childNodes; $total = $node->childCount; //no indentation if first child is a text node if (!DOMIT_Utilities::isTextNode($node->firstChild)) { $response .= DOMIT_Utilities::getIndentation($node_level); } for ($i = 0; $i < $total; $i++) { $child =& $myNodes[$i]; $response .= DOMIT_Utilities::getNormalizedString($child, $node_level, $subEntities, $definedEntities); } $response .= '</' . $node->nodeName . '>'; } $node_level--; if ($node->nextSibling == null) { $node_level--; $response .= DOMIT_Utilities::getIndentation($node_level); } else { //no indentation if next sibling is a text node if (!DOMIT_Utilities::isTextNode($node->nextSibling)) { $response .= DOMIT_Utilities::getIndentation($node_level); } } return $response; }