Re: XML: Better way to accomplish this?

2005-01-03 Thread flamesrock
Good idea! Thanks

Also, besides the document structure (I appreciate comments on that
too, of course,) do you think the code is efficient for xml? Any
special tricks you know of?

-thanks

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: XML: Better way to accomplish this?

2005-01-03 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, flamesrock
wrote:

> #
> #
> [...]
> #
> #
> [...]
> #
> #
> [...]
> #
> #

Don't you think it's better to use an attribute for the city nr.? 
Something like .  At least if you intent to write a DTD
or Schema this might be better.

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


XML: Better way to accomplish this?

2005-01-02 Thread flamesrock
Hi,
I'm working on creating an xml structure like the following, as
effiecienty and elegantly as possible using minidom preferably:

#
#
#
#0
#
#
#0
#
#
#0
#
#
#0
#
#
#
#
#
#
#
#
#
#0
#
#
#0
#
#
#0
#
#
#
#
#
#
#
#
#
#0
#
#
#0
#
#
#0
#
#
#
#
#
#
#
#
#
#0
#
#
#0
#
#
#0
#
#
#
#
#
(left out)

The following code accomplishes that, but being a newb to xml..I'm not
sure if this can be done a better (I'd like to stick with dom due to
the nature of this app):

(left textnode parts like mayor, cityname out to keep code concise for
now)
#from xml.dom.minidom import parseString
##create a new document
#scoreXML= parseString(u''.encode('UTF-8'))
#art = scoreXML.documentElement
#
##create a total population, cities and some city elements
#population = scoreXML.createElementNS(None,u'population')
#cities = scoreXML.createElementNS(None,u'cities')
#city1  = scoreXML.createElementNS(None,u'city1')
#city2  = scoreXML.createElementNS(None,u'city2')
#city3  = scoreXML.createElementNS(None,u'city3 and so on')
#
##add it under the region element
#art.appendChild(population)
#art.appendChild(cities)
#
## create a total element with a population number inside
## and do this for all RCI numbers
#population.appendChild(scoreXML.createElementNS(None,u'total'))
#total = scoreXML.createTextNode(u'0')
#population.firstChild.appendChild(total)
##will get RCI with seperate function
#RCI = [scoreXML.createTextNode(u'0'),
#  scoreXML.createTextNode(u'0'),
#  scoreXML.createTextNode(u'0')] #[r,c,i]
#for populationElement in [u'R',u'C',u'I']:
#
population.appendChild(scoreXML.createElementNS(None,populationElement))
#population.lastChild.appendChild(RCI[0])
#RCI.pop(0)
#
##add the elements underneath city
#allcities = [city1,city2,city3]
#for city in allcities:
#   cities.appendChild(city)
#
#   for cityattribute in [u'cityname',u'mayor',u'morelater']:
#   city.appendChild(scoreXML.createElementNS(None,cityattribute))
#
#   citypopulation = scoreXML.createElementNS(None,u'citypopulation')
#   city.appendChild(citypopulation)
#   #will get RCI with seperate function
#   RCI = [scoreXML.createTextNode(u'0'),
#scoreXML.createTextNode(u'0'),
#scoreXML.createTextNode(u'0')] #[r,c,i]
#
#   for populationElement in [u'R',u'C',u'I']:
#>>citypopulation.appendChild(scoreXML.createElementNS(None,populationElement))
#  citypopulation.lastChild.appendChild(RCI[0])
#  RCI.pop(0)
##write the result
#print scoreXML.toprettyxml()


Any ideas?

-thanks in advance

-- 
http://mail.python.org/mailman/listinfo/python-list