@param \SimpleXMLElement $elem

@return iterable
963898
private function loadAnnotationProperties(\SimpleXMLElement $elem): iterable
    {
        foreach ($elem->attributes() as $attrName => $value) {
            $value = (string) $value;

            if ('true' === $value) {
                $value = true;
            } elseif ('false' === $value) {
                $value = false;
            }

            yield $attrName => $value;
        }
    }
372513
protected function namespaceAttrs($ele) {
        if (!$this->xpath || $this->xpath->document !== $ele->ownerDocument) {
            $this->xpath = new \DOMXPath($ele->ownerDocument);
        }

        foreach ($this->xpath->query('namespace::*[not(.=../../namespace::*)]', $ele) as $nsNode) {
            if (!in_array($nsNode->nodeValue, $this->implicitNamespaces)) {
                $this->wr(' ')->wr($nsNode->nodeName)->wr('="')->wr($nsNode->nodeValue)->wr('"');
            }
        }
    }
105884
protected function fillXml(\SimpleXMLElement $element, $data)
    {
        foreach ($data as $key => $value) {
            if (is_array($value) || is_object($value)) {
                if (!is_numeric($key)) {
                    $child = $element->addChild($key);
                } else {
                    $child = $element;
                }
                
                $this->fillXml($child, $value);
            } else {
                $element->addChild($key, $value);
            }
        }
    }
1310000
protected function appendHTML(DOMElement $elem, string $html): DOMElement
   {
       try {
           $dom = new DOMDocument();
           $this->loadHTML($dom, $html);
           foreach($dom->childNodes as $node) {
               if ($node instanceof DOMElement) {
                   $elem->appendChild($this->template->createTextNode("\n"));
                   $elem->appendChild($this->template->importNode($node, true));
               }
           }
           return $elem;
       } catch (Throwable $e) {
           throw new RuntimeException("Can't append HTML: " . $e->getMessage());
       }
   }
1138222
function( elem ) {
        var data = {}, attr = elem.attributes;
        for( var i in attr ) {
            if( /^data-/.test(attr[i].name) ) {
                var key = attr[i].name.replace(/^data-/,'');
                data[ camelize(key) ] = typify( attr[i].value );
            }
        }
        return data;
    }
1059390
public static Optional<Element> getChildElement(final Element elem, final DitaClass cls) {
        final NodeList children = elem.getChildNodes();
        for (int i = 0; i < children.getLength(); i++) {
            final Node child = children.item(i);
            if (cls.matches(child)) {
                return Optional.of((Element) child);
            }
        }
        return Optional.empty();
    }
647633
def load(self, elem):
        
        self.testTag(elem, 'set')
        out = set()
        for xitem in elem:
            out.add(XmlDataIO.fromXml(xitem))
        return out
1067054
protected function elem(string $elemDef, $arrayArgs=[]) : self
        {
            [$tagName, $attrs] = $this->_parseElem($elemDef, $arrayArgs);

            if (isset ($this->emptyTags[$tagName])) {
                $newNode = new HtmlElement($tagName, $attrs);
            } else {
                $newNode = new HtmlContainerElement($tagName, $attrs);
            }
            $this->curNode->add($newNode);
            return $this->cloneit($newNode);
        }
964962
public function ElementsByContexts( $contexts )
	{
		if ( is_string( $contexts ) )
			$contexts = array_map( 'trim', explode( ",", $contexts ) );

		if ( is_a( $contexts, 'ContextsFilter' ) )
			$contexts = $contexts->Keys();

		if ( ! is_array( $contexts ) )
			throw new Exception( 'InstanceElementsFilter::ElementsByName $contexts must be a string or array' );

		$contexts = array_flip( array_map( 'strtolower', $contexts ) );

		// In PHP 7.0 $this is passed to closure functions automatically but not in earlier versions
		$elements = &$this->elements;

		$filtered = array_reduce( array_keys( $this->elements ), function( $carry, $elementName ) use( $contexts, &$elements ) {

			$contextElements = array_filter( $elements[ $elementName ], function( $element ) use( &$contexts, &$elements ) {

				if ( isset( $element['contextRef'] ) )
				{
					return isset( $contexts[ strtolower( $element['contextRef'] ) ] );
				}

				// Could be a tuple in which case the tuple members should be checked
				return array_reduce( $element['tuple_elements'], function( $carry, $tuple_element ) use( $contexts ) {

					if ( $carry ) return true; // Once one valid member is found there's no need to look for any others
					return array_reduce( $tuple_element, function( $carry, $entry ) use( $contexts ) {

						if ( $carry ) return true; // Once one valid member is found there's no need to look for any others
						return isset( $contexts[ strtolower( $entry['contextRef'] ) ] );

					} );

				}, false );

			} );

			if ( ! $contextElements ) return $carry;

			$carry[ $elementName ] = $contextElements;

			return $carry;

		}, array() );

		return new InstanceElementsFilter( $this->instance, $filtered );
	}
30157
public function parseXPath(array $xPaths, SimpleXMLElement $elem, $asArray = true)
    {

        if (!isset($xPaths['xPath']) || !isset($xPaths['key'])) {
            throw new \Exception('xPath Should have "xPath" & "key" set');
        }

        $xPath          = $xPaths['xPath'];
        $childXPaths    = (isset($xPaths['children'])) ? $xPaths['children'] : null;

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

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

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

            if (null !== $childXPaths) {
                foreach ($childXPaths as $childXPath) {
                    $getTextContent = true;
                    if (preg_match('#\/text\(\)$#', $childXPath['xPath'])) {
                        //we want to extract the value
                        //not an array of values
                        $getTextContent = false;
                    }

                    $childData = $this->parseXPath($childXPath, $child, $getTextContent);
                    if ($getTextContent) {
                        $data[$childXPath['key']] = $childData;
                    } else {
                        $data[$childXPath['key']] = current($childData);
                    }
                }
            }

            $return[] = $data;
        }
        return $return;
    }
