Replaces the DOI Identifier value in the provided XML

@param $doiValue
@param $xml
@return string
431127
public static function replaceDOIValue($doiValue, $xml)
    {
        $doiXML = new \DOMDocument();
        $doiXML->loadXML($xml);

        // remove the current identifier
        $currentIdentifier = $doiXML->getElementsByTagName('identifier');
        for ($i = 0; $i < $currentIdentifier->length; $i++) {
            $doiXML
                ->getElementsByTagName('resource')
                ->item(0)
                ->removeChild($currentIdentifier->item($i));
        }

        // add new identifier to the DOM
        $newIdentifier = $doiXML->createElement('identifier', $doiValue);
        $newIdentifier->setAttribute('identifierType', "DOI");
        $doiXML
            ->getElementsByTagName('resource')
            ->item(0)
            ->insertBefore(
                $newIdentifier,
                $doiXML->getElementsByTagName('resource')->item(0)->firstChild
            );

        return $doiXML->saveXML();
    }
636693
public function writeAttribute(string $attributeName, string $attributeValue): XmlStreamWriter
    {
        return $this->append(
                function(\DOMElement $parent) use ($attributeName, $attributeValue)
                {
                    $parent->setAttribute(
                            $attributeName,
                            $this->encode($attributeValue)
                    );
                },
                'attribute: "' . $attributeName . ':' . $attributeValue . '"'
        );
    }
221255
private function generateXmlString(array $authorValue)
    {
        $doc = new DOMDocument('1.0', 'utf-8');

        $root = $doc->createElement('ezauthor');
        $doc->appendChild($root);

        $authors = $doc->createElement('authors');
        $root->appendChild($authors);

        foreach ($authorValue as $author) {
            $authorNode = $doc->createElement('author');
            $authorNode->setAttribute('id', $author['id']);
            $authorNode->setAttribute('name', $author['name']);
            $authorNode->setAttribute('email', $author['email']);
            $authors->appendChild($authorNode);
            unset($authorNode);
        }

        return $doc->saveXML();
    }
453030
public function getAttributeFromXML($attribute, \SimpleXMLElement $xmlDocument)
    {
        /** @var \SimpleXMLElement $value */
        foreach ($xmlDocument->attributes() as $key => $value) {
            /** @var \SimpleXMLElement $attribute */
            if ($attribute === $key) {
                return (string) ($this->xmlToArray($value)[0]);
            }
        }

        return false;
    }
127674
private function restoreValueFromXmlString($xmlString)
    {
        $dom = new DOMDocument('1.0', 'utf-8');
        $authors = array();

        if ($dom->loadXML($xmlString) === true) {
            foreach ($dom->getElementsByTagName('author') as $author) {
                $authors[] = array(
                    'id' => $author->getAttribute('id'),
                    'name' => $author->getAttribute('name'),
                    'email' => $author->getAttribute('email'),
                );
            }
        }

        return $authors;
    }
155408
public function convert(DOMDocument $xmlDoc)
    {
        $xpath = new DOMXPath($xmlDoc);

        $elements = $xpath->query('//link|//embed|//embed-inline');

        /** @var \DOMElement $element */
        foreach ($elements as $element) {
            $location = null;

            if ($this->elementHasAttribute($element, 'object_id')) {
                try {
                    $contentInfo = $this->contentService->loadContentInfo(
                        $this->getElementAttribute($element, 'object_id')
                    );
                    $location = $this->locationService->loadLocation($contentInfo->mainLocationId);
                } catch (APINotFoundException $e) {
                    if ($this->logger) {
                        $this->logger->warning(
                            'While generating links for xmltext, could not locate ' .
                            'Content object with ID ' . $this->getElementAttribute($element, 'object_id')
                        );
                    }
                } catch (APIUnauthorizedException $e) {
                    if ($this->logger) {
                        $this->logger->notice(
                            'While generating links for xmltext, unauthorized to load ' .
                            'Content object with ID ' . $this->getElementAttribute($element, 'object_id')
                        );
                    }
                }
            }

            if ($this->elementHasAttribute($element, 'node_id')) {
                try {
                    $location = $this->locationService->loadLocation(
                        $this->getElementAttribute($element, 'node_id')
                    );
                } catch (APINotFoundException $e) {
                    if ($this->logger) {
                        $this->logger->warning(
                            'While generating links for xmltext, could not locate ' .
                            'Location with ID ' . $this->getElementAttribute($element, 'node_id')
                        );
                    }
                } catch (APIUnauthorizedException $e) {
                    if ($this->logger) {
                        $this->logger->notice(
                            'While generating links for xmltext, unauthorized to load ' .
                            'Location with ID ' . $this->getElementAttribute($element, 'node_id')
                        );
                    }
                }
            }

            if ($location !== null) {
                $element->setAttribute('url', $this->urlAliasRouter->generate($location));
            }

            // Copy temporary URL if it exists and is not set at this point
            if (!$element->hasAttribute('url') && $element->hasAttribute(EmbedLinking::TEMP_PREFIX . 'url')) {
                $element->setAttribute('url', $element->getAttribute(EmbedLinking::TEMP_PREFIX . 'url'));
            }

            if ($this->elementHasAttribute($element, 'anchor_name')) {
                $anchor = '#' . $this->getElementAttribute($element, 'anchor_name');
                if (strpos($element->getAttribute('url'), $anchor) === false) {
                    $element->setAttribute(
                        'url',
                        $element->getAttribute('url') . '#' .
                        $this->getElementAttribute($element, 'anchor_name')
                    );
                }
            }
        }
    }
