football England baseball Ameri" /> football England baseball Ameri" /> football England baseball Ameri"/>

I want to append an element to xml’s lead

25 Views Asked by At

sport.xml is

<sports>
  <sport order="001">
    <name>football</name>
    <orgin>England</orgin>
  </sport>
  <sport order="002">
    <name>baseball</name>
    <orgin>America</orgin>
  </sport>
</sports>

I want to append an element

<?xml version="1.0" encoding="UTF-8" ?>

to xml’s lead

As a result,I want to make a xml like

<?xml version="1.0" encoding="UTF-8" ?>
<sports>
  <sport order="001">
    <name>football</name>
    <orgin>England</orgin>
  </sport>
  <sport order="002">
    <name>baseball</name>
    <orgin>America</orgin>
  </sport>
</sports>

I wrote codes,

import xml.etree.ElementTree as ET 

tree = ET.parse('c:\\pg\sport.xml') 
root = tree.getroot()

but I cannot do it. How should I write codes to append the element to xml’s lead?

0

There are 0 best solutions below