1

I need to integrate the code that is in the answer to this thread.

How to rotate SVG by PHP

When I do it as a library I get error "construct", I do not have much knowledge about it, I hope you can help me.

Community
  • 1
  • 1

1 Answers1

0

From this class:

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); 
            } 
         } 
     } 
} 

You would transform it like this:

<?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); 
            } 
        } 
    } 
}

And use it like this:

$this->load->library('ExSimpleXMLElement');

$this->exsimplexmlelement->loadXML($xml);
machineaddict
  • 3,216
  • 8
  • 37
  • 61
  • machineaddict. I tried the code and I get the error image, which can be? I'm calling the liberia so: [link] (https://docs.google.com/file/d/0B4eow_YS2Y1eVjFaQV9HRlNCcWM/edit) ``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)`` – Corematrixx Jun 25 '14 at 11:15
  • Instead of `$xml = simplexml_load_file($file);`, use `$xml = file_get_contents($file);`. The `loadXML` method needs xml as string. – machineaddict Jun 25 '14 at 13:06
  • thanks!, what you said worked, but now I have another error! the controller related to liberia, calling the method "appendXML ()" Might you help me with this ... I have tried to correct it during the day but I have not done it! ``Fatal error: Call to undefined method SimpleXMLElement::appendXML() in C:\wamp\www\m3\trunk\application\controllers\svg.php`` controller: [svg](https://docs.google.com/file/d/0B4eow_YS2Y1eUkNtT1B6YlFsV28/edit) library: [ExSimpleXMLElement](https://docs.google.com/file/d/0B4eow_YS2Y1eUnUtc1VwaWNRMUE/edit) – Corematrixx Jun 26 '14 at 00:46