Extract a value from given element

@param  DOMElement $element
@return mixed
482928
protected function getValueFromElement(DOMElement $element)
	{
		return (!$element->attributes->length && $element->childNodes->length === 1 && $element->firstChild->nodeType === XML_TEXT_NODE)
		     ? $element->nodeValue
		     : $this->getElementConfig($element);
	}
290334
public function parseElement(Node $parent, \DOMElement $element)
    {
        if (Atom::NS !== $element->namespaceURI) {
            return null;
        }

        $name = 'atom:' . $element->localName;
        if (array_key_exists($name, $this->elementMap)) {
            $class = $this->elementMap[$name];

            return new $class($parent, $element);
        }

        return null;
    }
975474
protected function unmarshall(DOMElement $element)
    {
        $baseComponent = parent::unmarshall($element);
        $object = new NumberPresented();
        $object->setSectionIdentifier($baseComponent->getSectionIdentifier());
        $object->setIncludeCategories($baseComponent->getIncludeCategories());
        $object->setExcludeCategories($baseComponent->getExcludeCategories());

        return $object;
    }
502331
protected function getSubElement($element)
    {
        if ($element === BaseRange::INFINITY_MIN) {
            return BaseRange::INFINITY_MIN;
        } elseif ($element === BaseRange::INFINITY_MAX) {
            return BaseRange::INFINITY_MAX;
        } elseif ($element === '') {
            return null;
        }

        return new \DateTime($element);
    }
1015349
public function grabValueFrom($field)
    {
        $nodes = $this->match($field);
        if (!$nodes->count()) {
            throw new ElementNotFound($field, 'Field');
        }

        if ($nodes->filter('textarea')->count()) {
            return (new TextareaFormField($nodes->filter('textarea')->getNode(0)))->getValue();
        }

        $input = $nodes->filter('input');
        if ($input->count()) {
            return $this->getInputValue($input);
        }

        if ($nodes->filter('select')->count()) {
            $field = new ChoiceFormField($nodes->filter('select')->getNode(0));
            $options = $nodes->filter('option[selected]');
            $values = [];

            foreach ($options as $option) {
                $values[] = $option->getAttribute('value');
            }

            if (!$field->isMultiple()) {
                return reset($values);
            }

            return $values;
        }

        $this->fail("Element $nodes is not a form field or does not contain a form field");
    }
1192993
protected function extractNodesFromElement($element)
    {
        $references = array();
        if ($this->isNodeChoiceAttribute($element)) {
            $references = array($this->extractNodeFromChoiceAttribute($element));
        } elseif (is_string($element) && $this->hasInternalLinkBBCode($element)) {
            $references = array_merge($references, $this->extractNodeFromBBCode($element));
        } elseif (is_array($element)) {
            foreach ($element as $item) {
                $references = array_merge($references, $this->extractNodesFromElement($item));
            }
        }
        return $references;
    }
768006
protected function checkElementNode(DOMElement $element, Tag $tag)
	{
		$xpath = new DOMXPath($element->ownerDocument);

		// If current node is not an <xsl:attribute/> element, we exclude descendants
		// with an <xsl:attribute/> ancestor so that content such as:
		//   <script><xsl:attribute name="id"><xsl:value-of/></xsl:attribute></script>
		// would not trigger a false-positive due to the presence of an <xsl:value-of/>
		// element in a <script>
		$predicate = ($element->localName === 'attribute') ? '' : '[not(ancestor::xsl:attribute)]';

		// Test the select expression of <xsl:value-of/> nodes
		$query = './/xsl:value-of' . $predicate;
		foreach ($xpath->query($query, $element) as $valueOf)
		{
			$this->checkSelectNode($valueOf->getAttributeNode('select'), $tag);
		}

		// Reject all <xsl:apply-templates/> nodes
		$query = './/xsl:apply-templates' . $predicate;
		foreach ($xpath->query($query, $element) as $applyTemplates)
		{
			throw new UnsafeTemplateException('Cannot allow unfiltered data in this context', $applyTemplates);
		}
	}
504972
protected function wrap(\DOMElement $element, $html)
    {
        $wrapper = $element->ownerDocument->createDocumentFragment();
        $wrapper->appendXML($html);

        $result = $wrapper->firstChild;
        $element->parentNode->appendChild($wrapper);

        $xpath = new \DOMXpath($element->ownerDocument);
        $targets = $xpath->query('//inky-content', $wrapper);

        if ($targets->length) {
            $parent = $targets->item(0)->parentNode;
            $parent->removeChild($targets->item(0));
            $parent->appendChild($element);
        }

        return $result;
    }
