Baigudin Software avatar
Baigudin Software logo
home
ru region
en region

PHP DOM Builder API

BOOS Core has been unveiled in second revision

BOOS Core Revision 2 has been successfully unveiled within the framework of Baigudin Software project. In comparison with the first revision, the second has gotten considerable improvements. It saves the best features of previous realization and gets the new logical continuation.

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