Parse an OPDS flux.

@param \SimpleXMLElement $xmldata

@return Feed|Publication
@throws OpdsParserNoTitleException
507515
private function parse(\SimpleXMLElement $xmldata)
    {
        if (!isset($xmldata->title)) {

            throw new OpdsParserNoTitleException();
        }

        if ($xmldata->getName() === 'entry') {

            return $this->parseEntry($xmldata);
        }

        return $this->parseFeed($xmldata);
    }
1129707
public function dataUpload($fileData)
    {
        $target = parent::dataUpload($fileData);

        if ($this->applyEffects('upload')) {
            $target = $this->processEffects($target);
        }

        return $target;
    }
65192
public function addBehavior($bdata)
    {
        if ($bdata instanceof Behavior) {
            $behavior = $bdata;
            $behavior->setDatabase($this);
            $this->behaviors[$behavior->getName()] = $behavior;

            return $behavior;
        } else {
            $class = $this->getConfiguredBehavior($bdata['name']);
            $behavior = new $class();
            $behavior->loadFromXML($bdata);

            return $this->addBehavior($behavior);
        }
    }
270386
public function loadXML($xml_data)
    {
        if (!parent::loadXML($xml_data)) {
            return false;
        }
        $tagName = $this->xml->documentElement->tagName;
        if ($tagName=='DTE') {
            $this->xml = null;
            $this->xml_data = null;
            $this->arreglo = null;
            $Dte = new Dte($xml_data, false);
            $this->agregar($Dte);
            $this->setCaratula([
                'RutEnvia' => $Dte->getEmisor(),
                'RutReceptor' => $Dte->getReceptor(),
                'FchResol' => date('Y-m-d'),
                'NroResol' => ($Dte->getCertificacion()?'0':'').'9999',
            ]);
            if (!parent::loadXML($this->generar())) {
                return false;
            }
            $tagName = $this->xml->documentElement->tagName;
        }
        if ($tagName=='EnvioDTE') {
            $this->tipo = 0;
            return $this->xml;
        }
        if ($tagName=='EnvioBOLETA') {
            $this->tipo = 1;
            return $this->xml;
        }
        return false;
    }
305910
protected function parseString($parser, $data, $isFinal)
    {
        if (!xml_parse($parser, $data, $isFinal)) {
            throw new Exception(
                xml_error_string(xml_get_error_code($parser))
                .' At line: '.
                xml_get_current_line_number($parser)
            );
        }

        return $parser;
    }
752337
public static function parse($xml, $section = null)
  {
    $parser = new XMLParser($xml);
    if (is_string($section) && !empty($section)) {
      return $parser->getXml()->get($section, true);
    }
    return $parser->getXml();
  }
1272754
private function fixXmlNode($data)
    {
        if ($data instanceof \SimpleXMLElement) {
            if (\in_array(\dom_import_simplexml($data)->firstChild->nodeType, [XML_CDATA_SECTION_NODE, XML_TEXT_NODE])) {
                $data = $data->__toString();
            }
        }

        return $data;
    }
651002
protected function parseEndElement(\XMLReader $reader)
    {
        switch ($reader->name) {
            case 'hiddenBeforeDateTime':
            case 'hiddenAfterDateTime':
            case 'creationDateTime':
            case 'lastModificationDateTime':
            case 'lastPublicationDateTime':
            case 'accessRoles':
                break;
            case 'node':
                // update current path
                array_pop($this->nodeNameStack);
                // update current node identifier
                array_pop($this->nodeIdentifierStack);
                break;
            case 'variant':
                // we have collected all data for the node so we save it
                $nodeData = array_pop($this->nodeDataStack);

                // if XML files lack the identifier for a node, add it here
                if (!isset($nodeData['identifier'])) {
                    $nodeData['identifier'] = Algorithms::generateUUID();
                }

                $this->persistNodeData($nodeData);
                break;
            default:
                throw new ImportException(sprintf('Unexpected end element <%s> ', $reader->name), 1423578066);
                break;
        }
    }
