def parseFragment(file, context, namespaces=True):
 if namespaces:
  builder = FragmentBuilderNS(context)
 else:
  builder = FragmentBuilder(context)
 if isinstance(file, StringTypes):
  fp = open(file, 'rb')
  try:
   result = builder.parseFile(fp)
  finally:
   fp.close()
 else:
  result = builder.parseFile(file)
 return result

def parseFragment ( file , context , namespaces = True ) : if namespaces : builder = FragmentBuilderNS ( context ) else : builder = FragmentBuilder ( context ) if isinstance ( file , StringTypes ) : fp = open ( file , 'rb' ) try : result = builder . parseFile ( fp ) finally : fp . close ( ) else : result = builder . parseFile ( file ) return result
parse a fragment of a document .