Baigudin Software avatar
Baigudin Software logo
ru region
en region

PHP DOM Builder API 2.0

Baigudin Software registers the copyright of its own operating system – Embedded Object Operating System

The Russian Federal Service for Intellectual Property (Rospatent) registers the copyright of Embedded Object Operating System – Baigudin Software’s own embedded object-oriented 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.

use DomBuilder\Element as Element
// Create document 
$document Element::create()   
// 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" "">
<html xmlns="" xml:lang="en" lang="en">
    <title>PHP DOM Builder test page</title>
      Hello world

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