【发布时间】:2014-08-15 08:20:37
【问题描述】:
【问题讨论】:
标签: php codeigniter svg simplexml scale
【问题讨论】:
标签: php codeigniter svg simplexml scale
来自这个班级:
class ExSimpleXMLElement extends SimpleXMLElement
{
public function _construct($xml){
parent::_construct($xml);
}
/**
* Add SimpleXMLElement code into a SimpleXMLElement
* @param SimpleXMLElement $append
*/
public function appendXML($append)
{
if ($append) {
if (strlen(trim((string) $append))==0) {
$xml = $this->addChild($append->getName());
foreach($append->children() as $child) {
$xml->appendXML($child);
}
} else {
$xml = $this->addChild($append->getName(), (string) $append);
}
foreach($append->attributes() as $n => $v) {
$xml->addAttribute($n, $v);
}
}
}
}
你可以这样改造它:
<?php
class ExSimpleXMLElement
{
private $sxe;
public function loadXml($xml){
$this->sxe = new SimpleXMLElement($xml);
}
/**
* Add SimpleXMLElement code into a SimpleXMLElement
* @param SimpleXMLElement $append
*/
public function appendXML($append)
{
if ($append) {
if (strlen(trim((string) $append))==0) {
$xml = $this->sxe->addChild($append->getName());
foreach($append->children() as $child) {
$xml->appendXML($child);
}
} else {
$xml = $this->sxe->addChild($append->getName(), (string) $append);
}
foreach($append->attributes() as $n => $v) {
$xml->addAttribute($n, $v);
}
}
}
}
并像这样使用它:
$this->load->library('ExSimpleXMLElement');
$this->exsimplexmlelement->loadXML($xml);
【讨论】:
public function edit_svg(){ $this->load->library('ExSimpleXMLElement'); $file="images/designs/svg/a.svg"; //http://www.webdeveloper.com/forum/showthread.php?165648-Editing-XML-using-PHP $xml = simplexml_load_file($file); //Load the File. $this->exsimplexmlelement->loadXML($xml)
$xml = file_get_contents($file);,而不是$xml = simplexml_load_file($file);。 loadXML 方法需要 xml 作为字符串。
Fatal error: Call to undefined method SimpleXMLElement::appendXML() in C:\wamp\www\m3\trunk\application\controllers\svg.php 控制器:svg 库:ExSimpleXMLElement