Oct-31-2016, 08:13 PM
Hi , I am trying to write data in xml > please look at my code and guide me to correct it .
Create an element named <drug> for each drug entry.
Make the name, dosage, units, and cost attributes of each drug. Note that the cost is the cost per pill rather than the cost mg.
Make the count the text for that drug element.
Name Dosage Units Cost Count
Asprin 100 mg 0.10 320
Asprin 200 mg 0.15 211
Digoxin 10 mL 1.22 19
Digoxin 20 mL 2.01 27
import xml.etree.ElementTree as xml
drugs = """<?xml version="1.0"?>
<drugs>
<drug1 Name="Aspirin" Dosage ="100" Units="mg" Cost= "0.10">
Count = 320
</start>
<drug1 Name="Aspirin" Dosage ="200" Units="mg" Cost= "0.15">
Count =211
</start>
<drug1 Name="Digoxin" Dosage ="10" Units="mL" Cost= "1.22">
Count =19
</start>
<drug1 Name="Digoxin" Dosage ="20" Units="mL" Cost= "2.01">
Count =27
</start>
</drugs>
"""
`Create an XML structure that describes a set of drugs and the possible dosages they might have based on the table below.Create an element named <drug> for each drug entry.
Make the name, dosage, units, and cost attributes of each drug. Note that the cost is the cost per pill rather than the cost mg.
Make the count the text for that drug element.
Name Dosage Units Cost Count
Asprin 100 mg 0.10 320
Asprin 200 mg 0.15 211
Digoxin 10 mL 1.22 19
Digoxin 20 mL 2.01 27
`import xml.etree.ElementTree as xml
drugs = """<?xml version="1.0"?>
<drugs>
<drug1 Name="Aspirin" Dosage ="100" Units="mg" Cost= "0.10">
Count = 320
</start>
<drug1 Name="Aspirin" Dosage ="200" Units="mg" Cost= "0.15">
Count =211
</start>
<drug1 Name="Digoxin" Dosage ="10" Units="mL" Cost= "1.22">
Count =19
</start>
<drug1 Name="Digoxin" Dosage ="20" Units="mL" Cost= "2.01">
Count =27
</start>
</drugs>
"""