108085
public function convertAdventurersLog(string $data): array
    {
        // Parse data into ActivityFeed object
        $feedItems = [];

        try {
            $feed = new SimpleXmlElement($data);
        } catch (Exception $exception) {
            throw new DataConversionException("Could not parse the activity feed as XML.");
        }

        $itemElements = @$feed->xpath("/rss/channel/item");

        if ($itemElements === false) {
            throw new DataConversionException("Could not obtain any feed items from feed.");
        }

        foreach ($itemElements as $itemElement) {
            $time = new DateTime($itemElement->pubDate);
            $title = trim((string)$itemElement->title);
            $description = trim((string)$itemElement->description);

            if (!$time || !$title || !$description) {
                throw new DataConversionException(sprintf(
                    "Could not parse one of the activity feed items. (time: %s, title: %s, description: %s)",
                    $time ? $time->format("j-n-Y") : "", $title, $description
                ));
            }

            $feedItems[] = new ActivityFeedItem($time, $title, $description);
        }

        // Parse real name
        $titleElements = @$feed->xpath("/rss/channel/title");

        if ($titleElements === false || !count($titleElements)) {
            throw new DataConversionException("Could not obtain player name element from feed.");
        }

        $title = (string)$titleElements[0];
        $name = trim(substr($title, strrpos($title, ":") + 1));

        return [
            self::KEY_ACTIVITY_FEED => new ActivityFeed($feedItems),
            self::KEY_REAL_NAME => $name
        ];
    }
154212
public function parseXPath(array $xPaths, SimpleXMLElement $elem, array $parentData = [])
    {

        $xPath      = array_shift($xPaths);
        $children   = $elem->xpath($xPath);

        if (false === $children) {
            throw new \Exception(sprintf('Invalid xPath: "%s"', $xPath));
        }

        if (!count($children) && !count($parentData)) {
            //this is the top level so we don't need to nest
            return [$parentData];
        } elseif (!count($children)) {
            return [$parentData];
        }

        $return = [];
        foreach ($children as $child) {
            $data = $this->getScalarRecords($child);
            $data = array_merge($parentData, $data);

            if (count($xPaths) > 0) {
                $return = array_merge($return, $this->parseXPath($xPaths, $child, $data));
            } else {
                $return[] = $data;
            }
        }

        return $return;
    }
517606
public function parse($xmldom) : string
    {
        if (!$this->templatePreProcessed) {
            $this->preProcessTemplate();
        }

        $conversion = new Conversion($xmldom);
        $styles[0] = $this->getPreProcessedTemplateDom();
        $conversion->addStylesheet($styles);

        return (string) $conversion->toString();
    }
1298770
public function readString(string $data)
    {
        $reader = new XMLReader;
        $reader->XML($data);

        $contents = $this->toArray($reader);
        $reader->close();

        return $contents;
    }
936504
public function parseXml($xmlString)
    {
        $feedXml = simplexml_load_string($xmlString);
        $attributes = $feedXml->attributes();
        $feedArray = (array) $feedXml;
        if (!empty($attributes)) {
            $this->attributes = (array) $attributes;
        }

        if (array_key_exists('author', $feedArray)) {
            $this->author = $this->processAuthorNode($feedArray);
        }

        if (array_key_exists('entry', $feedArray)) {
            $this->entry = $this->processEntryNode($feedArray);
        }

        if (array_key_exists('category', $feedArray)) {
            $this->category = $this->processCategoryNode($feedArray);
        }

        if (array_key_exists('contributor', $feedArray)) {
            $this->contributor = $this->processContributorNode($feedArray);
        }

        if (array_key_exists('generator', $feedArray)) {
            $generator = new Generator();
            $generatorValue = $feedArray['generator'];
            if (is_string($generatorValue)) {
                $generator->setText($generatorValue);
            } else {
                $generator->parseXml($generatorValue->asXML());
            }

            $this->generator = $generator;
        }

        if (array_key_exists('icon', $feedArray)) {
            $this->icon = (string) $feedArray['icon'];
        }

        if (array_key_exists('id', $feedArray)) {
            $this->id = (string) $feedArray['id'];
        }

        if (array_key_exists('link', $feedArray)) {
            $this->link = $this->processLinkNode($feedArray);
        }

        if (array_key_exists('logo', $feedArray)) {
            $this->logo = (string) $feedArray['logo'];
        }

        if (array_key_exists('rights', $feedArray)) {
            $this->rights = (string) $feedArray['rights'];
        }

        if (array_key_exists('subtitle', $feedArray)) {
            $this->subtitle = (string) $feedArray['subtitle'];
        }

        if (array_key_exists('title', $feedArray)) {
            $this->title = (string) $feedArray['title'];
        }

        if (array_key_exists('updated', $feedArray)) {
            $this->updated = \DateTime::createFromFormat(
                \DateTime::ATOM,
                (string) $feedArray['updated']
            );
        }
    }
