gbElement base class

class xgbxml.xgbxml.gbElement[source]

The default element class for the gbxml parser.

add_child(child_nntag, **kwargs)[source]

Adds a new child element to the element.

Parameters
  • child_nntag (str) – The ‘no namespace’ tag of the child element.

  • kwargs – Attributes to be set for the child element.

Returns

The newly created child element.

Return type

(subclass of) gbElement

get_attribute(attribute_name)[source]

Returns the attribute value as a python type.

Parameters
  • attribute_name – The name of the attribute.

  • attribute_name – str

Raises

KeyError – If the attribute is not present in the element.

Return type

bool, str, float

property get_attributes

The attributes of the element.

Returns

A dictionary of attributes where the attribute values have been converted to the correct python types according to the schema.

Return type

dict

get_child(child_nntag, child_id=None)[source]

Returns a child element with specified tag.

If child_id is not supplied, then the first child element found is returned.

Parameters
  • child_nntag (str) – The ‘no namespace’ tag of the child element.

  • child_id (str) – Optional, the ‘id’ attribute of the child element.

Raises

?? – If the child element is not present.

Return type

(subclass of) gbElement

get_children(child_nntag)[source]

Returns child elements with a specified tag.

Parameters

child_nntag (str) – The ‘no e coercednamespace’ tag of the child elements.

Return type

list ??

property id

The id of the element.

Raises

KeyError – If, on retrieval, the ‘id’ attribute is not present in the element.

Return type

str

property nntag

Returns the tag without the namespace (‘no namespace tag’)

Example:

>>> print(gbXML.tag)
{http://www.gbxml.org/schema}gbXML
>>> print(gbXML.nntag)
gbXML
Return type

str

property ns

The namespace dictionary for xpath calls.

Return type

dict

set_attribute(attribute_name, value)[source]

Sets an attribute value of the element.

Attribute will be created if it does not already exist. Attribute value is modified if attribute does already exist. Value is coerced to the correct python type if needed.

Parameters
  • attribute_name – The name of the attribute.

  • attribute_name – str

  • value (bool, str, float) – The new value for the attribute.

Raises
  • KeyError – If attribute does not exist in the schema.

  • ValueError – If attribute has enumerations, and ‘value’ does not match one of the enumeration options.

Return type

The (coerced) value assigned to the attribute.

tostring()[source]

Returns a string of the xml of the element.

Return type

str

property value

The value of the element text as a python type.

Return type

str, float