976746
protected function serializeElement(DOMElement $element)
	{
		$php     = '';
		$elName  = $element->getAttribute('name');
		$id      = $element->getAttribute('id');
		$isVoid  = $element->getAttribute('void');

		// Test whether this element name is dynamic
		$isDynamic = (bool) (strpos($elName, '{') !== false);

		// PHP representation of this element's name
		$phpElName = $this->convertAttributeValueTemplate($elName);

		// NOTE: the element name is escaped by default to account for dynamically-generated names
		$phpElName = 'htmlspecialchars(' . $phpElName . ',' . ENT_QUOTES . ')';

		// If the element name is dynamic, we cache its name for convenience and performance
		if ($isDynamic)
		{
			$varName = '$e' . $id;

			// Add the var declaration to the source
			$php .= $varName . '=' . $phpElName . ';';

			// Replace the element name with the var
			$phpElName = $varName;
		}

		// Test whether this element is void if we need this information
		if ($isVoid === 'maybe')
		{
			$php .= '$v' . $id . '=preg_match(' . var_export(TemplateParser::$voidRegexp, true) . ',' . $phpElName . ');';
		}

		// Open the start tag
		$php .= "\$this->out.='<'." . $phpElName . ';';

		// Serialize this element's content
		$php .= $this->serializeChildren($element);

		// Close that element unless we know it's void
		if ($isVoid !== 'yes')
		{
			$php .= "\$this->out.='</'." . $phpElName . ".'>';";
		}

		// If this element was maybe void, serializeCloseTag() has put its content within an if
		// block. We need to close that block
		if ($isVoid === 'maybe')
		{
			$php .= '}';
		}

		return $php;
	}
847792
protected function exportHtml(\DOMElement $element)
    {
        $body = $this->getDocument()->createElement('body');
        $body->appendChild($element);
        $html = $this->getDocument()->getElementsByTagName('html')->item(0);
        $html->appendChild($this->getHead());
        $html->appendChild($body);

        $html =  $this->getDocument()->saveHTML();
        $this->reset();

        return $html;
    }
785685
private function extractObject(Element $element){
        if($element instanceof Container){
            foreach($element->getElements('oat\taoQtiItem\model\qti\QtiObject') as $object){
                $this->loadObjectAssets($object);
            }
        }
        if($element instanceof QtiObject){
            $this->loadObjectAssets($element);
        }
    }
360261
protected function unmarshall(DOMElement $element)
    {
        if (($shape = $this->getDOMElementAttributeAs($element, 'shape')) !== null) {

            $shapeVal = QtiShape::getConstantByName($shape);

            if ($shapeVal !== false) {

                if (($coords = $this->getDOMElementAttributeAs($element, 'coords')) !== null) {

                    try {
                        $coords = Utils::stringToCoords($coords, $shapeVal);

                        if (($mappedValue = $this->getDOMElementAttributeAs($element, 'mappedValue', 'float')) !== null) {
                            return new AreaMapEntry($shapeVal, $coords, $mappedValue);
                        } else {
                            $msg = "The mandatory attribute 'mappedValue' is missing from element '" . $element->localName . "'.";
                            throw new UnmarshallingException($msg, $element);
                        }
                    } catch (Exception $e) {
                        if (!$e instanceof UnmarshallingException) {
                            $msg = "The attribute 'coords' with value '${coords}' has an invalid value.";
                            throw new UnmarshallingException($msg, $element, $e);
                        } else {
                            throw $e;
                        }
                    }
                } else {
                    $msg = "The mandatory attribute 'coords' is missing from element '" . $element->localName . "'.";
                    throw new UnmarshallingException($msg, $element);
                }
            } else {
                $msg = "The 'shape' attribute value '${shape}' is not a valid value to represent QTI shapes.";
                throw new UnmarshallingException($msg, $element);
            }

        } else {
            $msg = "The mandatory attribute 'shape' is missing from element '" . $element->localName . "'.";
            throw new UnmarshallingException($msg, $element);
        }
    }
