Next / Previous / Contents / TCC Help System / NM Tech homepage

16. Test driver for a document fragment: crefrag

This script generates a small Web page without the enclosing html element. It demonstrates use of the DocumentFragment object, in particular the ability of such an object to have multiple children (unlike a Document), and to produce a file with no initial <?xml ...> processing instruction.

#!/usr/bin/env python
# crefrag: Fragment output testing for
# For documentation, see:

import xml4create as xc

frag = xc.DocumentFragment()

head = xc.Element ( frag, 'head' )
title = xc.Element ( head, 'title' )
xc.Text ( title, 'No title' )

body = xc.Element ( frag, 'body' )
h1 = xc.Element ( body, 'h1' )
xc.Text ( h1, 'No body either' )


Here's the output of this script:

  <title>No title</title>
  <h1>No body either</h1>