847260
protected function _property(\SimpleXMLElement $element, $property): array
    {
        $output = [];

        if (\method_exists($element, $property)) {
            $properties = $element->$property();

            if ($properties) {

                $data = \is_array($properties) ?
                    $properties : $this->_asArray($properties);

                if ($data !== null || $data === '') {
                    $output['@' . $property] = $data;
                }
            }
        }

        return $output;
    }
1289373
function (elem) {
    this._forEachNode(this._getAllNodesWithTag(elem, ["br"]), function(br) {
      var next = br.nextSibling;

      // Whether 2 or more <br> elements have been found and replaced with a
      // <p> block.
      var replaced = false;

      // If we find a <br> chain, remove the <br>s until we hit another element
      // or non-whitespace. This leaves behind the first <br> in the chain
      // (which will be replaced with a <p> later).
      while ((next = this._nextElement(next)) && (next.tagName == "BR")) {
        replaced = true;
        var brSibling = next.nextSibling;
        next.parentNode.removeChild(next);
        next = brSibling;
      }

      // If we removed a <br> chain, replace the remaining <br> with a <p>. Add
      // all sibling nodes as children of the <p> until we hit another <br>
      // chain.
      if (replaced) {
        var p = this._doc.createElement("p");
        br.parentNode.replaceChild(p, br);

        next = p.nextSibling;
        while (next) {
          // If we've hit another <br><br>, we're done adding children to this <p>.
          if (next.tagName == "BR") {
            var nextElem = this._nextElement(next.nextSibling);
            if (nextElem && nextElem.tagName == "BR")
              break;
          }

          if (!this._isPhrasingContent(next)) break;

          // Otherwise, make this node a child of the new <p>.
          var sibling = next.nextSibling;
          p.appendChild(next);
          next = sibling;
        }

        while (p.lastChild && this._isWhitespace(p.lastChild)) p.removeChild(p.lastChild);
      }
    });
  }
1373909
final protected function parseSimpleXML(\SimpleXMLElement $element)
    {
        $elements = [];

        foreach ($element->attributes() as $attribute => $value) {
            $elements[$attribute] = $value instanceof \SimpleXMLElement ? $this->parseSimpleXML($value) : $value;
        }

        foreach ($element->children() as $node => $child) {
            $elements[$node] = $child instanceof \SimpleXMLElement ? $this->parseSimpleXML($child) : $child;
        }

        if ($element->count() === 0 && \trim((string) $element) !== '') {
            $value = $this->getTypedValue((string) $element);

            if (\count($elements) === 0) {
                return $value;
            }

            $elements['_value_'] = $value;
        }

        return $elements;
    }
354579
protected function simpleXmlToArray(SimpleXMLElement $xml) {
		$result = [];
		
		foreach ($xml as $element) {
			$name    = $element->getName();
			$content = get_object_vars($element);
			
			if (isset($content['@attributes'])){
				if (isset($content['@attributes']['value'])) {
					$result[$name] = Std::parseValue($content['@attributes']['value']);
					continue;
				}
				
				unset($content['@attributes']);
			}
			
			if (empty($content)) {
				$result[$name] = Std::parseValue($element);
				continue;
			}
			
			$result[$name] = $this->simpleXmlToArray($element);
		}
		
		return $result;
	}
260749
public static List<Element> getChildElements(final Element elem, final DitaClass cls) {
        return getChildElements(elem, cls, false);
    }
34530
public function append($ele)
  {
    $args = \func_get_args();
    foreach ( $args as $ele ){
      if ( !isset($this->content) ){
        if ( \is_array($ele) && isset($ele[0]) ){
          $this->content = $ele;
        }
        else{
          $this->content = \is_object($ele) ? [$ele] : $ele;
        }
      }
      else if ( \is_array($this->content) ){
        if ( \is_array($ele) ){
          array_merge($this->content, $ele);
        }
        else{
          array_push($this->content, $ele);
        }
      }
      else if ( \is_string($this->content) ){
        if ( \is_array($ele) ){
          foreach ( $ele as $e ){
            $this->content .= $e->html();
          }
        }
        else{
          $this->content .= \is_object($ele) ? $ele->html() : $ele;
        }
      }
    }
    return $this;
  }
1013325
private static function simpleXmlToArray($element)
    {
        //====================================================================//
        // Safety Check
        if (false === $element) {
            return false;
        }
        //====================================================================//
        // Init Result
        $result = array();
        //====================================================================//
        // Get First Level Childrens
        $children = $element->children();
        $isArrayElement = false;
        //====================================================================//
        // For All Childrens
        foreach ($children as $elementName => $node) {
            //====================================================================//
            // This Element is an ArrayElement
            $isArrayElement = true;
            //====================================================================//
            // If Element Doesn't Already Exists => Store as Single Element
            if (!isset($result[$elementName])) {
                $result[$elementName] = array();
                $result[$elementName] = self::simpleXmlToArray($node);

                continue;
            }
            //====================================================================//
            // Element Already Exists => Store as Array Element
            //====================================================================//
            // Convert Single Element to Array Element
            if (!is_array($result[$elementName])) {
                $singleElement = $result[$elementName];       // Store Firts Element
                $result[$elementName] = array();                    // Create New Array
                $result[$elementName][] = $singleElement;             // Append To Array
            }
            //====================================================================//
            // Append Array Element
            $result[$elementName][] = self::simpleXmlToArray($node);
        }
        //====================================================================//
        // Return Single Element
        if (!$isArrayElement && '' == $children->getName()) {
            $result = base64_decode((string) $element, true);
        }

        return $result;
    }