Open a new element. Attributes can be given as keyword arguments, or as a string/string dictionary. The method returns an opaque identifier that can be passed to the :meth:`close` method, to close all open elements up to and including this one. Parameters
(self, tag, attrib=None, **extra)
| 134 | self.__data = [] |
| 135 | |
| 136 | def start(self, tag, attrib=None, **extra): |
| 137 | """ |
| 138 | Open a new element. Attributes can be given as keyword |
| 139 | arguments, or as a string/string dictionary. The method returns |
| 140 | an opaque identifier that can be passed to the :meth:`close` |
| 141 | method, to close all open elements up to and including this one. |
| 142 | |
| 143 | Parameters |
| 144 | ---------- |
| 145 | tag |
| 146 | Element tag. |
| 147 | attrib |
| 148 | Attribute dictionary. Alternatively, attributes can be given as |
| 149 | keyword arguments. |
| 150 | |
| 151 | Returns |
| 152 | ------- |
| 153 | An element identifier. |
| 154 | """ |
| 155 | if attrib is None: |
| 156 | attrib = {} |
| 157 | self.__flush() |
| 158 | tag = _escape_cdata(tag) |
| 159 | self.__data = [] |
| 160 | self.__tags.append(tag) |
| 161 | self.__write(self.__indentation[:len(self.__tags) - 1]) |
| 162 | self.__write(f"<{tag}") |
| 163 | for k, v in {**attrib, **extra}.items(): |
| 164 | if v: |
| 165 | k = _escape_cdata(k) |
| 166 | v = _quote_escape_attrib(v) |
| 167 | self.__write(f' {k}={v}') |
| 168 | self.__open = 1 |
| 169 | return len(self.__tags) - 1 |
| 170 | |
| 171 | def comment(self, comment): |
| 172 | """ |