s9e/sweetdom
SweetDOM is a lightweight PHP library for fast DOM parsing and manipulation. It offers a simple, jQuery-like API to find, traverse, and edit HTML/XML documents, making common scraping and transformation tasks easier without heavy dependencies.
libxslt).dompdf, symfony/dom).DOMDocument (Sweetdom wraps this, so no direct conflict but redundant if Laravel’s API suffices).DOMDocument for critical paths.DOMDocument or symfony/dom fulfill needs with less risk?laravel-notification-channels).dompdf or barryvdh/laravel-dompdf).DOMDocument.DocumentTransformer facade wrapping Sweetdom.$this->app->bind(DOMTransformer::class, function ($app) {
return new SweetdomTransformer();
});
DOMDocument for isolated tests.composer require s9e/sweetdom.use S9e\Sweetdom\Sweetdom;
$dom = Sweetdom::loadHTML('<div>Hello</div>');
$dom->find('div')->setText('World'); // Example transformation
memory_limit or chunk processing).Sweetdom::debug() or Laravel’s dd() for DOM inspection.memory_limit for large documents (e.g., 1G for XML >1MB).find() results for repeated operations).$cacheKey = 'email_template_'.$user->id;
$html = Cache::remember($cacheKey, now()->addHours(1), function () use ($dom) {
return $dom->saveHTML();
});
| Failure Scenario | Mitigation | Detection |
|---|---|---|
| DOM Parsing Errors | Validate input XML/HTML with a schema (e.g., DOMDocument::schemaValidate). |
Try-catch blocks + Laravel logs. |
| Memory Exhaustion | Implement chunked processing or increase memory_limit. |
PHP out_of_memory errors. |
| XPath Injection | Sanitize dynamic XPath queries (e.g., whitelist allowed functions). | Input validation layer. |
| Package Abandonment | Fork the repo or migrate to symfony/dom if Sweetdom is no longer maintained. |
Monitor GitHub activity. |
| Performance Degradation | Profile with Xdebug; optimize queries or switch to native DOMDocument. |
New Relic/Laravel Debugbar. |
How can I help you explore Laravel packages today?