OOP PHP DOM Abstraction? Layer
Moderator: General Moderators
OOP PHP DOM Abstraction? Layer
Sorry for all the abbreviations... my question is... has anybody every tried to create a PHP library that would be basically an abstraction (is that the correct term) layer to the Document Object Model... so basically you would never write any html... you would create php objects for each html tag you need. So basically the same kind of concept as DOM nodes in javascript, but in php... does anybody see what I am getting at?
Umm... yea pretty much. Do you use that at all? I haven't had time to look it over completely, but I imagine this could be used to compose fully valid XHTML documents? This could be a pretty powerful set of objects if put in the right hands it seems like... I wonder how come I've never seen/heard of it before... 
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
No, I don't use it currently. Although I'm not really meddling in the display code right now.
I imagine it's not getting much use because, like with Javascript, people choose the shortcut route (inline text literals and innerHTML for example) or choose preformed templates or other functionality (XSLT for example.)
I would certainly prefer generating output via the DOM when the output is XML/HTML based, but my output isn't always so simple. Sometimes it's PDF based, XUL or even command line based. All can need some adjustments of how controls are integrated, so it's difficult in my case to justify using the DOM a lot.
I imagine it's not getting much use because, like with Javascript, people choose the shortcut route (inline text literals and innerHTML for example) or choose preformed templates or other functionality (XSLT for example.)
I would certainly prefer generating output via the DOM when the output is XML/HTML based, but my output isn't always so simple. Sometimes it's PDF based, XUL or even command line based. All can need some adjustments of how controls are integrated, so it's difficult in my case to justify using the DOM a lot.
To me it seems that this could easily be extended to dynamically create very richly featured and well written javascript/php documents that are guaranteed to validate. I am going to start messing around with it. I was considering writing a PHP interface to the Google Maps API, and I think this could really help me out. It seems perfect for this task.
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
Edit: You'd have a helluva time using the DOM to re-write javascript 
I've researched just this...
My conclusion is, using a DOM would be a fantastic way of doing it as you *could* output valid XHTML, etc...
The problem is, your starting to work backwards...if you read up on the history of temlate engines, you'll see what I mean...
HTML has it's power in being a self-driven GUI...meaning there is no programming required to get things to display...
PHP allows for quick adhock hacks and is why you often see PHP intermingled with HTML...but in theory they can both be used seperately...allowing for optimal seperation of presentation from logic...
Realistically of course, we need template logic...at least sometimes...so it's not perfect...
Working with a DOM does two counter evolutionary things:
1) Removes the need for a HTML hack and brings the UI burden back onto a programmer
2) Brings display back into the domain of "programming"
These two things are what HTML (although not originally designed to do) is basically doing to the world of application development...
So although the DOM is cool...yes I have plenty of experience in working with DOM's I know it's neat...I'm not sure it would make for a good replacement for template engines or hardcoding HTML...
A couple years back I discovered this very same thing...but in javascript...I used the DOM to re-write the crappy HTML IE output into nice xhtml (or what I thought was xhtml)...when other developers where using regex and nasty hacks to re-write the xhtml...
now it's common practice amongst most WYSIWYG editors...TInyMCE uses this aproach from what I can tell...
http://html2xhtml.richarea.com/
He does too
I've researched just this...
My conclusion is, using a DOM would be a fantastic way of doing it as you *could* output valid XHTML, etc...
The problem is, your starting to work backwards...if you read up on the history of temlate engines, you'll see what I mean...
HTML has it's power in being a self-driven GUI...meaning there is no programming required to get things to display...
PHP allows for quick adhock hacks and is why you often see PHP intermingled with HTML...but in theory they can both be used seperately...allowing for optimal seperation of presentation from logic...
Realistically of course, we need template logic...at least sometimes...so it's not perfect...
Working with a DOM does two counter evolutionary things:
1) Removes the need for a HTML hack and brings the UI burden back onto a programmer
2) Brings display back into the domain of "programming"
These two things are what HTML (although not originally designed to do) is basically doing to the world of application development...
So although the DOM is cool...yes I have plenty of experience in working with DOM's I know it's neat...I'm not sure it would make for a good replacement for template engines or hardcoding HTML...
A couple years back I discovered this very same thing...but in javascript...I used the DOM to re-write the crappy HTML IE output into nice xhtml (or what I thought was xhtml)...when other developers where using regex and nasty hacks to re-write the xhtml...
now it's common practice amongst most WYSIWYG editors...TInyMCE uses this aproach from what I can tell...
http://html2xhtml.richarea.com/
He does too
- daedalus__
- DevNet Resident
- Posts: 1925
- Joined: Thu Feb 09, 2006 4:52 pm
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
Not sure I see where your coming from...
You want to use the DOM to insert javascript, etc into the templates, by basically:
Instead of using regex and replacing placeholders???
Implement something and I'll comment then as I still don't clearly understand what it is your doing...
I love DOM though so keep the topic rolling if you want
You want to use the DOM to insert javascript, etc into the templates, by basically:
Code: Select all
getElementById('jscript').innerHTML = "
alert('THis is uber cool javascript?');
";Implement something and I'll comment then as I still don't clearly understand what it is your doing...
I love DOM though so keep the topic rolling if you want
I think we're talking about something like
Code: Select all
$doc = new DOMDocument('1.0', 'iso-8859-1');
$doc->appendChild($doc->createProcessingInstruction('DOCTYPE', [...]));
[...]
$eScript = $doc->createElement('script');
$eScript->setAttribute('type', 'text/javascript');
$eScript->appendChild($doc->createCDATASection($javascript));
[...]-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
I can kind of agree about this giving too much responsibility to the developer, but for an all-in-one type guy like myself it seems to make sense to create documents like this... and also, it looks like you can import in already created xhtml docs and it will convert them... so you could have somebody design a template, and then you take over from there, right?
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
Why not just code the site in XHTML? I am kind of confused at the point of this. All the sites I do now are in XHTML.The Ninja Space Goat wrote:Umm... yea pretty much. Do you use that at all? I haven't had time to look it over completely, but I imagine this could be used to compose fully valid XHTML documents? This could be a pretty powerful set of objects if put in the right hands it seems like... I wonder how come I've never seen/heard of it before...