LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 09-14-2004, 05:13 PM   #1
Travis86
Member
 
Registered: Dec 2002
Location: The land of GMT -6
Distribution: OS X, PS2 Linux, Ubuntu, IRIX 6.5
Posts: 399

Rep: Reputation: 31
Python XML won't work.


I am trying to get pyXML to work and am having no luck. I could tell that it was installed but not working, so I tried to install it again. This didn't do anything. Also, I am doing this on OS X.

I have made two programs by more or less copying from Python and XML (the O'Reilly book), but they don't work. And I have tried a program from http://www.rexx.com/~dkuhlman/pyxmlfaq.html, but that didn't work either. Hopefully someone will be able to figure out what is going on.

Code:
import xml.dom.pulldom
from xml.dom.pulldom import parse

xmlhandle = open("example.xml")
xmlfile = parse(xmlhandle)

print xmlfile
print xmlfile.firstChild
Gives the message:

Code:
<xml.dom.pulldom.DOMEventStream instance at 0x4ae648>
Traceback (most recent call last):
  File "xmltest.py", line 9, in ?
    print xmlfile.firstChild
AttributeError: DOMEventStream instance has no attribute 'firstChild'
This:
Code:
import xml.dom.minidom

print xml.dom.minidom.parseString("<pete>re</pete>")
print xml.dom.minidom.parse(open("example.xml"))
Gives the message:
Code:
Traceback (most recent call last):
  File "xmltest.py", line 4, in ?
    print xml.dom.minidom.parse(open("example.xml"))
  File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-packages/_xmlplus/dom/minidom.py", line 1908, in parse
    return expatbuilder.parse(file)
  File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-packages/_xmlplus/dom/expatbuilder.py", line 928, in parse
    result = builder.parseFile(file)
  File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-packages/_xmlplus/dom/expatbuilder.py", line 207, in parseFile
    parser.Parse(buffer, 0)
  File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-packages/_xmlplus/dom/expatbuilder.py", line 437, in element_decl_handler
    assert info._model is None
AssertionError
The program from http://www.rexx.com/~dkuhlman/pyxmlfaq.html, which I am just running because it's supposed to work is:
Code:
import sys
from xml.dom import minidom, Node

def showNode(node):
    if node.nodeType == Node.ELEMENT_NODE:
        print 'Element name: %s' % node.nodeName
        for (name, value) in node.attributes.items():
            print '    Attr -- Name: %s  Value: %s' % (name, value)
        if node.attributes.get('ID') is not None:
            print '    ID: %s' % node.attributes.get('ID').value

def main():
    root = minidom.parse(sys.argv[1])
    node = root.firstChild
    showNode(node)
    for child in node.childNodes:
        showNode(child)

if __name__ == '__main__':
    main()
When run with xmltest2.py example.xml gives the message:
Code:
File "xmltest2.py", line 20, in ?
    main()
  File "xmltest2.py", line 13, in main
    root = minidom.parse(sys.argv[1])
  File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-packages/_xmlplus/dom/minidom.py", line 1908, in parse
    return expatbuilder.parse(file)
  File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-packages/_xmlplus/dom/expatbuilder.py", line 924, in parse
    result = builder.parseFile(fp)
  File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-packages/_xmlplus/dom/expatbuilder.py", line 207, in parseFile
    parser.Parse(buffer, 0)
  File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-packages/_xmlplus/dom/expatbuilder.py", line 437, in element_decl_handler
    assert info._model is None
AssertionError
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Python doesn't work zirtik Programming 9 10-17-2005 05:28 AM
getting wxPython to work with python servnov Linux - Newbie 0 01-09-2005 11:48 AM
XML database with python? (I don't understand the circular logic) flamesrock Programming 10 12-23-2004 08:31 PM
python doesn´t work little_ball Linux - Newbie 4 12-04-2004 09:09 AM
Consuming .Net XML Web Services using Python coolman0stress Programming 0 06-22-2004 10:54 PM


All times are GMT -5. The time now is 09:28 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration