Edgewall Software

Changes between Version 4 and Version 5 of GenshiFaq


Ignore:
Timestamp:
Jul 7, 2006, 6:30:59 PM (18 years ago)
Author:
cmlenz
Comment:

Added "Why XML-based" Q/A

Legend:

Unmodified
Added
Removed
Modified
  • GenshiFaq

    v4 v5  
    11= Frequently Asked Questions =
    2 [[PageOutline(2-3)]]
    32
    43Here you can find answers to frequently asked questions about Markup.
     4
     5[[PageOutline(2-3, Overview, inline)]]
    56
    67== What is Markup? ==
     
    1920See his article [http://naeblis.cx/rtomayko/2004/11/30/pythonic-xml-based-templating-language “In search of a Pythonic, XML-based Templating Language”] for the details.
    2021
     22== Why XML-based? ==
     23
     24Most template engines for web applications are character-stream based: they know nothing about the format of the text that is being generated. They simply substitute variable expressions, and provide some kind of directives looping, conditionals, etc. Thus they can be used to generate any kind of textual output, be it HTML, plain text emails, program code, or really anything else.
     25
     26However, 99% of the templates used by web applications generate some kind of XML/HTML-based markup. So we believe that web applications can benefit from a template engine that “knows what it's doing” when it comes to markup. You don't need to worry about generating output that is not well-formed, nor do you need to worry about accidentially not escaping some data, thereby greatly reducing the risk for introducing [http://de.wikipedia.org/wiki/Cross_Site_Scripting XSS] attack vectors. Furthermore, your templates look a lot more like the targetted output format: an HTML template looks like HTML, a template for an RSS feed looks like RSS. Directives in text-based template languages often result in rather messy templates, or produce excessive amounts of unnecessary white space.
     27
     28In addition, text-based templates don't even work all that well for many text formats. Imagine you want to generate a plain text email or an [http://www.ietf.org/rfc/rfc2445.txt iCalendar] file. How do you deal with important concerns such as line-wrapping and white-space in your templates? You may be better off using a specialized formatter.
     29
    2130== So then why not just use Kid? ==
    2231
     
    2938== What are the main differences between Kid and Markup? ==
    3039
    31 Markup executes templates directly, there's no code generation phase. Expressions are evaluated in a more forgiving way by walking the AST. Template variables are stored on a stack, which means that some variable set in a loop deep in the template don't leak into the rest of the template. And even though Markup doesn't generate Python code for templates, it generally performs better than Kid (up to 2x in our tests).
     40Markup executes templates directly, there's no code generation phase. Expressions are evaluated in a more forgiving way by walking the AST. Template variables are stored on a stack, which means that some variable set in a loop deep in the template won't leak into the rest of the template. And even though Markup doesn't generate Python code for templates, it generally performs better than Kid (up to 2x in our tests).
    3241
    3342Markup does not depend on !ElementTree. It uses Expat for parsing XML, and is based on streaming slightly abstracted parse events through the processing pipeline. It uses XInclude (instead of Kids' `py:extends`) to allow template authors to factor out common bits. For match templates, it uses XPath expressions instead of the !ElementTree API.