443147
private static function fixXmlLocation(string $schemaSource, string $xmlUri): string
    {
        $newPath = str_replace('\\', '/', __DIR__).'/../Resources/schemas/xml.xsd';
        $parts = explode('/', $newPath);
        $locationstart = 'file:///';
        if (0 === stripos($newPath, 'phar://')) {
            $tmpfile = tempnam(sys_get_temp_dir(), 'symfony');
            if ($tmpfile) {
                copy($newPath, $tmpfile);
                $parts = explode('/', str_replace('\\', '/', $tmpfile));
            } else {
                array_shift($parts);
                $locationstart = 'phar:///';
            }
        }

        $drive = '\\' === \DIRECTORY_SEPARATOR ? array_shift($parts).'/' : '';
        $newPath = $locationstart.$drive.implode('/', array_map('rawurlencode', $parts));

        return str_replace($xmlUri, $newPath, $schemaSource);
    }
685030
private function handleValue( $value, DOMDocument $domDocument )
    {
        switch ( gettype( $value ) )
        {
            case 'integer':
                $node = $domDocument->createElement( 'int', $value );
                break;

            case 'boolean':
                $node = $domDocument->createElement( 'boolean', $value );
                break;

            case 'string':
                $node = $domDocument->createElement( 'string', $value );
                break;

            case 'double':
                $node = $domDocument->createElement( 'double', $value );
                break;

            case 'array':
                // array
                if ( empty( $value ) || key( $value ) === 0 )
                {
                    $node = $domDocument->createElement( 'array' );
                    $dataNode = $domDocument->createElement( 'data' );
                    $node->appendChild( $dataNode );

                    foreach ( $value as $cell )
                    {
                        $valueNode = $domDocument->createElement( 'value' );
                        $valueNode->appendChild( $this->handleValue( $cell, $domDocument ) );
                        $dataNode->appendChild( $valueNode );
                    }
                }
                // hash
                else
                {
                    $node = $domDocument->createElement( 'struct' );

                    foreach ( $value as $name => $cell )
                    {
                        // //member
                        $memberNode = $domDocument->createElement( 'member' );

                        // //member/name
                        $memberNode->appendChild( $domDocument->createElement( 'name', $name ) );

                        // //member/value
                        $valueNode = $domDocument->createElement( 'value' );
                        $memberNode->appendChild( $valueNode );
                        // //member/value/*
                        $valueNode->appendChild( $this->handleValue( $cell, $domDocument ) );

                        $node->appendChild( $memberNode );
                    }
                }
                break;

            case 'object':
                {
                    // DateTime is okay
                    if ( !$value instanceof DateTime )
                        continue;
                    $node = $domDocument->createElement( 'dateTime.iso8601', $value->format( DateTime::ISO8601 ) );
                }
                break;

            default:
                {
                    throw new \UnexpectedValueException( "Unknown return value type" );
                }
        }

        return $node;
    }
1041982
private String prepareXmlForParsing(String xml) throws TheDavidBoxClientException{
		//Escape all & symbols in the response so it can parse it later
		xml = xml.replaceAll("&", "&amp;");
		
		String xmlReady;
		try {
			//It repairs the encoding to allow all utf-8 symbols
			xmlReady = new String(xml.getBytes(), CHARSET_ENCODING);
		} catch (UnsupportedEncodingException e) {
			throw new TheDavidBoxClientException(e);
		}
		return xmlReady;
	}
