SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Guru momos's Avatar
    Join Date
    Apr 2004
    Location
    Belgium
    Posts
    920
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    When do you use the DOM?

    To put together html that you send to a browser you can easily just paste together a few strings, this is actually what I've been doing for a long time with only a few exceptions. But if we really want to do it the clean way we should use the Document Object Model, this way all our tags are closed for sure and we can easily attach something in the middle of an already existing piece. While in theory this sounds perfect, I've almost never seen any code using it. So when and why are you guys using or not using the DOM?

  2. #2
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Using DOM to create HTML output has a big drawback -- a very difficult (if at all) template implementation, unless it's pure CSS. That's why most of the time you will see pre-made HTML documents used as templates.

    But DOM does not limit you to HTML documents, you can use it to parse XML documents, or build them. However, SimpleXML is easier and more powerful to use, so you're better off with that most likely.

    Where DOM comes really handy, though, is for building spider-like programs. Combined with HTML Tidy it can do wonders.
    Saul

  3. #3
    SitePoint Guru momos's Avatar
    Join Date
    Apr 2004
    Location
    Belgium
    Posts
    920
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The only moments I use it is for generating feeds.
    But I'm planning to rewrite my template-engine was thinking of using the DOM for that, although the benchmark-tests I wrote for my first attempts weren't very promissing.

  4. #4
    SitePoint Wizard Hammer65's Avatar
    Join Date
    Nov 2004
    Location
    Lincoln Nebraska
    Posts
    1,161
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That isn't surprising. DOM manipulations are pretty verbose.

    The DOM is great for changing an existing document, but writing a whole one from scratch is going to be slow, and doesn't hold any real advantages that I can think of.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •