Creates and returns a template object based on the provided template definition.

@param string $xml

@return Template
19728
protected function createTemplateFromXml($xml)
    {
        /** @var Template $template */
        $template = $this->serializer->deserialize($xml, 'phpDocumentor\Transformer\Template', 'xml');
        $template->propagateParameters();

        return $template;
    }
904942
protected static function loadAsXML($template)
	{
		$xml = '<?xml version="1.0" encoding="utf-8" ?><xsl:template xmlns:xsl="' . self::XMLNS_XSL . '">' . $template . '</xsl:template>';

		$useErrors = libxml_use_internal_errors(true);
		$dom       = new DOMDocument;
		$success   = $dom->loadXML($xml, LIBXML_NOCDATA | LIBXML_NSCLEAN);
		self::removeInvalidAttributes($dom);
		libxml_use_internal_errors($useErrors);

		return ($success) ? $dom : false;
	}
1064173
public static function fromXml(\DOMElement $xml)
    {
        $static = new static();
        $static->libraryItemMetadata = LibraryItemMetadata::fromXml($xml);

        $expenseId = $xml->getElementsByTagName('id');
        $static->expenseId = StringLiteral::fromXml($expenseId);

        $date = $xml->getElementsByTagName('date');
        $static->date = DateTime::fromXml($date);

        $amount = $xml->getElementsByTagName('amount');
        $static->amount = FloatLiteral::fromXml($amount);

        $stringLiterals = array(
            'title' => $xml->getElementsByTagName('title'),
            'description' => $xml->getElementsByTagName('description'),
            'type' => $xml->getElementsByTagName('type'),
        );
        foreach ($stringLiterals as $propertyName => $xmlTag) {
            $static->$propertyName = StringLiteral::fromXml($xmlTag);
        }

        return $static;
    }
172368
public static function parseElementXml(SimpleXMLElement $xml){

        $attributes = array();
        foreach($xml->attributes() as $name => $value){
            $attributes[$name] = (string) $value;
        }

        $returnValue = array(
            'qtiClass' => $xml->getName()
        );

        if(count($attributes)){
            $returnValue['attributes'] = $attributes;
        }

        return $returnValue;
    }
359742
public static function fromXml(\DOMElement $xml)
    {
        $static = new static();

        $locationId = $xml->getElementsByTagName('pickupLocation');
        $static->locationId = StringLiteral::fromXml($locationId);

        $text = $xml->getElementsByTagName('pickupLocationText');
        $static->text = StringLiteral::fromXml($text);

        return $static;
    }
550774
public function create(string $template) : Box
    {
        foreach ($this->paths as &$path) {
            // full path to template file without extension
            $file = \rtrim($path, '/') . '/' . \trim($template, '/');

            if (\file_exists($t = $file . '.php')) {
                return (new Box(
                        new Template($t),
                        new EvalRendererDecorator(
                            new NullRenderer())))
                            ->assign([
                                'markdown' => function($md) {
                                    return new Box(
                                        new Atom($md),
                                        new MarkdownRendererDecorator(
                                            new NullRenderer(), $this->parsedown));
                                }
                            ]);
            }

            if (\file_exists($t = $file . '.md.php')) {
                return (new Box(
                        new Template($t),
                        new MarkdownRendererDecorator(
                            new EvalRendererDecorator(
                                new NullRenderer()), $this->parsedown)))
                                ->assign([
                                    'markdown' => function($md) {
                                        return new Box(
                                            new Atom($md),
                                            new MarkdownRendererDecorator(
                                                new NullRenderer(), $this->parsedown));
                                    }
                                ]);
            }

            if (\file_exists($t = $file . '.md')) {
                return new Box(
                        new Template($t),
                        new MarkdownRendererDecorator(
                            new NullRenderer(), $this->parsedown));
            }

            if (\file_exists($t = $file . '.html')) {
                return new Box(
                        new Template($t),
                        new NullRenderer());
            }
        }

        throw new \RuntimeException(\sprintf('Template "%s" not found.', $template));
    }
233757
public function formatXml($xml)
    {
        $dom = new DOMDocument();
        $dom->formatOutput = true;
        $dom->preserveWhiteSpace = false;
        $dom->loadXml($xml);

        return $dom->saveXml();
    }
4571
public function format($xml)
    {
        $dom = new DOMDocument('1.0');
        $dom->preserveWhiteSpace = false;
        $dom->formatOutput = true;
        $dom->loadXML($xml);
        $formatted = $dom->saveXML();

        if (!$formatted) {
            throw new Exception("An error occurred while formatting the XML");
        }

        return $formatted;
    }
599459
public static function create_template($template) {
        global $PAGE;

        $params = self::validate_parameters(self::create_template_parameters(), array('template' => $template));
        $params = $params['template'];
        $context = self::get_context_from_params($params);
        self::validate_context($context);
        $output = $PAGE->get_renderer('core');

        unset($params['contextlevel']);
        unset($params['instanceid']);
        $params = (object) $params;
        $params->contextid = $context->id;

        $result = api::create_template($params);
        $exporter = new template_exporter($result);
        $record = $exporter->export($output);
        return $record;
    }
