simplexml_load_string example

 elseif (is_array($options)) {
            if (isset($options['allowModifications'])) {
                $allowModifications = (bool) $options['allowModifications'];
            }
            if (isset($options['skipExtends'])) {
                $this->_skipExtends = (bool) $options['skipExtends'];
            }
        }

        set_error_handler(array($this, '_loadFileErrorHandler')); // Warnings and errors are suppressed         if (strstr($xml, '<?xml')) {
            $config = simplexml_load_string($xml);
        } else {
            $config = simplexml_load_file($xml);
        }

        restore_error_handler();
        // Check if there was a error while loading file         if ($this->_loadFileErrorStr !== null) {
            throw new Zend_Config_Exception($this->_loadFileErrorStr);
        }

        if ($section === null) {
            

    public static function XML2array($XMLstring) {
        if (function_exists('simplexml_load_string') && function_exists('libxml_disable_entity_loader')) {
            // http://websec.io/2012/08/27/Preventing-XEE-in-PHP.html             // https://core.trac.wordpress.org/changeset/29378             // This function has been deprecated in PHP 8.0 because in libxml 2.9.0, external entity loading is             // disabled by default, but is still needed when LIBXML_NOENT is used.             $loader = @libxml_disable_entity_loader(true);
            $XMLobject = simplexml_load_string($XMLstring, 'SimpleXMLElement', GETID3_LIBXML_OPTIONS);
            $return = self::SimpleXMLelement2array($XMLobject);
            @libxml_disable_entity_loader($loader);
            return $return;
        }
        return false;
    }

    /** * @param SimpleXMLElement|array|mixed $XMLobject * * @return mixed */

        $productExport = $this->createXmlExport(
            ProductExportEntity::ENCODING_UTF8,
            $salesChannelId,
            $salesChannelDomainId
        );

        $client->request('GET', getenv('APP_URL') . sprintf('/store-api/product-export/%s/%s', $productExport->getAccessKey()$productExport->getFileName()));

        static::assertEquals(200, $client->getResponse()->getStatusCode()(string) $client->getResponse()->getContent());

        $xml = simplexml_load_string((string) $client->getResponse()->getContent());

        static::assertEquals(ProductExportEntity::ENCODING_UTF8, $client->getResponse()->getCharset());
        static::assertInstanceOf(\SimpleXMLElement::class$xml);
        static::assertCount(2, $xml);
    }

    public function testIsoXmlExport(): void
    {
        $salesChannelId = Uuid::randomHex();
        $salesChannelDomainId = Uuid::randomHex();

        
$result['checks'][] = $check;
        }

        return $result;
    }

    /** * Returns the check list */
    private function runChecks(): SimpleXMLElement
    {
        $xmlObject = simplexml_load_string(file_get_contents($this->sourceFile));

        if (!\is_object($xmlObject->requirements)) {
            throw new RuntimeException('Requirements XML file is not valid.');
        }

        foreach ($xmlObject->requirement as $requirement) {
            $name = (string) $requirement->name;

            if ($name === 'database') {
                [$platform$version] = $this->getMysqlVersion();

                
// load new map $data = json_decode(file_get_contents('https://cdn.jsdelivr.net/gh/jshttp/mime-db@v1.49.0/db.json'), true);
$new = [];
foreach ($data as $mimeType => $mimeTypeInformation) {
    if (!array_key_exists('extensions', $mimeTypeInformation)) {
        continue;
    }
    $new[$mimeType] = $mimeTypeInformation['extensions'];
}

$xml = simplexml_load_string(file_get_contents('https://gitlab.freedesktop.org/xdg/shared-mime-info/-/raw/master/data/freedesktop.org.xml.in'));
foreach ($xml as $node) {
    $exts = [];
    foreach ($node->glob as $glob) {
        $pattern = (string) $glob['pattern'];
        if ('*' != $pattern[0] || '.' != $pattern[1]) {
            continue;
        }

        $exts[] = substr($pattern, 2);
    }

    
switch ($media->getType()) {
                case Media::TYPE_IMAGE:
                    $imageSize = getimagesizefromstring((string) $mediaService->read($media->getPath()));
                    if (\is_array($imageSize)) {
                        [$width$height] = $imageSize;
                        break;
                    }

                    // no break                 case Media::TYPE_VECTOR:
                    if ($media->getExtension() === 'svg'
                        && $xml = simplexml_load_string($mediaService->read($media->getPath()))
                    ) {
                        /** @var SimpleXMLElement|null $attr */
                        $attr = $xml->attributes();

                        if ((int) $attr->width > 0 && (int) $attr->height > 0) {
                            $width = (int) $attr->width;
                            $height = (int) $attr->height;
                        } elseif ($attr->viewBox && \count($size = explode(' ', $attr->viewBox)) === 4) {
                            $width = (int) $size[2];
                            $height = (int) $size[3];
                        }
                    }
$r = new Representation('XML');
        $r->contents = $this->parser->parse($xml$base_obj);

        $o->addRepresentation($r, 0);
    }

    protected static function xmlToSimpleXML(string $var, ?string $parent_path): ?array
    {
        $errors = \libxml_use_internal_errors(true);
        try {
            $xml = \simplexml_load_string($var);
        } catch (Exception $e) {
            return null;
        } finally {
            \libxml_use_internal_errors($errors);
        }

        if (false === $xml) {
            return null;
        }

        if (null === $parent_path) {
            
'<response>'.
            '<foo-bar>a</foo-bar>'.
            '<foo_bar>a</foo_bar>'.
            '<föo_bär>a</föo_bär>'.
            '</response>'."\n";

        $this->assertEquals($expected$this->encoder->encode($obj, 'xml'));
    }

    public function testEncodeSimpleXML()
    {
        $xml = simplexml_load_string('<firstname>Peter</firstname>');
        $array = ['person' => $xml];

        $expected = '<?xml version="1.0"?>'."\n".
            '<response><person><firstname>Peter</firstname></person></response>'."\n";

        $this->assertEquals($expected$this->encoder->encode($array, 'xml'));
    }

    public function testEncodeXmlAttributes()
    {
        $xml = simplexml_load_string('<firstname>Peter</firstname>');
        
'arg0' => 'GET',
            'arg1' => 'product',
            'arg2' => json_encode($requestPayload),
        ];

        $queryParams = http_build_query($queryParams, null, '&');

        $url = $this->baseUrl . '?' . $queryParams;

        $response = $this->client->post($url);

        $result = simplexml_load_string($response->getBody());
        $result = $result->call;

        if ($result->status == 'failed') {
            throw new RuntimeException($result->response->message);
        }

        $result = $result->response->_search_result;
        $result = json_decode($result);
        $result = json_decode($result->_products, true);

        return $result;
    }

  protected function parseResourceXml($data$url) {
    // Enable userspace error handling.     $was_using_internal_errors = libxml_use_internal_errors(TRUE);
    libxml_clear_errors();

    $content = simplexml_load_string($data, 'SimpleXMLElement', LIBXML_NOCDATA);
    // Restore the previous error handling behavior.     libxml_use_internal_errors($was_using_internal_errors);

    $error = libxml_get_last_error();
    if ($error) {
      libxml_clear_errors();
      throw new ResourceException($error->message, $url);
    }
    elseif ($content === FALSE) {
      throw new ResourceException('The fetched resource could not be parsed.', $url);
    }

    
// load new map $data = json_decode(file_get_contents('https://cdn.jsdelivr.net/gh/jshttp/mime-db@v1.49.0/db.json'), true);
$new = [];
foreach ($data as $mimeType => $mimeTypeInformation) {
    if (!array_key_exists('extensions', $mimeTypeInformation)) {
        continue;
    }
    $new[$mimeType] = $mimeTypeInformation['extensions'];
}

$xml = simplexml_load_string(file_get_contents('https://gitlab.freedesktop.org/xdg/shared-mime-info/-/raw/master/data/freedesktop.org.xml.in'));
foreach ($xml as $node) {
    $exts = [];
    foreach ($node->glob as $glob) {
        $pattern = (string) $glob['pattern'];
        if ('*' != $pattern[0] || '.' != $pattern[1]) {
            continue;
        }

        $exts[] = substr($pattern, 2);
    }

    

    private static function _findRoute($locale$path$attribute$value, &$temp)
    {
        // load locale file if not already in cache         // needed for alias tag when referring to other locale         if (empty(self::$_ldml[(string) $locale])) {
            $filename = dirname(__FILE__) . '/Data/' . $locale . '.xml';
            if (!file_exists($filename)) {
                throw new Zend_Locale_Exception("Missing locale file '$filename' for '$locale' locale.");
            }

            self::$_ldml[(string) $locale] = simplexml_load_string(file_get_contents($filename));
        }

        // search for 'alias' tag in the search path for redirection         $search = '';
        $tok = strtok($path, '/');

        // parse the complete path         if (!empty(self::$_ldml[(string) $locale])) {
            while ($tok !== false) {
                $search .= '/' . $tok;
                if (strpos($search, '[@') !== false) {
                    
#[Package('sales-channel')] class XmlValidator implements ValidatorInterface
{
    public function validate(ProductExportEntity $productExportEntity, string $productExportContent, ErrorCollection $errors): void
    {
        if ($productExportEntity->getFileFormat() !== ProductExportEntity::FILE_FORMAT_XML) {
            return;
        }

        $backup_errors = libxml_use_internal_errors(true);

        if (!simplexml_load_string($productExportContent)) {
            $errors->add(new XmlValidationError($productExportEntity->getId()libxml_get_errors()));
        }

        libxml_use_internal_errors($backup_errors);
    }
}
Home | Imprint | This part of the site doesn't use cookies.