916454
public function convertDOM($domElement) {

        $value = "";

        // Deal with straightforward primitives first.  These occur when a text node is passed
        if ($domElement instanceof \DOMText || $domElement instanceof \DOMAttr) {

            // Get the value
            $value = utf8_decode($domElement->nodeValue);

            // Handle booleans as special case
            if (strtolower($value) == "true") {
                $value = true;
            } elseif (strtolower($value) == "false") {
                $value = false;
            }

        } // Now deal with the inherently more complex element cases
        else if ($domElement instanceof \DOMElement) {

            // Get the name
            $elementName = $domElement->nodeName;

            // Handle the Array case next
            if (strtolower($elementName) == "array" || (isset($this->tagClassMap[$elementName]) && strtolower($this->tagClassMap [$elementName]) == "array")) {

                $value = array();

                // Loop through each child.  If we encounter "Value" elements we find the first child of the value item and pass this off for
                // recursive processing, otherwise we pass the child node off for processing and add the result to the array to return
                $arrayElements = $domElement->childNodes;
                for ($i = 0; $i < $arrayElements->length; $i++) {
                    $arrayElement = $arrayElements->item($i);

                    if ($arrayElement instanceof \DOMElement) {

                        $key = $arrayElement->getAttribute("key");

                        // Convert the value into an object
                        $convertedValue = $this->convertDOM($arrayElement);

                        // Now set the array value either with a key or not depending on whether a key attribute is set.
                        if (isset ($key) && $key) {
                            $value [$key] = $convertedValue;
                        } else {
                            $value [] = $convertedValue;
                        }
                    }
                }

            } // Handle the case where a value node is passed.  This only occurs in the case where a lazy array is defined
            // With a single entry.  Here we simply evaluate and pass back the child entity
            else if (strtolower($elementName) == "value") {

                $valueElements = $domElement->childNodes;

                // Check for the count of child nodes to see whether we need to implicitly create an array wrapper
                if ($valueElements->length == 0) {
                    $value = "";
                } else if ($valueElements->length == 1) {
                    $value = $this->convertDOM($valueElements->item(0));
                } else {
                    $value = array();
                    for ($j = 0; $j < $valueElements->length; $j++) {
                        $currentItem = $valueElements->item($j);
                        if (!($currentItem instanceof \DOMText) && !($currentItem instanceof \DOMComment)) {
                            $key = $currentItem->getAttribute("key");
                            if (isset ($key) && $key) {
                                $value [$key] = $this->convertDOM($currentItem);
                            } else {
                                $value [] = $this->convertDOM($currentItem);
                            }
                        }
                    }
                    // If the result was only in fact a single item, reduce the array to a single value again.
                    if (sizeof($value) == 1) {
                        $value = $value [0];
                    }
                }

            } // Otherwise we must be in the object case
            else {

                // Array of property sets which pertain to set or get methods.  These
                // ensure that we write non accessor members first and prevent
                // ordering problems when we provide custom functionality to write to
                // properties in other get / set methods.
                $deferredPropertySets = array();

                // If a mapping has been defined for this element, use the mapping
                if (isset ($this->tagClassMap [$elementName])) {
                    $elementName = $this->tagClassMap [$elementName];
                }

                // Create the class

                if (strtolower($elementName) == "value") {
                    $value = $this->convertDOM($domElement->childNodes->item(0));
                } else {
                    $value = $this->loadObject($domElement, $elementName);
                }
            }

        }

        return $value;

    }
1103466
protected function getElementTemplate($element)
  {
    $element = strtolower($element);
    if (!array_key_exists($element, $this->elementTemplates)) {
      throw new \Exception(sprintf('Element %s non reconnu.', $element));
      return '';
    }

    if (!is_null($this->elementTemplates[$element])) {
      return $this->elementTemplates[$element];
    }

    $content = static::getAssetContent($element);
    $content = str_replace('%class%', implode(' ', $this->elementClasses[$element]), $content);
    $content = str_replace('%querystring%', $this->getQueryString(), $content);
    $content = str_replace('%argumentname%', $this->argumentName, $content);
    $this->elementTemplates[$element] = $content;
    return $content;
  }
1309024
function get_inner_html( DOMElement $element ) {

        $inner_html= '';

        $children = $element->childNodes;

        foreach ( $children as $child ) {

            $inner_html .= $child->ownerDocument->saveXML( $child );

        }

        return $inner_html;

    }
784284
protected function unmarshall(DOMElement $element)
    {
        $component = new Colgroup();

        if (($span = $this->getDOMElementAttributeAs($element, 'span', 'integer')) !== null) {
            $component->setSpan($span);
        }

        $cols = new ColCollection();
        foreach ($this->getChildElementsByTagName($element, 'col') as $colElt) {
            $marshaller = $this->getMarshallerFactory()->createMarshaller($colElt);
            $cols[] = $marshaller->unmarshall($colElt);
        }
        $component->setContent($cols);

        $this->fillBodyElement($component, $element);

        return $component;
    }
35942
protected function elementHasSafeUrl(DOMElement $element)
	{
		return $element->firstChild instanceof DOMText && $this->isSafeUrl($element->firstChild->textContent);
	}