get_parser

xgbxml.xgbxml.get_parser(version='6.01')[source]

Returns a lxml.etree.XMLParser containing custom elements for gbXML files.

Parameters:

version (str) – The gbxml version string. Default is ‘6.01’.

Return type:

lxml.etree.XMLParser

Note

Using this parser means that when lxml is used to read in a gbXML file, the different elements (gbXML, Campus, Building etc.) are instantiated with custom classes.

This means that the lxml/xgbxml elements have additional features, which are specifically designed for working with gbXML files.

For example, the gbXML element has additional properties such as version and temperatureUnit for direct access to the XML attributes. It also has additional methods, such as add_Campus, for creating new child elements.

The xgbxml parser provides three types of additional properties and methods:

  1. Properties and methods inherited from the gbElement class.

  2. Properties and methods that are automatically generated from the gbXML schema file. For example, this method generates the version property and the add_Campus method for the gbXML element.

  3. Properties and methods which are custom written for the element. This is bespoke code written for a particular element to provide additional functionality. An example is the get_shell() method of the Surface class.

Code Example

from lxml import etree
import xgbxml

parser=xgbxml.get_parser()  # default is gbXML version 6.01

tree=etree.parse('my_gbxml_file.xml', parser)
gbxml=tree.getroot()