473,659 Members | 3,605 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XML: Better way to accomplish this?

Hi,
I'm working on creating an xml structure like the following, as
effiecienty and elegantly as possible using minidom preferably:

#<region>
# <population>
# <total>
# 0
# </total>
# <R>
# 0
# </R>
# <C>
# 0
# </C>
# <I>
# 0
# </I>
# </population>
# <cities>
# <city1>
# <cityname/>
# <mayor/>
# <morelater/>
# <citypopulation >
# <R>
# 0
# </R>
# <C>
# 0
# </C>
# <I>
# 0
# </I>
# </citypopulation>
# </city1>
# <city2>
# <cityname/>
# <mayor/>
# <morelater/>
# <citypopulation >
# <R>
# 0
# </R>
# <C>
# 0
# </C>
# <I>
# 0
# </I>
# </citypopulation>
# </city2>
# <city3 and so on>
# <cityname/>
# <mayor/>
# <morelater/>
# <citypopulation >
# <R>
# 0
# </R>
# <C>
# 0
# </C>
# <I>
# 0
# </I>
# </citypopulation>
# </city3 and so on>
# </cities>
#</region>
(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'< region/>'.encode('UT F-8'))
# art = scoreXML.docume ntElement
#
# #create a total population, cities and some city elements
# population = scoreXML.create ElementNS(None, u'population')
# cities = scoreXML.create ElementNS(None, u'cities')
# city1 = scoreXML.create ElementNS(None, u'city1')
# city2 = scoreXML.create ElementNS(None, u'city2')
# city3 = scoreXML.create ElementNS(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.appe ndChild(scoreXM L.createElement NS(None,u'total '))
# total = scoreXML.create TextNode(u'0')
# population.firs tChild.appendCh ild(total)
# #will get RCI with seperate function
# RCI = [scoreXML.create TextNode(u'0'),
# scoreXML.create TextNode(u'0'),
# scoreXML.create TextNode(u'0')] #[r,c,i]
# for populationEleme nt in [u'R',u'C',u'I']:
#
population.appe ndChild(scoreXM L.createElement NS(None,populat ionElement))
# population.last Child.appendChi ld(RCI[0])
# RCI.pop(0)
#
# #add the elements underneath city
# allcities = [city1,city2,cit y3]
# for city in allcities:
# cities.appendCh ild(city)
#
# for cityattribute in [u'cityname',u'm ayor',u'morelat er']:
# city.appendChil d(scoreXML.crea teElementNS(Non e,cityattribute ))
#
# citypopulation = scoreXML.create ElementNS(None, u'citypopulatio n')
# city.appendChil d(citypopulatio n)
# #will get RCI with seperate function
# RCI = [scoreXML.create TextNode(u'0'),
# scoreXML.create TextNode(u'0'),
# scoreXML.create TextNode(u'0')] #[r,c,i]
#
# for populationEleme nt in [u'R',u'C',u'I']:
#>>>>>>>>>>city population.appe ndChild(scoreXM L.createElement NS(None,populat ionElement))
# citypopulation. lastChild.appen dChild(RCI[0])
# RCI.pop(0)
# #write the result
# print scoreXML.topret tyxml()
Any ideas?

-thanks in advance

Jul 18 '05 #1
2 1278
In <11************ **********@c13g 2000cwb.googleg roups.com>, flamesrock
wrote:
# <cities>
# <city1>
[...]
# </city1>
# <city2>
[...]
# </city2>
# <city3 and so on>
[...]
# </city3 and so on>
# </cities>


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

Ciao,
Marc 'BlackJack' Rintsch
Jul 18 '05 #2
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

Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2100
by: Gene Ellis | last post by:
Our sys op won't/can't install the server side XSLT libraries, to allow us perform server-side translations on our webserver It is a Linux machine. Is it possible to put the XML and XSL files on a different machine and have the translation take place there and then have the results given to the webserver and then it gets served out to the user? How would I accomplish something like that? Php? 3rd party software? Please let me know. Thank...
3
2053
by: Tim Dempsey | last post by:
Folks, I need some advice. I hpoe some of you can advise me. Our church's weekly bulletin has been published on paper for years. It is created in MS Word and sent to the publishing company. Now I need to publish the same information on our new web site. But I don't want to put an image of the paper bulletin on the web site. I want it to look natural there, as if it were produced with god web design principles.
1
1437
by: milkyway | last post by:
Hello, I am considering the following in order to accomplish my task. An application has to be created that runs from a regular computer as well as from a WAP-enabled device. When the user is presented with information to enter on a screen and then presses the "Continue" button, it would then call a .jsp. The .jsp would create a .xml on the fly that would be passed to an XSLT
8
1262
by: Wayne Wengert | last post by:
I am trying to build a VB.NET Windows application in which I want to create an XML file from data collected from the user and stored in arrays. I am looking for any pointers to information on how to accomplish this. TIA Wayne
6
13492
by: Thomas Polan | last post by:
Sorry if this has been posted before... I am receiving XML messages over a TCP client. Messages vary in size and sometimes can arrive in groups. Thus, I am not guaranteed to receive a full message in a single read from my socket. I am loading each message into an XmlDocument after it arrives. I need a way to make sure I have a complete XML message before I load it into an XmlDocument or it will throw an exception. I am currently...
3
1826
by: Kanchana D S | last post by:
Hi, I am trying to design the schema for an XML file. The approach that I am planning to follow is to have 2 XSD files, each containing some relevant information about the elements in the instance document and then planning to automatically generate the XML file from these 2 schema files using the XMLSpy tool.
4
3595
by: Scott | last post by:
I think I have confused myself with reading all the articles on XML so I am hoping someone can point me in the direction for each piece of the project I am trying to develop. 1st Step - I need to have a Web app that will create an XML stream and send it to a Web Services on our Web server 2nd Step - Need to create a Web Service that will accept the XML Stream - then "process" it, then send an XML Stream back
0
1251
by: wyattroerb | last post by:
Hi, like a lot of other newbies in xml i suffer from the various ways you can take for xml data processing in python. Here are my two major problems: Problem number one: A application written in python remote controls (demands actions) a HIL (Hardware in the loop) test stand and evaluate its actions (system reactions on the demand ) afterwards. The application puts all the results in a word protocol during the test. Now i would like to...
2
2030
by: -D- | last post by:
I'm taking my first stab at using xml, so please bear with my novice questions and understanding of xml. I'm trying to create an xml file that holds all my website navigation. If I understand correctly, I can use xslt to create different menus from the xml file. What I'm trying to accomplish is to create a top menu bar, left navigation menu bar and sub header navigation bar. Then place the transformed xslt menus into user controls...
0
8428
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8337
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8531
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8628
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7359
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
2754
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1978
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1739
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.