473,402 Members | 2,072 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

trying to use sax for a very basic first xml parser

Hi,

I need to parse xml files for the Blender Game Engine. ATM I am trying
to get this script running in the BGE. This is my first script and I
dont have much experience programming...

import xml.sax

class PnmlHandler(xml.sax.ContentHandler):
def __init__(self):
self.inPlace=0

def startElement(self, name, attrs):
if name != "place": return
if attrs.getLength()==0: return

print 'Starting element:', name
print "attrs:", attrs.keys()
id = attrs.get("id", None)
print "id:", id

if name == "place":
self.inPlace=1

def endElement(self, name):
if name == "place":
self.inPlace=0

parser = xml.sax.make_parser()
parser.setContentHandler(PnmlHandler())
parser.parse(open("bpm.pnml","r"))

this works in the IDLE ide. Output:

Starting element: place
attrs: [u'id']
id: p9723441
Starting element: place
attrs: [u'id']
id: p26811937
Starting element: place
attrs: [u'id']
id: p24278422[/code]

but when I copy the script into blender and run it I get:

Expand|Select|Wrap|Line Numbers
  1. Compiled with Python version 2.5.
  2. Checking for installed Python... got it!
  3. Traceback (most recent call last):
  4. File "Text", line 27, in <module>
  5. File "H:\Python25\lib\xml\sax\__init__.py", line 93, in make_parser
  6. raise SAXReaderNotAvailable("No parsers found", None)
  7. xml.sax._exceptions.SAXReaderNotAvailable: No parsers found
Its probably a stupid question but thanks anyway!
Jul 14 '08 #1
4 1690
Hello,
but when I copy the script into blender and run it I get:

Expand|Select|Wrap|Line Numbers
  1. Compiled with Python version 2.5.
  2. Checking for installed Python... got it!
  3. Traceback (most recent call last):
  4. * File "Text", line 27, in <module>
  5. * File "H:\Python25\lib\xml\sax\__init__.py", line 93, in make_parser
  6. * * raise SAXReaderNotAvailable("No parsers found", None)
  7. xml.sax._exceptions.SAXReaderNotAvailable: No parsers found
Python is using an external library for SAX (expat IIRC).
I *guess* the Python that comes with Blender don't have this library.
Its probably a stupid question but thanks anyway!
He who asks is a fool for five minutes, but he who does not ask
remains a fool forever.
- Chinese Proverb

HTH,
--
Miki <mi*********@gmail.com>
http://pythonwise.blogspot.com
Jul 14 '08 #2
On Jul 14, 8:14*pm, Miki <miki.teb...@gmail.comwrote:

Python is using an external library for SAX (expat IIRC).
I *guess* the Python that comes with Blender don't have this library.
I don't know... I didnt install any external libraries for sax. I
think python comes with a standard sax library.
And before I had python installed Blender said at startup:
"Compiled with Python version 2.5.
Checking for installed Python... No installed Python found.
Some scripts will not run. Continuing happily"

After installing Python 2.5.2 it now says:
"Compiled with Python version 2.5.
Checking for installed Python... got it!"
So I think it is using the installed Python.

Could it be that I have to install the same python version Blender was
compiled with?
Jul 14 '08 #3
Hello,
Could it be that I have to install the same python version Blender was
compiled with?
I have no idea.

May I suggest you ask in the blender list?

HTH,
--
Miki <mi*********@gmail.com>
http://pythonwise.blogspot.com

Jul 15 '08 #4
>
May I suggest you ask in the blender list?
Will do that and report back. Thank you!

Manuel
Jul 15 '08 #5

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

Similar topics

19
by: Leif K-Brooks | last post by:
Has anyone ever tried implementing a simple unstructured BASIC dialect in Python? I'm getting interested in language implementation, and looking at a reasonably simple example like that could be...
1
by: Larry | last post by:
I am a C++/Java programmer trying to get going with some simpe xml transformations at work here. I bought the O'Reilly book Learning xlst for kicks. Someone at work sent me this xml shown below,...
9
by: Tom | last post by:
Hey all, I've been planning to get myself started with DocBook for quite some time now, so when I unexpectedly encountered a task for which DocBook might actually be very useful, I thought I'd...
59
by: Philipp Lenssen | last post by:
I've tested some of the new Nokia 6600 functionality. It ships with WAP2 and XHTML Support (it says). What it does is check the Doctype -- if it's not the XHTML Mobile Profile Doctype, but a...
1
by: Ale K. | last post by:
i just reinstalled everything on my machine... i created a web project and when trying to run it i got the following.... What is it , how to fix it?? Thanks Error Server Error in '/Tester'...
25
by: Neo Geshel | last post by:
This works: <form> <asp:TextBox id="name" /> <%= name.ClientID %> </form> But this DOES NOT work: <form>
4
by: News | last post by:
Hi Everyone, The attached code creates client connections to websphere queue managers and then processes an inquiry against them. The program functions when it gets options from the command...
25
by: samjnaa | last post by:
Please check for sanity and approve for posting at python-dev. In Visual Basic there is the keyword "with" which allows an object- name to be declared as governing the following statements. For...
3
by: Bint | last post by:
Hi, I'm trying to parse an xml file into an array tree. From the PHP site in the comments, I got this code. But it doesn't work for me. It's saying that the passed variable is not an array or...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.