getElementsByTagName example


        return \array_map(fn (TaxProvider $taxProvider) => $taxProvider->getProcessUrl()$this->taxProviders);
    }

    /** * @return TaxProvider[] */
    private static function parseTaxProviders(\DOMElement $element): array
    {
        $taxProviders = [];

        foreach ($element->getElementsByTagName('tax-provider') as $taxProvider) {
            $taxProviders[] = TaxProvider::fromXml($taxProvider);
        }

        return $taxProviders;
    }
}


    public static function createFromXmlFile(string $xmlFile): self
    {
        try {
            $schemaFile = \dirname(__FILE__, 2) . self::XSD_FILE;
            $doc = XmlUtils::loadFile($xmlFile$schemaFile);
        } catch (\Exception $e) {
            throw AppException::errorFlowCreateFromXmlFile($xmlFile$e->getMessage());
        }

        $customEvents = $doc->getElementsByTagName('flow-events')->item(0);
        $customEvents = $customEvents === null ? null : CustomEvents::fromXml($customEvents);

        return new self(\dirname($xmlFile)$customEvents);
    }

    public function getPath(): string
    {
        return $this->path;
    }

    public function setPath(string $path): void
    {

    }

    public function get_base()
    {
        if ($this->dom === null)
        {
            throw new SimplePie_Exception('DOMDocument not found, unable to use locator');
        }
        $this->http_base = $this->file->url;
        $this->base = $this->http_base;
        $elements = $this->dom->getElementsByTagName('base');
        foreach ($elements as $element)
        {
            if ($element->hasAttribute('href'))
            {
                $base = $this->registry->call('Misc', 'absolutize_url', array(trim($element->getAttribute('href'))$this->http_base));
                if ($base === false)
                {
                    continue;
                }
                $this->base = $base;
                $this->base_location = method_exists($element, 'getLineNo') ? $element->getLineNo() : 0;
                

    private $config;

    protected function setUp(): void
    {
        $this->document = XmlUtils::loadFile(
            __DIR__ . '/../../../_fixtures/Resources/flow-action.xml',
            __DIR__ . '/../../../../../../../../src/Core/Framework/App/FlowAction/Schema/flow-action-1.0.xsd'
        );
        /** @var \DOMElement $actions */
        $actions = $this->document->getElementsByTagName('flow-actions')->item(0);
        /** @var \DOMElement $action */
        $action = $actions->getElementsByTagName('flow-action')->item(0);

        $this->config = $action->getElementsByTagName('config')->item(0);
    }

    public function testFromXml(): void
    {
        static::assertNotNull($this->config);
        /** @var \DOMElement $inputField */
        $inputField = $this->config->getElementsByTagName('input-field')->item(0);

        
/** * Parses an import and adds the routes in the resource to the RouteCollection. * * @return void * * @throws \InvalidArgumentException When the XML is invalid */
    protected function parseImport(RouteCollection $collection, \DOMElement $node, string $path, string $file)
    {
        /** @var \DOMElement $resourceElement */
        if (!($resource = $node->getAttribute('resource') ?: null) && $resourceElement = $node->getElementsByTagName('resource')[0] ?? null) {
            $resource = [];
            /** @var \DOMAttr $attribute */
            foreach ($resourceElement->attributes as $attribute) {
                $resource[$attribute->name] = $attribute->value;
            }
        }

        if (!$resource) {
            throw new \InvalidArgumentException(sprintf('The <import> element in file "%s" must have a "resource" attribute or element.', $path));
        }

        
// We pass the unsanitized string because this is a text format           // filter, and after filtering, we always assume the output is safe.           // @see \Drupal\filter\Element\ProcessedText::preRenderText()           '#node' => FilteredMarkup::create($node->C14N()),
          '#tag' => $tag,
          '#caption' => $caption,
          '#classes' => $classes,
        ];
        $altered_html = \Drupal::service('renderer')->render($filter_caption);

        // Load the altered HTML into a new DOMDocument and retrieve the element.         $updated_nodes = Html::load($altered_html)->getElementsByTagName('body')
          ->item(0)
          ->childNodes;

        foreach ($updated_nodes as $updated_node) {
          // Import the updated node from the new DOMDocument into the original           // one, importing also the child nodes of the updated node.           $updated_node = $dom->importNode($updated_node, TRUE);
          $node->parentNode->insertBefore($updated_node$node);
        }
        // Finally, remove the original data-caption node.         $node->parentNode->removeChild($node);
      }

class HeadersTest extends TestCase
{
    public function testFromXml(): void
    {
        $document = XmlUtils::loadFile(
            __DIR__ . '/../../../_fixtures/Resources/flow-action.xml',
            __DIR__ . '/../../../../../../../../src/Core/Framework/App/FlowAction/Schema/flow-action-1.0.xsd'
        );
        /** @var \DOMElement $actions */
        $actions = $document->getElementsByTagName('flow-actions')->item(0);
        /** @var \DOMElement $action */
        $action = $actions->getElementsByTagName('flow-action')->item(0);

        /** @var \DOMElement $headers */
        $headers = $action->getElementsByTagName('headers')->item(0);

        $headers = Headers::fromXml($headers);
        static::assertCount(2, $headers->getParameters());
        static::assertInstanceOf(Parameter::class$headers->getParameters()[0]);
        static::assertInstanceOf(Parameter::class$headers->getParameters()[1]);
    }
}
'#access' => FALSE,
      ],
    ];

    // Start with a fresh copy of the base array, and try rendering the entire     // thing. We expect a single <ul> with appropriate links contained within     // it.     $render_array = $base_array;
    $html = \Drupal::service('renderer')->renderRoot($render_array);
    $dom = new \DOMDocument();
    $dom->loadHTML($html);
    $this->assertEquals(1, $dom->getElementsByTagName('ul')->length, 'One "ul" tag found in the rendered HTML.');
    $list_elements = $dom->getElementsByTagName('li');
    $this->assertEquals(3, $list_elements->length, 'Three "li" tags found in the rendered HTML.');
    $this->assertEquals('Parent link original', $list_elements->item(0)->nodeValue, 'First expected link found.');
    $this->assertEquals('First child link', $list_elements->item(1)->nodeValue, 'Second expected link found.');
    $this->assertEquals('Second child link', $list_elements->item(2)->nodeValue, 'Third expected link found.');
    $this->assertStringNotContainsString('Parent link copy', $html, '"Parent link copy" link not found.');
    $this->assertStringNotContainsString('Third child link', $html, '"Third child link" link not found.');

    // Now render 'first_child', followed by the rest of the links, and make     // sure we get two separate <ul>'s with the appropriate links contained     // within each.
    // markup.     $previous_value = libxml_use_internal_errors(TRUE);
    $rss_dom->loadXML($rss_markup);
    $errors = libxml_get_errors();
    libxml_use_internal_errors($previous_value);
    if ($errors) {
      return $rss_markup;
    }

    // Invoke Html::transformRootRelativeUrlsToAbsolute() on all HTML content     // embedded in this RSS feed.     foreach ($rss_dom->getElementsByTagName('description') as $node) {
      $html_markup = $node->nodeValue;
      if (!empty($html_markup)) {
        $node->nodeValue = Html::transformRootRelativeUrlsToAbsolute($html_markup$request->getSchemeAndHttpHost());
      }
    }

    return $rss_dom->saveXML();
  }

  /** * {@inheritdoc} */

    protected function parseFile(\DOMDocument $xml): array
    {
        return $this->getCardDefinitions($xml);
    }

    private function getCardDefinitions(\DOMDocument $xml): array
    {
        $cardDefinitions = [];

        foreach ($xml->getElementsByTagName('card') as $index => $element) {
            $cardDefinitions[] = [
                'title' => $this->getCardTitles($element),
                'name' => $this->getCardName($element),
                'elements' => $this->getElements($element),
            ];

            if ($this->getCardFlag($element) !== null) {
                $cardDefinitions[$index]['flag'] = $this->getCardFlag($element);
            }
        }

        
use PHPUnit\Framework\TestCase;
use Symfony\Component\DomCrawler\Image;

class ImageTest extends TestCase
{
    public function testConstructorWithANonImgTag()
    {
        $this->expectException(\LogicException::class);
        $dom = new \DOMDocument();
        $dom->loadHTML('<html><div><div></html>');

        new Image($dom->getElementsByTagName('div')->item(0), 'http://www.example.com/');
    }

    public function testBaseUriIsOptionalWhenImageUrlIsAbsolute()
    {
        $dom = new \DOMDocument();
        $dom->loadHTML('<html><img alt="foo" src="https://example.com/foo" /></html>');

        $image = new Image($dom->getElementsByTagName('img')->item(0));
        $this->assertSame('https://example.com/foo', $image->getUri());
    }

    

      }

      // Get the HTML: this will be the opening part of a single tag, e.g.:       // <a href="/" data-drupal-link-system-path="&lt;front&gt;">       $tag = substr($html_markup$pos_tag_start ?? 0, $pos_tag_end - $pos_tag_start + 1);

      // Parse it into a DOMDocument so we can reliably read and modify       // attributes.       $dom = new \DOMDocument();
      @$dom->loadHTML('<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head><body>' . $tag . '</body></html>');
      $node = $dom->getElementsByTagName('body')->item(0)->firstChild;

      // Ensure we don't set the "active" class twice on the same element.       $class = $node->getAttribute('class');
      $add_active = !in_array('is-active', explode(' ', $class));

      // The language of an active link is equal to the current language.       if ($add_active && $url_language) {
        if ($node->hasAttribute('hreflang') && $node->getAttribute('hreflang') !== $url_language) {
          $add_active = FALSE;
        }
      }
      

