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

13.5. addText(): Adding text content to an element

This convenience function handles the special logic used to add text content to an ElementTree-style node. The problem is that if the node does not have any children, the new text is appended to the node's .text attribute, but if there are any children, the new text must be appended to the .tail attribute of the last child. Refer to Section 2, “How ElementTree represents XML” for a discussion of why this is necessary.

Here is the general calling sequence to add some text string s to an existing node:

addText(node, s)