riesenia / pohoda

XML generator a parser pre Pohodu
35 stars 25 forks source link

Nacitanie XML z premennej #22

Closed morvy closed 3 years ago

morvy commented 3 years ago

Zdravim,

neviem ci robim nieco zle, ale potreboval som nacitavat XML z premennej namiesto suboru. Nevedel som to cez $pohoda->load tak som si rozsiril classu o tuto funkciu. Robim to zbytocne a slo to aj bez toho alebo sa s nacitanim XML z premennej/stringu neratalo?

use Riesenia\Pohoda;

class PohodaString extends Pohoda
{
    /**
     * Load XML string.
     *
     * @param string $name
     * @param string $xmlstring
     *
     * @return bool
     */
    public function loadString(string $name, string $xmlstring)
    {
        $this->_xmlReader = new \XMLReader();

        if (!$this->_xmlReader->XML($xmlstring)) {
            return false;
        }

        $fullName = 'Riesenia\\Pohoda\\' . $name;

        if (!\class_exists($fullName)) {
            throw new \DomainException('Not allowed entity: ' . $name);
        }

        while ($this->_xmlReader->read() && $this->_xmlReader->name !== $fullName::$importRoot) {
            // skip to first element
        }

        return true;
    }
}
segy commented 3 years ago

Zdravim. S nacitanim stringu sa neratalo, takze ked ste to takto potrebovali, tak je to ok :)