At the moment I have a nice class that generates HTML and allows me to create pages without having to worry about things like closing tags, proper nesting, or clear formatting. The syntax is simple and straight forward,
//Create an anchor tag
$anchor = new Tag("a", array("name"=>"anchor");
//Create a paragraph
$paragraph = Tag::Craft("p", "Lorem ipsum dolor sit amet, consectetur.");
//Create a container for them and add them;
$div = new Tag("p", "id='container'");
$div->add($anchor);
$div->add($paragraph);
echo $div;
Creates:
<div id="container">
<a name="anchor" />
<p>Lorem ipsum dolor sit amet, consectetur.</p>
</div>
This is all well and good, I can quickly create tags, fill them with content and other tags, and output them cleanly. However I cannot do things like, take existing html and parse it in. Or find a Tag using something like xPath.
As far as I can tell I have 2 options:
- Write xPath and parsing functionality into my Tag tool. Time consuming, annoying, and probably effort better spent elsewhere.
- Use DOM objects. Very sparse documentation and not fully baked in places. Especially since the production environment's PHP is a few subversions behind. Also this will be used for HTML not XML which could cause alot of errors and log spam.
Any thoughts on where I should go from here? Or experience using DOM to achieve this?