示例#1
0
def doEncode(cls, obj, el, ver, format, bounds, xmldecl, namespaces=True, 
             nsmappings={}, out=None):

  cfg = cls.config(ver)
  if not bounds:
    cfg.getProperties().add(GML2.NO_FEATURE_BOUNDS)

  e = Encoder(cfg)
  if not xmldecl:
    e.setOmitXMLDeclaration(True)
  if format:
    e.setIndenting(True)
  if namespaces:
    for pre,uri in nsmappings.iteritems():
      if uri:
        e.getNamespaces().declarePrefix(pre, uri)
  else:
    e.setNamespaceAware(False)

  if not isinstance(el, tuple):
    el = (cls.uri(ver), el) 

  qname = QName(el[0], el[1])
  
  if out:
    return doOutput(lambda output: e.encode(obj, qname, output), out)
  else:
    return e.encodeAsString(obj, qname)
示例#2
0
def doEncode(cls,
             obj,
             el,
             ver,
             format,
             bounds,
             xmldecl,
             namespaces=True,
             nsmappings={},
             out=None):

    cfg = cls.config(ver)
    if not bounds:
        cfg.getProperties().add(GML2.NO_FEATURE_BOUNDS)

    e = Encoder(cfg)
    if not xmldecl:
        e.setOmitXMLDeclaration(True)
    if format:
        e.setIndenting(True)
    if namespaces:
        for pre, uri in nsmappings.iteritems():
            if uri:
                e.getNamespaces().declarePrefix(pre, uri)
    else:
        e.setNamespaceAware(False)

    if not isinstance(el, tuple):
        el = (cls.uri(ver), el)

    qname = QName(el[0], el[1])

    if out:
        return doOutput(lambda output: e.encode(obj, qname, output), out)
    else:
        return e.encodeAsString(obj, qname)