594541
private function buildXml(\DOMNode $parentNode, $data, string $xmlRootNodeName = null): bool
    {
        $append = true;
        $removeEmptyTags = $this->context[self::REMOVE_EMPTY_TAGS] ?? $this->defaultContext[self::REMOVE_EMPTY_TAGS] ?? false;
        $encoderIgnoredNodeTypes = $this->context[self::ENCODER_IGNORED_NODE_TYPES] ?? $this->defaultContext[self::ENCODER_IGNORED_NODE_TYPES];

        if (\is_array($data) || ($data instanceof \Traversable && !$this->serializer->supportsNormalization($data, $this->format))) {
            foreach ($data as $key => $data) {
                //Ah this is the magic @ attribute types.
                if (0 === strpos($key, '@') && $this->isElementNameValid($attributeName = substr($key, 1))) {
                    if (!is_scalar($data)) {
                        $data = $this->serializer->normalize($data, $this->format, $this->context);
                    }
                    $parentNode->setAttribute($attributeName, $data);
                } elseif ('#' === $key) {
                    $append = $this->selectNodeType($parentNode, $data);
                } elseif ('#comment' === $key) {
                    if (!\in_array(XML_COMMENT_NODE, $encoderIgnoredNodeTypes, true)) {
                        $append = $this->appendComment($parentNode, $data);
                    }
                } elseif (\is_array($data) && false === is_numeric($key)) {
                    // Is this array fully numeric keys?
                    if (ctype_digit(implode('', array_keys($data)))) {
                        /*
                         * Create nodes to append to $parentNode based on the $key of this array
                         * Produces <xml><item>0</item><item>1</item></xml>
                         * From ["item" => [0,1]];.
                         */
                        foreach ($data as $subData) {
                            $append = $this->appendNode($parentNode, $subData, $key);
                        }
                    } else {
                        $append = $this->appendNode($parentNode, $data, $key);
                    }
                } elseif (is_numeric($key) || !$this->isElementNameValid($key)) {
                    $append = $this->appendNode($parentNode, $data, 'item', $key);
                } elseif (null !== $data || !$removeEmptyTags) {
                    $append = $this->appendNode($parentNode, $data, $key);
                }
            }

            return $append;
        }

        if (\is_object($data)) {
            $data = $this->serializer->normalize($data, $this->format, $this->context);
            if (null !== $data && !is_scalar($data)) {
                return $this->buildXml($parentNode, $data, $xmlRootNodeName);
            }

            // top level data object was normalized into a scalar
            if (!$parentNode->parentNode->parentNode) {
                $root = $parentNode->parentNode;
                $root->removeChild($parentNode);

                return $this->appendNode($root, $data, $xmlRootNodeName);
            }

            return $this->appendNode($parentNode, $data, 'data');
        }

        throw new NotEncodableValueException(sprintf('An unexpected value could not be serialized: %s', var_export($data, true)));
    }
544173
private function parseTranslations($translationsData)
    {
        $translations = Translations::fromPoString($translationsData);
        if (count($translations) < 1) {
            throw new Exception('No translations downloaded');
        }

        return $translations;
    }
1070869
public function xml($data)
    {
        if ($data instanceof SimpleXMLElement) {
            $data = $data->saveXML();
        }
        $dom = new DOMDocument();
        $dom->loadXml($data);
        $dom->formatOutput = true;
        return $dom->saveXML();
    }
1315490
private function parseXml($xml)
    {
        $priorSetting = libxml_use_internal_errors(true);
        try {
            libxml_clear_errors();
            $xmlPayload = new \SimpleXMLElement($xml);
            if ($error = libxml_get_last_error()) {
                throw new \RuntimeException($error->message);
            }
        } catch (\Exception $e) {
            throw new ParserException("Error parsing XML: {$e->getMessage()}", 0, $e);
        } finally {
            libxml_use_internal_errors($priorSetting);
        }

        return $xmlPayload;
    }