$dom = new DOMDocument(); $dom->loadXML($xmlStr); $canonical = $dom->C14N(); echo $canonical;
$options = array( 'formatOutput' => true, 'exclusive' => true, 'prefixList' => array('ds', 'xsi') ); $canonical = $dom->C14N(false, false, $options); echo $canonical;This code demonstrates the use of options with the C14N function. In this case, the options specify that the output should be formatted (with indentation and line breaks), that namespace declarations should be exclusive (i.e., not duplicated), and that certain namespace prefixes should be preserved. The PHP DOMDocument C14N function is included in the standard PHP library, so no external package or library is required.