PHP DOM Element Problem
PHP DOM Element Problem
The Element class represents an HTML/XML tag that defines a DOM tree. An example:
-you may see there are elements with or without closing tag (</elementclosingtag>)
-you may see there are attributes of elements that have or don’t have a value (att2)
-you may see there can also be terminal string nodes(“Hello world!”).
Each element:
-has its own tag name;
-may or not have an ending tag. Elements that don’t have ending/enclosing tag are known as standalone
elements. That can be known using a private boolean variable, for example.
-an array of key-value attributes. There can also exist attributes that have empty value inside, for example
see “checked” attribute: <input type=”checkbox” checked>
-an array of element objects, that represents its direct children inside the DOM. Children in this array can
be other element objects are the same type as the parent object, having their own name, attributes and
children elements etc.
-Remember, children in an element's children array can also be bare string terminals:
example: <p class="blue-p">
I am a blue text.
<span style="color: red">But i am red.</span>
</p>
Up here, the p element has two children:
-one that is a string
-one that is an element, having another single child being a string.
Requirements:
-Define the Element Class, its fields and constructor.
The constructor can be done such:
-The element class should also have an instance method named “toString()”. This method will return the
HTML string representation of the DOM tree stored in the corresponding Element object.
Example of usage
<div class=”btn”>
Log In
</i>
</div>
</div>
By echoing this into the browser, you may see the DOM tree that was build using inspect element.