Afternoon

Wondering has anyone much experience with lxml specifically objectify?

When I pick up a file with lxml and use objectify dumping root works as 
expected actually better its quite nice. This is how i do it, file handling 
part left out for brevity.

def getsMeet(file_list):
    for filename in sorted(file_list):
        filename=my_dir + filename
        yield filename

def parseXML():
    """
    """
    for file in getsMeet(file_list):
        with open(file) as f:
            xml = f.read()

            root = objectify.fromstring(xml)
            print(root.tag)
            print(objectify.dump(root))
            race = objectify.SubElement(root,"race")
            print(objectify.dump(race))


parseXML()

So the first call to print(objectify.dump(root)) gives as a sample.

meeting = None [ObjectifiedElement]
  * id = '42977'
  * barriertrial = '0'
  * venue = 'Rosehill Gardens'
  * date = '2016-05-21T00:00:00'
  * gearchanges = '-1'
  * stewardsreport = '-1'
  * gearlist = '-1'
  * racebook = '0'
  * postracestewards = '0'
  * meetingtype = 'TAB'
  * rail = 'Timing - Electronic : Rail - +6m'
  * weather = 'Fine      '
  * trackcondition = 'Good 3    '
  * nomsdeadline = '2016-05-16T11:00:00'
  * weightsdeadline = '2016-05-17T16:00:00'
  * acceptdeadline = '2016-05-18T09:00:00'
  * jockeydeadline = '2016-05-18T12:00:00'
    club = '' [StringElement]
      * abbrevname = 'Australian Turf Club'
      * code = '56398'
      * associationclass = '1'
      * website = 'http://'
    race = None [ObjectifiedElement]
      * id = '215411'
      * number = '1'
      * nomnumber = '9'

Then I am confused when I want to repeat this but only for the subelement race 
I get a return but not as expected.

This is my return
race = '' [StringElement]

so why do i not get all the elements of race as I do when i dump the root?

Cheers

Sayth
PS I am referring to this documentation 
http://lxml.de/objectify.html#element-access-through-object-attributes
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to