0

i've been playing around with python for some time now, and i decided to take vegaseat's advice to make a project of mine own.

the project consist of transforming an access database to xml, and then from xml generate some html files.
i exported one table, made some basic modifications on the xml with some small python scripts and now i've hit a wall.

basicaly i have one main table in which i have my main data and keys to other tables containing other relevant data.
after exporting my main table to xml i have in some tags only keys to other tables. and now i want to change those keys to meaningful data.
for instance: after exporting, i have a line like this: <tagZ>1</tagZ>, and i want to change it to be just an opening tag for something else; <tagQ attr1="xx" attr2="yy">.
the data which must be written in attr1 and attr2 depends upon the number (in this case number 1) inside the tag (tagZ).

2
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by dcleaner
0

An interesting project, it will force you to learn three languages (Python, HTML and XML) all at the same time. Python has quite a number of XML related modules. Your project might be more a string handling project though.

0

i already know html very well, and xml more or less. but putting all this together represents a challenge.
i' ve written a code to change my xml a bit... it's a mixture from several books, and who knows how many more resources :icon_redface:

# -*- coding: utf-8 -*-

filePath='D:\\xxx.xml'
outFile=filePath+'.new'

findreplace = [(u'<tag1>', u'\n<tag2>'),]

inF = open(filePath,'rb')
s=unicode(inF.read(),'utf-8')
inF.close()

for i in findreplace:
    outtext=s.replace(i[0],i[1])
    s=outtext

outF = open(outFile,'wb')
outF.write(outtext.encode('utf-8'))
outF.close()

the code only changes the specified string with another specified string.
that was ok for some changes, but not for more complex with should be taken care of with a loop of some sort. i know how the algorithm should look like, i just don't know it to write it down into a working code.

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.