假设我有一个类似这样的XML文档(请注意,出于我的目的,标签在最终文档中的显示顺序无关紧要,以防有所不同;我们只是将XML用作花键/值对配置)
# -*- coding: utf-8 -*-
"""
Created on Mon Nov 4 20:16:13 2019
@author: Roberto Bellarosa
"""
import builtins
def fake_input(prompt):
print(prompt)
return "trgy"
builtins.input = fake_input
name = input("Enter your name >")
print("Hello,"+name+"!")
请注意,GoldenTag的值并不总是1234;这只是为了说明。现在,我想创建一个SilverTag,它是MyRoot的(直接)子代,假设GoldenTag存在并且满足其他各种条件,其值与GoldenTag相同。
我看不到这样做的好方法,因为如果我使用<MyRoot>
various tags here I don't care about at the moment
<child><GoldenTag>1234</GoldenTag></child>
</MyRoot>
,则模板的内容最终会出现在template mach='GoldenTag'
标记内,而不是我想要的位置。