xml parsing as YML parser does does

bab mis babmis307 at gmail.com
Tue Sep 24 09:22:53 EDT 2013


Hi ,
Here is an example how i do yml parsing and a proper pythonic object returns , is it possible in XML, tried lxml,dom, but there is no straight forward solution:

[root at linux-source pyrun]# cat x.yml
#Section for specifying test process information

Test: 

    commoninfo: 
        buildhome   : "/root/linuxbuilds"

     
    Project:
        default:
        
            test_parameters:
                svnuser    : "vmbuild"
                suite      : "sanity"
                username   : "root"
                
        
            Commands         :
                -   name       : generalcheck of destination
                    action     : generalcheck

                -   name       : retrieve source from svn
                    action     : retsource
                    params     : src=x,src1=y
[root at linux-source pyrun]

================================

[root at linux-source pyrun]# cat a.py 
import yaml
fd = open("x.yml")
data = fd.read()
fd.close()
ydata = yaml.safe_load(data)
import pprint
pprint.pprint( ydata )

=======================


[root at linux-source pyrun]# python a.py 
{'Test': {'Project': {'default': {'Commands': [{'action': 'generalcheck',
                                                'name': 'generalcheck of destination'},
                                               {'action': 'retsource',
                                                'name': 'retrieve source from svn',
                                                'params': 'src=x,src1=y'}],
                                  'test_parameters': {
                                                      'suite': 'sanity',
                                                      'svnuser': 'vmbuild',
                                                      'username': 'root'}}},
          'commoninfo': {'buildhome': '/root/linuxbuilds'}}}



More information about the Python-list mailing list