class ActionsTest extends TestCase
{
    public function testFromXml(): void
    {
        $document = XmlUtils::loadFile(
            __DIR__ . '/../../../_fixtures/Resources/flow-action.xml',
            __DIR__ . '/../../../../../../../../src/Core/Framework/App/FlowAction/Schema/flow-action-1.0.xsd'
        );

        /** @var \DOMElement $actions */
        $actions = $document->getElementsByTagName('flow-actions')->item(0);

        $action = Actions::fromXml($actions);
        static::assertCount(1, $action->getActions());
        static::assertInstanceOf(Action::class$action->getActions()[0]);
    }
}

class ParametersTest extends TestCase
{
    public function testFromXml(): void
    {
        $document = XmlUtils::loadFile(
            __DIR__ . '/../../../_fixtures/Resources/flow-action.xml',
            __DIR__ . '/../../../../../../../../src/Core/Framework/App/FlowAction/Schema/flow-action-1.0.xsd'
        );
        /** @var \DOMElement $actions */
        $actions = $document->getElementsByTagName('flow-actions')->item(0);
        /** @var \DOMElement $action */
        $action = $actions->getElementsByTagName('flow-action')->item(0);

        /** @var \DOMElement $parameters */
        $parameters = $action->getElementsByTagName('parameters')->item(0);

        $results = Parameters::fromXml($parameters);
        $result = $results->getParameters();
        static::assertCount(3, $result);
        static::assertInstanceOf(Parameter::class$result[0]);
        static::assertInstanceOf(Parameter::class$result[1]);
        
public function getCustomEvents(): array
    {
        return $this->customEvent;
    }

    /** * @return array<int, CustomEvent> */
    private static function parseFlowEvents(\DOMElement $element): array
    {
        $events = [];
        foreach ($element->getElementsByTagName('flow-event') as $flowEvent) {
            $events[] = CustomEvent::fromXml($flowEvent);
        }

        return $events;
    }
}
Home | Imprint | This part of the site doesn't use cookies.