Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ Python ➜ Parsing XML file to strings?

Parsing XML file to strings?

It is now over 60 days since the last post. This thread is closed.     Refresh page


Pages: 1  2 

Posted by Rakon   USA  (123 posts)  Bio
Date Reply #15 on Wed 08 Nov 2006 11:41 AM (UTC)
Message
Sure:

def trig():
	filename = eg.fileopenbox(msg=None, title='Open file...', argInitialFile=sys.path[6]+'\example.txt')

	file = open(filename)
	mydom = parse(file)



	trigs = mydom.getElementsByTagName('trigger')

	for trig in trigs:
		match = trig.getAttribute('match')
		regex = trig.getAttribute('regexp')
		send = trig.getElementsByTagName('send')
		send = send[0].toprettyxml()
		send = str(send).replace("	","",1)
		send = send.strip("<send>\n")
		send = send.strip("</send>\n")

		newline = "Match is: \n" + match "Send is: " + str(send)
		Write.write(newline)
	file.close()


Its called by a menu function in Tk, as thats the base of the program, a GUI.

menubar = Menu(Root)
File = Menu(menubar, tearoff=1)
File.add_command(label = "Open file...",command=open_file)
File.add_command(label="Convert XML", command=trig)
menubar.add_cascade(label="File", menu=File)


The 'file' is a local variable, and as stated if the function is in a py file by itself, but not as a function, as the actual program itself, the conversion works. Inside the function call, for some reason it doesn't.

Ked:
Email me at <penquincoder@gmail> for the entire program.

Yes, I am a criminal.
My crime is that of curiosity.
My crime is that of judging people by what they say and think, not what they look like.
My crime is that of outsmarting you, something that you will never forgive me for.
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


63,962 views.

This is page 2, subject is 2 pages long:  [Previous page]  1  2 

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.