Exemplo n.º 1
0
    def visit_simple_type(self, node, parent):
        """
        Definition::

            <simpleType
              final = (#all | (list | union | restriction))
              id = ID
              name = NCName
              {any attributes with non-schema Namespace}...>
            Content: (annotation?, (restriction | list | union))
            </simpleType>

        :param node: The XML node
        :type node: lxml.etree._Element
        :param parent: The parent XML node
        :type parent: lxml.etree._Element

        """

        if parent.tag == tags.schema:
            name = node.get('name')
            is_global = True
        else:
            name = parent.get('name', 'Anonymous')
            is_global = False
        base_type = '{http://www.w3.org/2001/XMLSchema}string'
        qname = as_qname(name, node.nsmap, self.document._target_namespace)

        annotation, items = self._pop_annotation(node.getchildren())
        child = items[0]
        if child.tag == tags.restriction:
            base_type = self.visit_restriction_simple_type(child, node)
            xsd_type = xsd_types.UnresolvedCustomType(qname, base_type,
                                                      self.schema)

        elif child.tag == tags.list:
            xsd_type = self.visit_list(child, node)

        elif child.tag == tags.union:
            xsd_type = self.visit_union(child, node)
        else:
            raise AssertionError("Unexpected child: %r" % child.tag)

        assert xsd_type is not None
        if is_global:
            self.register_type(qname, xsd_type)
        return xsd_type
Exemplo n.º 2
0
    def visit_simple_type(self, node, parent):
        """
            <simpleType
              final = (#all | (list | union | restriction))
              id = ID
              name = NCName
              {any attributes with non-schema Namespace}...>
            Content: (annotation?, (restriction | list | union))
            </simpleType>
        """

        if parent.tag == tags.schema:
            name = node.get('name')
            is_anonymous = False
        else:
            name = parent.get('name')
            is_anonymous = True

        base_type = '{http://www.w3.org/2001/XMLSchema}string'
        for child in node.iterchildren():
            if child.tag == tags.annotation:
                continue

            elif child.tag == tags.restriction:
                base_type = self.visit_restriction_simple_type(child, node)
                break

            elif child.tag == tags.list:
                self.visit_list(child, node)
                break

            elif child.tag == tags.union:
                self.visit_union(child, node)
                break

        xsd_type = xsd_types.UnresolvedCustomType(name, base_type)
        if not is_anonymous:
            qname = as_qname(name, node.nsmap, self.schema._target_namespace)
            self.schema.register_type(qname, xsd_type)
        return xsd_type