How to use the xmlschema.components.XsdGroup function in xmlschema

To help you get started, we’ve selected a few xmlschema examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sissaschool / xmlschema / xmlschema / components.py View on Github external
def iter_elements(self):
        for item in self:
            if isinstance(item, (XsdElement, XsdAnyElement)):
                yield item
            elif isinstance(item, XsdGroup):
                for e in item.iter_elements():
                    yield e
github sissaschool / xmlschema / xmlschema / components.py View on Github external
def __setattr__(self, name, value):
        if name == 'model':
            self._check_value(name, value, None, XSD_SEQUENCE_TAG, XSD_CHOICE_TAG, XSD_ALL_TAG)
        elif name == 'mixed':
            self._check_value(name, value, True, False)
        elif name == '_group':
            self._check_type(name, value, list)
            for i in range(len(value)):
                self._check_type(i, value[i], XsdGroup, XsdElement, XsdAnyElement)
        super(XsdGroup, self).__setattr__(name, value)
github sissaschool / xmlschema / xmlschema / factories.py View on Github external
else:
                raise XMLSchemaParseError("missing both attributes 'name' and 'ref'", elem)
        elif ref is None:
            # Global group
            group_name = get_qname(schema.target_namespace, name)
            content_model = get_xsd_component(elem)
        else:
            raise XMLSchemaParseError("found both attributes 'name' and 'ref'", elem)
    else:
        # Local group (SEQUENCE|ALL|CHOICE)
        content_model = elem
        group_name = None

    check_tag(content_model, XSD_SEQUENCE_TAG, XSD_ALL_TAG, XSD_CHOICE_TAG)
    if instance is None:
        xsd_group = XsdGroup(
            name=group_name,
            elem=content_model if elem.tag != XSD_GROUP_TAG else elem,
            schema=schema,
            model=content_model.tag,
            mixed=mixed,
            is_global=is_global
        )
    else:
        instance.elem = elem
        instance.schema = schema
        instance.model = content_model.tag
        instance.mixed = mixed
        xsd_group = instance

    if xsd_group.built is False:
        for child in iter_xsd_declarations(content_model):
github sissaschool / xmlschema / xmlschema / factories.py View on Github external
# Model group with 'name' or 'ref'
        name = elem.attrib.get('name')
        ref = elem.attrib.get('ref')
        if name is None:
            if ref is not None:
                group_name, namespace = split_reference(ref, schema.namespaces)
                xsd_group = schema.maps.lookup_group(group_name, **kwargs)
                if instance is not None:
                    instance.name = xsd_group.name
                    instance.model = xsd_group.model
                    instance.length = len(xsd_group)
                    if not instance:
                        instance.extend(xsd_group)
                    return instance
                else:
                    return XsdGroup(
                        name=xsd_group.name,
                        elem=elem,
                        schema=schema,
                        model=xsd_group.model,
                        mixed=mixed,
                        initlist=list(xsd_group)
                    )
            else:
                raise XMLSchemaParseError("missing both attributes 'name' and 'ref'", elem)
        elif ref is None:
            # Global group
            group_name = get_qname(schema.target_namespace, name)
            content_model = get_xsd_component(elem)
        else:
            raise XMLSchemaParseError("found both attributes 'name' and 'ref'", elem)
    else:
github sissaschool / xmlschema / xmlschema / factories.py View on Github external
except XMLSchemaParseError as err:
                schema.errors.append(err)
                if isinstance(err.obj, XsdComponent):
                    return err.obj
                elif etree_iselement(err.obj):
                    # Produce a dummy declaration for prosecuting the parse process
                    name = err.obj.get('name')
                    if issubclass(xsd_class, (XsdAtomicRestriction, XsdUnion, XsdList)):
                        return ANY_SIMPLE_TYPE
                    elif not name:
                        raise
                    elif issubclass(xsd_class, XsdSimpleType):
                        return ANY_SIMPLE_TYPE
                    elif issubclass(xsd_class, XsdComplexType):
                        return ANY_TYPE
                    elif issubclass(xsd_class, XsdGroup):
                        return xsd_class(name)
                    elif issubclass(xsd_class, XsdAttribute):
                        return xsd_class(name, xsd_type=ANY_SIMPLE_TYPE)
                    elif issubclass(xsd_class, XsdElement):
                        return xsd_class(name, xsd_type=ANY_TYPE)
                raise
            else:
                # Checks and connects the result with the instance argument
                if not isinstance(result, XsdComponent):
                    raise XMLSchemaTypeError("factory result must be a XsdComponent: %r" % result)
                elif instance is not None and id(instance) != id(result):
                    raise XMLSchemaValueError("instance %r replaced by %r," % (instance, result))
                if result.is_global is not is_global:
                    if is_global:
                        raise XMLSchemaValueError("%r must be global." % result)
                    else:
github sissaschool / xmlschema / xmlschema / components.py View on Github external
def __setattr__(self, name, value):
        if name == 'model':
            check_value(self, name, None, value, (None, XSD_GROUP_TAG, XSD_SEQUENCE_TAG, XSD_CHOICE_TAG, XSD_ALL_TAG))
        elif name == 'mixed':
            check_value(self, name, None, value, (True, False))
        elif name == '_group':
            check_type(self, name, None, value, (list,))
            for i in range(len(value)):
                check_type(self, name, i, value[i], (XsdGroup, XsdElement, XsdAnyElement))
        super(XsdGroup, self).__setattr__(name, value)
github sissaschool / xmlschema / xmlschema / components.py View on Github external
def __setattr__(self, name, value):
        if name == 'model':
            self._check_value(name, value, None, XSD_SEQUENCE_TAG, XSD_CHOICE_TAG, XSD_ALL_TAG)
        elif name == 'mixed':
            self._check_value(name, value, True, False)
        elif name == '_group':
            self._check_type(name, value, list)
            for i in range(len(value)):
                self._check_type(i, value[i], XsdGroup, XsdElement, XsdAnyElement)
        super(XsdGroup, self).__setattr__(name, value)
github sissaschool / xmlschema / xmlschema / factories.py View on Github external
@xsd_factory(XsdGroup, XSD_COMPLEX_TYPE_TAG, XSD_GROUP_TAG,
             XSD_SEQUENCE_TAG, XSD_ALL_TAG, XSD_CHOICE_TAG)
def xsd_group_factory(elem, schema, instance=None, is_global=False, **kwargs):
    """
    Factory for XSD 'group', 'sequence', 'choice', 'all' definitions.

    
      Content: (annotation?, (all | choice | sequence)?)
    

github sissaschool / xmlschema / xmlschema / factories.py View on Github external
derivation = None
    content_node = get_xsd_component(elem, required=False, strict=False)

    if instance is None:
        content_type = None
        attributes = XsdAttributeGroup(elem=elem, schema=schema)
    else:
        content_type = instance.content_type
        attributes = instance.attributes

    if content_node is None or content_node.tag in (
            XSD_ATTRIBUTE_TAG, XSD_ATTRIBUTE_GROUP_TAG, XSD_ANY_ATTRIBUTE_TAG):
        #
        # complexType with empty content
        if content_type is None:
            content_type = XsdGroup(elem=elem, schema=schema, mixed=mixed, length=0)
        attributes.update(attribute_group_factory(elem, schema, instance=attributes, **kwargs))

    elif content_node.tag in (XSD_GROUP_TAG, XSD_SEQUENCE_TAG, XSD_ALL_TAG, XSD_CHOICE_TAG):
        #
        # complexType with child elements
        if content_type is None:
            content_type = XsdGroup(elem=content_node, schema=schema, mixed=mixed)

        content_type = group_factory(content_node, schema, content_type, mixed=mixed, **kwargs)
        attributes.update(attribute_group_factory(elem, schema, instance=attributes, **kwargs))

    elif content_node.tag == XSD_COMPLEX_CONTENT_TAG:
        #
        # complexType with complexContent restriction/extension
        if 'mixed' in content_node.attrib:
            mixed = content_node.attrib['mixed'] in ('true', '1')