N.B. SCHOOL ASSIGNMENT Re: [Tutor] Re: txt to xml using dom

Magnus Lyckå magnus@thinkware.se
Sat Jun 14 16:52:01 2003


At 09:45 2003-06-14 +1200, Tom Brownlee wrote:
>Im a tertiary student from new zealand doing python programming at the 
>moment. we have an assignment to do that involves using dom (minidom). if 
>possible can anybody help me.

We can't do your assignments as I think you understand.
We're here to help people, to encourage the use of Python,
and to learn things. We're not here to sabotage some
educational system.

If you feel that the assignment isn't reasonable, you have to
bring that up with the school.

>i have to take a course outline in .txt format and pass it through a 
>python program that outputs the .txt document into xml tags etc. that is 
>to say...txt document in = xml out (in a .txt file)

It seems to me that the difficult part here is to parse the
text file, which is not XML to begin with, so DOM won't be
of any help here, only to create the XML document once you
have built the structure. You have to figure out how to do
this on your own. DOM is really overkill for such a simple
XML format. Perhaps you should start by thinking about how
to solve it without minidom, just using plain Python?

Actaully, considering that you seem to be rather lost: Start
with a program that just prints every line in the file, line
by line, just the way they are. Then see if you can make it
detect whether lines are headings, and just print out some
arbitrary message about that. Once you can do that, you might
want to involve the DOM.

Always try to solve your problems gradually...

>if possible can i have the corrected code.

Really!

I certainly don't expect anyone here will aid you in cheating
in your class. Don't you have any instructors at school who
you can ask for help? Perhaps they can give you a nudge in the
right direction?

I also hope the teachers are smart enough to search the
internet for material they hand out in assignments, so you
should worry if you did get help. (I don't know if completely
futile attempts to cheat can lead to reprimands in New Zealand.
At my Alma Mater, you would get a three month suspension from
your studies if you were found cheating. If it was a first
offense.)

>this may seem demanding and lazy on my part but i have spent many hours on 
>this problem and utterly frustrated that it doesnt work, and as a beginner 
>im losing faith in python altogether :(

He he. As long as you don't loose your faith in yourself. Are
you suggesting that this would have been much easier in another
language, or did you expect Python to create some miracle for you?

Python will make programming much easier than most other programming
languages, but it won't solve your basic problems for you. You must
still understand what you want to achieve, and be capable of
expressing that in a clear way.

I have deliberately not looked at your code, but try to take a little
step at a time. You can't just write a program and expect it to work.
With python, you have great support to work interactively with your
file and try to extract data in various ways. Play with the interpreter.
Try to get out the first heading to begin with. When that works, try
to get all first level headings...and so on.


--
Magnus Lycka (It's really Lyckå), magnus@thinkware.se
Thinkware AB, Sweden, www.thinkware.se
I code Python ~ The Agile Programming Language