我想构建以下XML元素(以便自定义图号格式):
<figcaption>
<span class="fignum">Figura 1.2</span> - Description of figure.
</figcaption>
但我不知道如何指定文本的位置。实际上,如果我在创建文本之前创建子元素
^{pr2}$我得到了一个不期望的结果(文本位于子元素之前):
<figcaption>
- Description of figure.<span class="fignum">Figure 1.2</span>
</figcaption>
如何指定文本相对于子元素的位置?在
您需要使用
span
元素的tail
属性:使用ElementTree,元素在元素内部有一个
text
,元素后面和外部有一个tail
。在对于多个子元素,父元素的
text
是第一个子元素之前的文本,元素中的所有其他文本都将分配给子元素tail
。在这个问题的另一个答案中的一些例子已被删除:
^{pr2}$相关问题 更多 >
编程相关推荐