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

14.17. The DocumentFragment class

A DocumentFragment object is like a free-floating Element: it can have any number of Element or other children.

xml4create.py
# - - - - -   c l a s s   D o c u m e n t F r a g m e n t   - - - - -

class DocumentFragment:
    """Represents part of an XML document.

      State/Invariants:
        .doc:   [ a Document object ]
        .node:
          [ a DOM DocumentFragment object whose .ownerDocument
            attribute contains a DOM Document instance ]
    """

The .doc attribute is a DOM Document instance we create strictly because we need its factory functions. No actual content will be added to this Document.

xml4create.py
# - - -   D o c u m e n t F r a g m e n t . _ _ i n i t _ _   - - -

    def __init__ ( self, nsMap=None ):
        """Constructor for DocumentFragment.
        """

        #-- 1 --
        # [ dom  :=  a DOMImplementation object ]
        dom  =  domlette.implementation

        #-- 2 --
        # [ doc        :=  a new, empty DOM Document object ]
        self.doc  =  Document('dummy', nsMap=nsMap)

        #-- 3 --
        # [ doc is a DOM Document object ->
        #     self.node  :=  a DOM DocumentFragment object ]
        self.node  =  self.doc.node.createDocumentFragment()