[Tutor] xml stuff

Furmanek, Greg Greg.Furmanek@hit.cendant.com
Thu, 8 Mar 2001 16:03:30 -0500


Ok I have used the expat stuff and I get some strange results:

Character data: [u'    ']
Start element: [PRICE] [{}]
Character data: [u'$7.06']
End element: [PRICE]
Character data: [u'\012']
Character data: [u'    ']
Start element: [AVAILABILITY] [{}]
Character data: [u'052599']
End element: [AVAILABILITY]
Character data: [u'\012']
Character data: [u'  ']
End element: [PLANT]
Character data: [u'\012']
Character data: [u'  ']
Character data: [u'\012']
End element: [CATALOG]

when parsing some stuff I get these u characters.
Is this normal. code follows:

from xml.parsers import expat




def start_element(name, attrs):
    print 'Start element: [%s] [%s]' % ( name, attrs)

def end_element(name):
    print 'End element: [%s]' % ( name )

def char_data(data):
    print 'Character data: [%s]' % ( repr(data) )

#  ...............................   FUNCTIONS
...............................
def main():

	p = expat.ParserCreate()

	p.StartElementHandler = start_element
	p.EndElementHandler = end_element
	p.CharacterDataHandler = char_data

	p.Parse( 
"""<?xml version="1.0"?>
<CATALOG>
  <PLANT>
    <COMMON>Butterfly Weed</COMMON>
    <BOTANICAL>Asclepias tuberosa</BOTANICAL>
    <ZONE>Annual</ZONE>
    <LIGHT>Sunny</LIGHT>
    <PRICE>$2.78</PRICE>
    <AVAILABILITY>063099</AVAILABILITY>
  </PLANT>
  
  <PLANT>
    <COMMON>Cinquefoil</COMMON>
    <BOTANICAL>Potentilla</BOTANICAL>
    <ZONE>Annual</ZONE>
    <LIGHT>Shade</LIGHT>
    <PRICE>$7.06</PRICE>
    <AVAILABILITY>052599</AVAILABILITY>
  </PLANT>
  
</CATALOG>""")



#  ................................   CLASSES
................................




#  ............................   EXECUTION START
............................
if __name__ == "__main__":
	main()


"The sender believes that this E-mail and any attachments were free of any
virus, worm, Trojan horse, and/or malicious code when sent.  This message
and its attachments could have been infected during transmission.  By
reading the message and opening any attachments, the recipient accepts full
responsibility for taking protective and remedial action about viruses and
other defects.  The sender's employer is not liable for any loss or damage
arising in any way from this message or its attachments."