Sunday, 15 July 2012

Canonicalization (c14n) of XML code using PHP class method -



Canonicalization (c14n) of XML code using PHP class method -

i found in php documentation method domnode class, defined domnode::c14n (http://cl1.php.net/manual/en/domnode.c14n.php). sadly i've had hard time finding finish examples it's usage, , have tryed code no success... due null experiance using php default classes.

<?php $document = '<document>... (more xml code canonicalize)</document>'; $xml = new c14n(); $xml = $document->c14n();

when executing get:

fatal error: class 'c14n' not found in c:\wamp\www\...

i have researched , class domnode included in dom extension suposed come installed , enabled default, plus c14n not class method.

i have php 5.3.13.

thanks in advance.

to help reading php manual here:

domnode::c14n

this means class domnode there method named c14n.

so find such domnode, can phone call method on?

well, domdocument illustration domnode, see next manual page: http://cl1.php.net/manual/en/class.domdocument.php write

domdocument extends domnode {

an extends stands is a, domdocument domnode. scrolling downwards on page give general illustration code on how create such object, need phone call method:

// "create" document. $xml = new domdocument( "1.0", "iso-8859-15" ); $xml->loadxml('<document>... (more xml code canonicalize)</document>'); echo $xml->c14n();

hope helps orientation.

example (online-demo):

<?php // "create" document. $xml = new domdocument( "1.0", "iso-8859-15" ); $xml->loadxml('<document b="c" f="e" a="j">... <!-- stupid whitespace illustration --> mother told me go shopping </document>'); echo $xml->c14n();

program output

<document a="j" b="c" f="e">... mother told me go shopping </document>

as illustration shows, attributes sorted , comment has been removed.

php xml

No comments:

Post a Comment