340813
public static function createFromXML( $source )
    {
        $newObj = new eZPage();

        if ( $source )
        {
            $dom = new DOMDocument( '1.0', 'utf-8' );
            $success = $dom->loadXML( $source );
            $root = $dom->documentElement;

            foreach ( $root->childNodes as $node )
            {
                if ( $node->nodeType == XML_ELEMENT_NODE && $node->nodeName == 'zone' )
                {
                    $zoneNode = eZPageZone::createFromXML( $node );
                    $newObj->addZone( $zoneNode );
                }
                elseif ( $node->nodeType == XML_ELEMENT_NODE )
                {
                    $newObj->setAttribute( $node->nodeName, $node->nodeValue );
                }
            }

            if ( $root->hasAttributes() )
            {
                foreach ( $root->attributes as $attr )
                {
                    $newObj->setAttribute( $attr->name, $attr->value );
                }
            }
        }

        $zoneINI = eZINI::instance( 'zone.ini' );
        $layoutName = $newObj->attribute( 'zone_layout' );
        if ( $zoneINI->hasVariable( $layoutName, 'Zones' ) )
        {
            foreach ( $zoneINI->variable( $layoutName, 'Zones' ) as $zoneIdentifier )
            {
                foreach ( $newObj->attribute( 'zones' ) as $inObjectZone )
                {
                    if ( $inObjectZone->attribute( 'zone_identifier' ) === $zoneIdentifier )
                        continue 2;
                }

                $newZone = $newObj->addZone( new eZPageZone() );
                $newZone->setAttribute( 'id', md5( mt_rand() . microtime() . $newObj->getZoneCount() ) );
                $newZone->setAttribute( 'zone_identifier', $zoneIdentifier );
                $newZone->setAttribute( 'action', 'add' );
            }
        }

        return $newObj;
    }
397125
public static function fromXml(\DOMDocument $xml)
    {
        $static = new static();

        $url = $xml->getElementsByTagName('resource');
        $static->autoLoginUrl = StringLiteral::fromXml($url);

        $code = $xml->getElementsByTagName('code');
        $static->code = StringLiteral::fromXml($code);

        return $static;
    }
286381
public function build(SimpleXMLElement $parent = null) : SimpleXMLElement
    {
        if ($parent === null) {
            $xml = new SimpleXMLElement('<' . get_called_class()::getTagName() . "/>", LIBXML_PARSEHUGE);
        } else {
            $xml = $parent->addChild(get_called_class()::getTagName());
        }
        $this->setAttributes($xml);
        $this->setChilds($xml);

        return $xml;
    }
1276236
private function xmlToElements($xml)
    {
        //====================================================================//
        // Convert XML to Object Recursively
        try {
            $result = simplexml_load_string($xml, "SimpleXMLElement", LIBXML_NOERROR);
        } catch (Exception $ex) {
            $this->fault = $ex->getMessage();

            return false;
        }

        return $result;
    }
605218
public static function format($xml) {
        $domtree = new DOMDocument('1.0', 'UTF-8');
        $domtree->loadXML($xml);
        $domtree->preserveWhiteSpace = false;
        $domtree->formatOutput = true;
        $domtree->setIndent = (1);
        return $domtree->saveXML();
    }
1092091
public static function toPlainObject( $xml )
	{
		$parser	= new XML_DOM_Parser();
		$document	= $parser->parse( $xml );
		$rootNode	= array_shift( $document->getChildren() );
		$rootName	= $rootNode->getNodeName();
		$object->$rootName	= new stdClass();
		self::convertToObjectRecursive( $rootNode, $object->$rootName );
		return $object;
	}
1093879
public static function fromXml(\DOMElement $xml)
    {
        $static = new static();
        $static->libraryItemMetadata = LibraryItemMetadata::fromXml($xml);
        $static->pickupLocation = PickupLocation::fromXml($xml);

        $requestStartDate = $xml->getElementsByTagName('requestDate');
        $requestEndDate = $xml->getElementsByTagName('endRequestDate');
        $static->requestDateRange = DateTimeRange::fromXml($requestStartDate, $requestEndDate);

        $holdStartDate = $xml->getElementsByTagName('holdDate');
        $holdEndDate = $xml->getElementsByTagName('endHoldDate');
        $static->holdDateRange = DateTimeRange::fromXml($holdStartDate, $holdEndDate);

        $cancelable = $xml->getElementsByTagName('cancelable');
        $static->cancelable = BoolLiteral::fromXml($cancelable);

        $stringLiterals = array(
            'requestNumber' => $xml->getElementsByTagName('requestNumber'),
            'sequence' => $xml->getElementsByTagName('sequence'),
            'queuePosition' => $xml->getElementsByTagName('queuePosition'),
            'itemSequence' => $xml->getElementsByTagName('itemSequence'),
            'status' => $xml->getElementsByTagName('status'),
        );
        foreach ($stringLiterals as $propertyName => $xmlTag) {
            $static->$propertyName = StringLiteral::fromXml($xmlTag);
        }

        return $static;
    }
866011
private function prepareCreateXMLChildObject()
    {
        $fragment = new CNabuPHPMethodBuilder(
            $this, 'createXMLChildObject', CNabuPHPMethodBuilder::METHOD_PROTECTED,
            false, false, false, true, 'CNabuXMLDataObject'
        );
        $this->getDocument()->addUse('\nabu\xml\CNabuXMLDataObject');

        $fragment->addComment("Create the XML Child object filled with their Data Object.");
        $fragment->addComment("@return CNabuXMLDataObject Returns a XML instance with the child data object instance.");

        $fragment->addParam(
            'nb_child', 'CNabuDataObject', true, null, 'CNabuDataObject',
            'Child data object.'
        );
        $this->getDocument()->addUse('\nabu\data\CNabuDataObject');

        $class_name = preg_replace('/List(Base)*$/', '', $this->class_name);
        $class_ns = preg_replace('/\\\\base$/', '', $this->class_namespace);

        $fragment->addFragment("return new $class_name(\$nb_child);");
        $this->getDocument()->addUse("\\$class_ns\\$class_name");

        $this->addFragment($fragment);
    }