494451
public static function parseResponseConditionXml(SimpleXMLElement $xml){
        $returnValue = self::parseElementXml($xml);
        foreach($xml->responseIf as $responseIfXml){
            $returnValue['responseIf'] = self::parseResponseIfXml($responseIfXml);
            break;
        }
        foreach($xml->responseElseIf as $responseIfXml){
            if(!isset($returnValue['responseElseIfs'])){
                $returnValue['responseElseIfs'] = array();
            }
            $returnValue['responseElseIfs'][] = self::parseResponseIfXml($responseIfXml);
        }
        foreach($xml->responseElse as $responseIfXml){
            $returnValue['responseElse'] = self::parseResponseElseXml($responseIfXml);
            break;
        }
        return $returnValue;
    }
1356371
private function requestResponseFor( $doi ) {

		$this->httpRequest->setOption( CURLOPT_FOLLOWLOCATION, true );

		$this->httpRequest->setOption( CURLOPT_RETURNTRANSFER, true );
		$this->httpRequest->setOption( CURLOPT_FAILONERROR, true );
		$this->httpRequest->setOption( CURLOPT_SSL_VERIFYPEER, false );

		$this->httpRequest->setOption( CURLOPT_URL, self::CROSSREF_CONTENT_API . $doi );

		$this->httpRequest->setOption( CURLOPT_HTTPHEADER, array(
			'Accept: application/vnd.citationstyles.csl+json',
			'Content-Type: application/x-www-form-urlencoded;charset=UTF-8'
		) );

		return $this->httpRequest->execute();
	}
1364463
private function fixEntities($xml)
    {
        $newXML = '';
        $n_letras = strlen($xml);
        $convertir = false;
        for ($i=0; $i<$n_letras; ++$i) {
            if ($xml[$i]=='>')
                $convertir = true;
            if ($xml[$i]=='<')
                $convertir = false;
            if ($convertir) {
                $l = $xml[$i]=='\'' ? '&apos;' : ($xml[$i]=='"' ? '&quot;' : $xml[$i]);
            } else {
                $l = $xml[$i];
            }
            $newXML .= $l;
        }
        return $newXML;
    }
1315789
public static function convertFromXMLString($root_element, $xml)
    {
        $doc = new DOMDocument('1.0', 'utf-8');
        $doc->loadXML($xml);

        return self::convertFromDOMDocument($root_element, $doc);
    }
473111
protected function validateHeaderValue($headerValue) : void
	{
		if (\is_string($headerValue))
		{
			$headerValue = [$headerValue];
		}

		if (! \is_array($headerValue) || [] === $headerValue)
		{
			throw new \InvalidArgumentException('Header value must be a string or not an empty array');
		}

		foreach ($headerValue as $oneOf)
		{
			if (! \is_string($oneOf))
			{
				throw new \InvalidArgumentException('Header value must be a string or an array containing only strings');
			}
			else if (! \preg_match(HeaderInterface::RFC7230_FIELD_VALUE, $oneOf))
			{
				throw new \InvalidArgumentException(\sprintf('The given header value "%s" is not valid', $oneOf));
			}
		}
	}
507492
private String replaceVars(final String langValue) {
        String ret = StringUtils.replace(langValue, "${servePath}", Latkes.getServePath());
        ret = StringUtils.replace(ret, "${staticServePath}", Latkes.getStaticServePath());

        return ret;
    }
1029759
private function setSpecificAttributeKeyWithGivenId(\SimpleXMLElement $xml, $keyValue) {
        // Specific Attribute: change the key with the given id
        if ($xml->attributes()->id) {
            return (string) $xml->attributes()->id;
        }
        return $keyValue;
    }
1349990
public static function parseExpressionXml(SimpleXMLElement $xml){
        $returnValue = self::parseElementXml($xml);
        $value = trim($xml);
        $expressions = array();
        foreach($xml->children() as $child){
            $expressions[] = self::parseExpressionXml($child);
        }
        if(count($expressions)){
            $returnValue['expressions'] = $expressions;
        }
        if(strlen($value)){
            $returnValue['value'] = $value;
        }
        return $returnValue;
    }