Baigudin Software avatar
Baigudin Software logo
home
ru region
en region

PHP DOM Builder API 2.0

EOOS Automotive R22-08 is released in version v0.10.0

The second official release of EOOS Automotive that is qualified for POSIX and WIN32 compatible operating systems and based on interfaces designed for EOOS RT – real time operating system.

DOM tree traversal

In previous article, we have created a basic HTML document. Actually, it was only a cover for future events. Let's try to add something more than we have. For example, we will output "Hello world" and add "PHP DOM Builder test page" title.

<?php
use DomBuilder\Element as Element
// Create document 
$document Element::create()   
  ->
insert('html')     
  ->
insert('head')     
  ->
after('body')     
  ->
root(); 
// Look for BODY tag in document  
$p $document->child()->child()->next()->insert('p')->html('Hello world'); 
// Look for HEAD tag relatively from created P teg
$p->parent()->prev()->insert('title')->html('PHP DOM Builder test page'); 
// Output document 
echo Element::getDocument($document);
?>

The result of this example is this document page:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    <title>PHP DOM Builder test page</title>
  </head>
  <body>
    <p>
      Hello world
    </p>
  </body>
</html>

That tree traversal technique is more efficient, but it is not useful some times. Other techniques for selecting elements, we will discuss in next articles .

To the previous article

To the articles list

To the next article