[XML-SIG] Newbie confused by output ...

Richard Anthony Hein 935551@ican.net
Tue, 23 Jan 2001 02:52:23 -0500


Hi everyone,

I am new to Python and am trying to get a hang of the XML libraries
available.  I am having trouble finding tutorials and documentation.

When I finally found some documentation at
http://velocity.activestate.com/docs/ActivePython/lib/expat-example.html, I
tried the example for expat (actually used pyexpat and expat), and have the
following result:

>>> from xml.parsers import expat
>>> def start_element(name, attrs):
... 	print 'Start element:', name, attrs
...
>>> def end_element(name):
... 	print 'End element:', name
...
>>> def char_data(data):
... 	print 'Character data:', repr(data)
...
>>> p = pyexpat.ParserCreate()
>>> p.StartElementHandler = start_element
>>> p.EndElementHandler = end_element
>>> p.CharacterDataHandler = char_data
>>> p.Parse("""<?xml version="1.0"?>
... <parent id="top"><child1 name="Paul">Text goes here</child1>
... <child2 name="Fred">More text</child2>
... </parent>""")
Start element: parent {u'id': u'top'}
Start element: child1 {u'name': u'Paul'}
Character data: u'Text goes here'
End element: child1
Character data: u'\012'
Start element: child2 {u'name': u'Fred'}
Character data: u'More text'
End element: child2
Character data: u'\012'
End element: parent
1

So what are all of those u's doing in there, and why is there a 1 printed?
This was unexpected.

Also, perhaps you can point me towards some helpful tutorials for getting up
to speed with XML processing in Python?

TIA,

Richard Anthony Hein