Thread: Writing an HTML Preprocessor

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    204

    Writing an HTML Preprocessor

    I'm trying to write an HTML preprocessor. What is the best way to go about this? Should I read the entire file into a character array first, and then process that? Should I read it into an array of strings instead?

    Basically I have an HTML file, like the one below.

    Code:
    <html>
    <title></title>
    <body>
    
    <h1>This is an HTML file.</h1> 
    
    #insert HelloWorld.html                 
    
    </body>
    </html>
    When I run the preprocessor on the above HTML code, the line that reads "#insert HelloWorld.html" is replaced by the contents of the file "HelloWorld.html."

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Depends on how complex your transformation is. If it's just preprocessor-like directives, streaming the file through a filter is sufficient, and much more memory-efficient than reading it whole.
    XSLT, on the other hand, is so complex that it must parse both the style sheet and the file it works on in full before being able to do anything.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Please Help - C code creates dynamic HTML
    By Christie2008 in forum C Programming
    Replies: 19
    Last Post: 04-02-2008, 07:36 PM
  2. Folding@Home Cboard team?
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 398
    Last Post: 10-11-2005, 08:44 AM
  3. Preprocessor Directives Problem
    By MipZhaP in forum C++ Programming
    Replies: 6
    Last Post: 02-18-2005, 01:53 PM
  4. help! fifo read problem
    By judoman in forum C Programming
    Replies: 1
    Last Post: 08-16-2004, 09:19 AM
  5. html form - writing ip to a hidden field
    By iain in forum A Brief History of Cprogramming.com
    Replies: 14
    Last Post: 11-16-2001, 03:29 AM