我在PHP文档中发现了一个来自DOMNode类的方法,定义为DOMNode::C14N (http://cl1.php.net/manual/en/domnode.c14n.php)。遗憾的是,我很难找到关于它的用法的完整示例,而且我尝试了一些代码,但没有成功。可能是因为我使用PHP本机类的空体验。
<?php
$Document = '<Document>... (more XML code to canonicalize)</Document>';
$xml = new C14N();
$xml = $Document->C14N();在执行时,我得到:
Fatal error: Class 'C14N' not found in C:\wamp\www\...我已经研究过了,类DOMNode包含在DOM扩展中,它适合于默认情况下安装和启用,而且c14n不是一个类,而是一个方法。
我有PHP 5.3.13。
提前谢谢。
发布于 2014-06-19 16:24:36
为了帮助您阅读PHP手册,这里:
DOMNode::C14N这意味着对于类DOMNode,有一个名为C14N的方法。
那么在哪里可以找到这样一个DOMNode,这样您就可以调用该方法了?
例如,DOMDocument是一个DOMNode,请参阅下面的手册页:http://cl1.php.net/manual/en/class.domdocument.php它写的是
DOMDocument extends DOMNode {扩展是a,所以DOMDocument是DOMNode。在该页面上向下滚动将为您提供一些关于如何创建这样一个对象的通用示例代码,然后只需调用该方法:
// "Create" the document.
$xml = new DOMDocument( "1.0", "ISO-8859-15" );
$xml->loadXML('<Document>... (more XML code to canonicalize)</Document>');
echo $xml->C14N();希望这对你的方向有帮助。
示例 (在线演示):
<?php
// "Create" the document.
$xml = new DOMDocument( "1.0", "ISO-8859-15" );
$xml->loadXML('<Document b="c"
f="e" a="j">...
<!-- stupid whitespace example -->
mother told me to go shopping
</Document>');
echo $xml->C14N();程序输出
<Document a="j" b="c" f="e">...
mother told me to go shopping
</Document>如本例所示,属性被排序,注释已被删除。
https://stackoverflow.com/questions/24311486
复制相似问题