1.1.2.3. gnr.core.gnrbagxml

Last page update: November 23, 2011

Classes:

External methods:

Complete reference:

1.1.2.3.1. BagFromXml

1.1.2.3.3. External methods

1.1.2.3.4. gnr.core.gnrbagxml - The complete reference list

class gnr.core.gnrbagxml.BagFromXml

The class that handles the conversion from the XML format to the Bag class

build(source, fromFile, catalog=None, bagcls=<class 'gnr.core.gnrbag.Bag'>, empty=None)

TODO

Parameters:
  • source – TODO
  • fromFile – TODO
  • catalog – TODO
  • bagcls – TODO
  • empty – TODO
do_build(source, fromFile, catalog=None, bagcls=<class 'gnr.core.gnrbag.Bag'>, empty=None, testmode=False)

TODO

Parameters:
  • source – TODO
  • fromFile – TODO
  • catalog – TODO
  • bagcls – TODO
  • empty – TODO
  • testmode – TODO
class gnr.core.gnrbagxml.BagToXml

The class that handles the conversion from the Bag class to the XML format

bagToXmlBlock(bag)

Return an XML block version of the Bag.

The XML block version of the Bag uses XML attributes for an efficient representation of types: If the element-leaf is a simple string, there are no type attributes in the corresponding XML nodes otherwise a ‘T’ attribute is set to the node and the value of ‘T’ changes in function of the type (value of ‘T’ is ‘B’ for boolean, ‘L’ for integer, ‘R’ for float, ‘D’ for date, ‘H’ for time).

>>> mybag=Bag()
>>> mybag['aa.bb']=4567
>>> mybag['aa.cc']='test'
>>> mybag.toXmlBlock()
['<aa>', u'<cc>test</cc>', u'<bb T="L">4567</bb>', '</aa>']
build(bag, filename=None, encoding='UTF-8', catalog=None, typeattrs=True, typevalue=True, addBagTypeAttr=True, onBuildTag=None, unresolved=False, autocreate=False, docHeader=None, self_closed_tags=None, translate_cb=None, omitUnknownTypes=False, omitRoot=False, forcedTagAttr=None)

Return a complete standard XML version of the Bag, including the encoding tag <?xml version='1.0' encoding='UTF-8'?>; the Bag’s content is hierarchically represented as an XML block sub-element of the <GenRoBag> node.

Is also possible to write the result on a file, passing the path of the file as the filename parameter.

Parameters:
  • bag – the Bag to transform in a XML block version
  • filename – the path of the output file
  • encoding – allow to set the XML encoding
  • catalog – TODO
  • typeattrs – TODO
  • typevalue – TODO
  • addBagTypeAttr – TODO
  • onBuildTag – TODO
  • unresolved – TODO
  • autocreate – TODO
  • docHeader – TODO
  • self_closed_tags – TODO
  • translate_cb – TODO
  • omitUnknownTypes – TODO
  • omitRoot – TODO
  • forceTagAttr – TODO
>>> mybag = Bag()
>>> mybag['aa.bb'] = 4567
>>> mybag.toXml()
'<?xml version='1.0' encoding='iso-8859-15'?><GenRoBag><aa><bb T="L">4567</bb></aa></GenRoBag>'
buildTag(tagName, value, attributes=None, cls='', xmlMode=False)

TODO Return the XML tag that represent self BagNode

Parameters:
  • tagName – TODO
  • value – TODO
  • attributes – TODO
  • cls – TODO
  • xmlMode – TODO
nodeToXmlBlock(node)

Handle all the different node types, call the method build tag. Return the XML tag that represent the BagNode

Parameters:node – the BagNode
gnr.core.gnrbagxml.isValidValue(value)

A check method for the validity of a Bag value

Parameters:value – the value to be checked