<s> import os <EOL> from lxml import etree <EOL> XSD_NAMESPACE = "<STR_LIT>" <EOL> XSD = "<STR_LIT>" % XSD_NAMESPACE <EOL> NSMAP = dict ( xsd = XSD_NAMESPACE ) <EOL> def xsd2py ( fn , nsname ) : <EOL> tree = etree . parse ( fn ) <EOL> root = tree . getroot ( ) <EOL> yield "<STR_LIT>" <EOL> yield "<STR_LIT>" % ( nsname , nsname , str ( root . get ( '<STR_LIT>' ) ) ) <EOL> for e in root : <EOL> if e . tag == XSD + '<STR_LIT>' : <EOL> na = e . get ( '<STR_LIT:name>' , None ) <EOL> if na is None : <EOL> yield indent + "<STR_LIT>" % e . tag <EOL> continue <EOL> yield indent + "<STR_LIT>" % na <EOL> for ee in e : <EOL> if ee . tag == XSD + '<STR_LIT>' : <EOL> for item in ee : <EOL> na = item . get ( '<STR_LIT:name>' , None ) <EOL> if na is None : <EOL> continue <EOL> ta = item . get ( '<STR_LIT:type>' , None ) <EOL> if ta is None : <EOL> yield indent * <NUM_LIT:2> + "<STR_LIT>" % na <EOL> else : <EOL> if '<STR_LIT::>' in ta : <EOL> typename = ta . replace ( '<STR_LIT::>' , '<STR_LIT:.>' ) <EOL> else : <EOL> typename = nsname + '<STR_LIT:.>' + ta <EOL> yield indent * <NUM_LIT:2> + "<STR_LIT>" % ( na , typename ) <EOL> elif e . tag == XSD + '<STR_LIT>' : <EOL> na = e . get ( '<STR_LIT:name>' , None ) <EOL> if na is None : <EOL> yield indent + "<STR_LIT>" % e . tag <EOL> continue <EOL> yield indent + "<STR_LIT>" % e . tag <EOL> yield indent + "<STR_LIT>" % na <EOL> else : <EOL> yield indent + "<STR_LIT>" % e . tag <EOL> def main ( ) : <EOL> fn = os . path . join ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> for ln in xsd2py ( fn , '<STR_LIT>' ) : <EOL> print ln </s>
