private function _getComparableXmlString(\DOMNode $node) { if ($node instanceof \DOMDocument) { return $node->C14N(); } $dom = new \DOMDocument(); $dom->appendChild($dom->importNode($node, true)); return $dom->C14N(); }
/** * @return string */ public function getChildrenAsString() { return $this->node->C14N(); }
/** * Returns the normalized, whitespace-cleaned, and indented textual * representation of a DOMNode. * * @param DOMNode $node * @param boolean $canonicalize * @param boolean $ignoreCase * @return string */ private function nodeToText(DOMNode $node, $canonicalize, $ignoreCase) { if ($canonicalize) { $document = new DOMDocument(); $document->loadXML($node->C14N()); $node = $document; } if ($node instanceof DOMDocument) { $document = $node; } else { $document = $node->ownerDocument; } $document->formatOutput = true; $document->normalizeDocument(); if ($node instanceof DOMDocument) { $text = $node->saveXML(); } else { $text = $document->saveXML($node); } if ($ignoreCase) { $text = strtolower($text); } return $text; }
public function getXML() { return $this->retInutNFe->C14N(); }
/** * Pretty print XML tree. * * @param \DOMNode $element Element. * @return string */ public function cout(\DOMNode $element) { if (1 === $this->_color) { return $element->C14N(); } $out = null; $nodes = $element->childNodes; for ($i = 0, $max = $nodes->length; $i < $max; ++$i) { $node = $nodes->item($i); switch ($node->nodeType) { case XML_ELEMENT_NODE: $out .= $this->color('<', 'oc') . $this->color($node->tagName, 'tagname'); foreach ($node->attributes as $attr) { $out .= ' ' . $this->color($attr->name, 'attrname') . $this->color('=', '=') . $this->color('"', 'q') . $this->color($attr->value, 'attrvalue') . $this->color('"', 'q'); } $out .= $this->color('>', 'oc') . $this->cout($node) . $this->color('</', 'oc') . $this->color($node->tagName, 'tagname') . $this->color('>', 'oc'); break; case XML_TEXT_NODE: $out .= $this->color($node->wholeText, 'text'); break; case XML_CDATA_SECTION_NODE: break; case XML_ENTITY_REF_NODE: $out .= $this->color('&' . $node->name . ';', 'entity'); break; case XML_ENTITY_NODE: break; case XML_PI_NODE: $out .= $this->color('<?' . $node->target . ' ' . $node->data . '?>', 'pi'); break; case XML_COMMENT_NODE: $out .= $this->color('<!--' . $node->data . '-->', 'comment'); break; default: var_dump($node->nodeType); } } return $out; }
/** * Canonicalizes a DOM document or a single DOM node * * @param \DOMNode $data Node(s) to be canonicalized * @throws \UnexpectedValueException If the canonicalization process failed * @return string|bool Canonicalized node(s), or false on failure */ protected function canonicalize(\DOMNode $object) { $options = $this->c14nOptionMapping[$this->canonicalMethod]; // canonicalize the provided data with the preset options $c14nData = $object->C14N($options['exclusive'], $options['withComments']); if (is_string($c14nData) && strlen($c14nData)) { return $c14nData; } throw new \UnexpectedValueException('Unable to canonicalize the provided DOM document'); }
/** * Convert Code * * Convert code tags by indenting blocks of code and wrapping single lines in backticks. * * @param DOMNode $node * @return string */ private function convert_code($node) { // Store the content of the code block in an array, one entry for each line $markdown = ''; $code_content = html_entity_decode($node->C14N()); $code_content = str_replace(array("<code>", "</code>"), "", $code_content); $code_content = str_replace(array("<pre>", "</pre>"), "", $code_content); $lines = preg_split('/\\r\\n|\\r|\\n/', $code_content); $total = count($lines); // If there's more than one line of code, prepend each line with four spaces and no backticks. if ($total > 1 || $node->nodeName === 'pre') { // Remove the first and last line if they're empty $first_line = trim($lines[0]); $last_line = trim($lines[$total - 1]); $first_line = trim($first_line, "
"); //trim XML style carriage returns too $last_line = trim($last_line, "
"); if (empty($first_line)) { array_shift($lines); } if (empty($last_line)) { array_pop($lines); } $count = 1; foreach ($lines as $line) { $line = str_replace('
', '', $line); $markdown .= " " . $line; // Add newlines, except final line of the code if ($count != $total) { $markdown .= PHP_EOL; } $count++; } $markdown .= PHP_EOL; } else { // There's only one line of code. It's a code span, not a block. Just wrap it with backticks. $markdown .= "`" . $lines[0] . "`"; } return $markdown; }
/** * Canonicalizes XML node. * * @see Sisyphus_C14n_C14nInterface::canonicalize() * Sisyphus_C14n_C14nInterface::canonicalize() * * @link http://php.net/manual/en/domnode.c14n.php DOMNode::C14N() * * @param DOMNode $xml DOM node to canonicalize * * @return string canonicalized XML as string */ public function canonicalize(DOMNode $xml) { $inclusiveNamespaces = $this->getContext()->isExclusive() ? $this->getContext()->getInclusiveNamespaces() : null; return $xml->C14N($this->getContext()->isExclusive(), $this->getContext()->isWithComments(), $this->prepareXpathData(), $inclusiveNamespaces); }
/** * Get the inner content of a DOMNode. * * @param \DOMNode $node A DOMNode instance * * @return string The inner content */ protected function getInner(\DOMNode $node) { $c14n = $node->C14N(); $begin = strpos($c14n, '>'); $end = strrpos($c14n, '<'); $content = substr($c14n, $begin + 1, $end - $begin - 1); return $content; }