所以我想稍微讨论文件,并决定深入研究XML标签。但是,我不知所措。我不知道从哪里开始,我看到的所有地方要么让我困惑,要么我遇到了问题。
现在我的字面意思是我的代码的骨干。我不确定如何与文件中的XML标签进行交互以写入信息并从中获取数据。
def XMLData(fileName):
#read file.
rFile = open(fileName, "r").read()
#make new file for summarizing data.
nFile = input("")
#write to new file.
wFile = open(nFile, "w")
#Stuff to write goes here.
#write to new file the data from read file.
wFile.write(readFile)
#close file.
wFile.close
例如,我有一组足球队的标签。
<team>
<name> Denver Broncos </name>
<players>
<player>
<jno> 50 </jno>
<fname> Zaire </fname>
<lname> Anderson </lname>
<height> 5-11 </height>
<weight> 220 </weight>
<age> 24 </age>
<position> ILB </position>
<school> Nebraska </school>
</player>
</players>
</team>
我想要完成的是将一些信息写入新文件,同时利用XML标签中的数据,如下所示:
There are {} players on the team. #number of <player> tags
Zaire Anderson, ILB, wears J50. He is 5 foot 11 inches tall, and weighs 220 pounds. He is 24 years old. He went to Nebraska. #Info on the <player>
有人能给我一个很好的资源,或者给我一些帮助让我走?我并没有要求任何人为我写任何代码,只是希望得到帮助,让我离开我的洞。