Python & XML
Paul Prescod
paulp at ActiveState.com
Tue Feb 13 13:44:11 EST 2001
Chris Richard Adams wrote:
>
> Hi all..
>
>
>
> I have a tab seperated file that I would like to parse and store in XML
>
> format.
>
> file example:
>
> line1: 12:00:00 bob nassl.pdf 123.123.123.123
>
> would like to create an xml file from this text file in the form
>
> <upload>
>
> <time>12:00:00</time>
>
> <user>bob</user>
>
> <file>nassl.pdf</file>
>
> <ip>123.123.123.123</ip>
>
> </upload>
I would suggest something like this:
time, name, file, ip = line.split("\t")
print """
<upload>
<time>%s</time>
<user>%s</user>
<file>%s</file>
<ip>%s</ip>
</upload>""" % (date, name, file, ip)
I would discourage you from spending much effort looking for
XML-specific ways to do things that you probably already know how to do.
Reading an XML file is hard and should usually be done through a
specialized module. Writing XML is easy so you often don't need a
module.
Paul Prescod
More information about the Python-list
mailing list