/** * Generates canonical representation of an XML document. * * <blockquote> Root Node- The root node is the parent of the * top-level document element. The result of processing each of * its child nodes that is in the node-set in document order. The * root node does not generate a byte order mark, XML declaration, * nor anything from within the document type declaration. * </blockquote> * * Note: in addition to the root XML element, XML document can * contain other nodes included in the canonical output on the top * level (e.g. processing instructions and comments) * * @link http://www.w3.org/TR/xml-c14n#ProcessingModel Canonical * XML Processing Model * * @param DOMDocument $node document being canonicalized * * @return string canonicalized string representation */ public function canonicalize($node) { $nodeStrings = array(); foreach ($node->childNodes as $node) { $strategy = new Sisyphus_C14n_Legacy_Strategy_Dispatcher($this->getContext(), $this->getNodeset()); $nodeStrings[] = $strategy->canonicalize($node); } return join(self::LINEFEED, array_filter($nodeStrings)); }
/** * Generates canonical string presentation of an XML Element * * @see Sisyphus_C14n_Legacy_Strategy_Element::canonicalize() * the description of the canonicalization algorithm * * @param DOMElement $node DOM element being canonicalized * * @return string canonical presentation */ public function canonicalize($node) { $namespaceString = $this->generateNamespaceString($node); $attributeString = $this->generateAttributeString($node); $strategy = new Sisyphus_C14n_Legacy_Strategy_Dispatcher($this->getContext(), $this->getNodeset()); $nestedString = ''; foreach ($node->childNodes as $child) { $nestedString .= $strategy->canonicalize($child); } return $this->generateOutputString($node->nodeName, $namespaceString, $attributeString, $nestedString); }
/** * Canonicalizes XML node. * * @see Sisyphus_C14n_C14nInterface::canonicalize() * Sisyphus_C14n_C14nInterface::canonicalize() * * @param DOMNode $xml DOM node to canonicalize * * @return string canonicalized XML as string */ public function canonicalize(DOMNode $xml) { $this->setNodeset(new Sisyphus_C14n_Legacy_Nodeset($xml instanceof DOMDocument ? $xml : $xml->ownerDocument, $xml, $this->getContext())); $strategy = new Sisyphus_C14n_Legacy_Strategy_Dispatcher($this->getContext(), $this->getNodeset()); return $strategy->canonicalize($this->getNodeset()->getApex()); }