Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 45945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T15:53:20+00:00 2026-05-10T15:53:20+00:00

I recently discovered the genshi.builder module. It reminds me of Divmod Nevow’s Stan module.

  • 0

I recently discovered the genshi.builder module. It reminds me of Divmod Nevow’s Stan module. How would one use genshi.builder.tag to build an HTML document with a particular doctype? Or is this even a good thing to do? If not, what is the right way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T15:53:20+00:00Added an answer on May 10, 2026 at 3:53 pm

    It’s not possible to build an entire page using just genshi.builder.tag — you would need to perform some surgery on the resulting stream to insert the doctype. Besides, the resulting code would look horrific. The recommended way to use Genshi is to use a separate template file, generate a stream from it, and then render that stream to the output type you want.

    genshi.builder.tag is mostly useful for when you need to generate simple markup from within Python, such as when you’re building a form or doing some sort of logic-heavy modification of the output.

    See documentation for:

    • Creating and using templates
    • The XML-based template language
    • genshi.builder API docs

    If you really want to generate a full document using only builder.tag, this (completely untested) code could be a good starting point:

    from itertools import chain from genshi.core import DOCTYPE, Stream from genshi.output import DocType from genshi.builder import tag as t  # Build the page using `genshi.builder.tag` page = t.html (t.head (t.title ('Hello world!')), t.body (t.div ('Body text')))  # Convert the page element into a stream stream = page.generate ()  # Chain the page stream with a stream containing only an HTML4 doctype declaration stream = Stream (chain ([(DOCTYPE, DocType.get ('html4'), None)], stream))  # Convert the stream to text using the 'html' renderer (could also be xml, xhtml, text, etc) text = stream.render ('html') 

    The resulting page will have no whitespace in it — it’ll look normal, but you’ll have a hard time reading the source code because it will be entirely on one line. Implementing appropriate filters to add whitespace is left as an exercise to the reader.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 58k
  • Answers 58k
  • Best Answers 0
  • User 1

Related Questions

No related questions found

  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer try this: def initialize(): global VAR print('Content-type: text/html\n\n') print(VAR) VAR… May 11, 2026 at 8:54 am
  • added an answer Let me google that for you :) EDIT : Add… May 11, 2026 at 8:54 am
  • added an answer Found a XSLT in the RSS toolkit for ASP.NET on… May 11, 2026 at 8:54 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.