コード例 #1
0
    def bind(self, qname: str, text: NoneStr, tail: NoneStr, objects: List) -> bool:
        obj: Any = None
        if self.has_children:
            obj = AnyElement(
                qname=qname,
                text=ParserUtils.normalize_content(text),
                tail=ParserUtils.normalize_content(tail),
                attributes=ParserUtils.parse_any_attributes(self.attrs, self.ns_map),
                children=ParserUtils.fetch_any_children(self.position, objects),
            )
            objects.append((self.var.qname, obj))
        else:
            var = self.var
            ns_map = self.ns_map
            datatype = ParserUtils.data_type(self.attrs, self.ns_map)
            obj = ParserUtils.parse_value(text, [datatype.type], var.default, ns_map)

            if var.derived:
                obj = DerivedElement(qname=qname, value=obj)

            objects.append((qname, obj))

            if self.mixed:
                tail = ParserUtils.normalize_content(tail)
                if tail:
                    objects.append((None, tail))

        return True
コード例 #2
0
    def bind(self, qname: str, text: NoneStr, tail: NoneStr, objects: List) -> bool:
        obj = AnyElement(
            qname=qname,
            text=ParserUtils.normalize_content(text),
            tail=ParserUtils.normalize_content(tail),
            attributes=ParserUtils.parse_any_attributes(self.attrs, self.ns_map),
            children=ParserUtils.fetch_any_children(self.position, objects),
        )
        objects.append((self.var.qname, obj))

        return True
コード例 #3
0
ファイル: nodes.py プロジェクト: rmr1154/xsdata
    def parse_element(self, element: Element, objects: List[Any]) -> Tuple:
        """
        Parse the given element attributes/text/tail, find all child objects
        and mixed content and initialize a new generic element instance.

        :return: A tuple of the object's qualified name and a new
            :class:`xsdata.formats.dataclass.models.generics.AnyElement` instance.
        """
        obj = ParserUtils.parse_any_element(element)
        obj.children = ParserUtils.fetch_any_children(self.position, objects)

        return self.qname, obj
コード例 #4
0
    def bind(self, qname: str, text: NoneStr, tail: NoneStr,
             objects: List) -> bool:
        children = ParserUtils.fetch_any_children(self.position, objects)
        attributes = ParserUtils.parse_any_attributes(self.attrs, self.ns_map)
        derived = self.var.derived or qname != self.var.qname
        text = ParserUtils.normalize_content(text) if children else text
        text = "" if text is None and not self.var.nillable else text
        tail = ParserUtils.normalize_content(tail)

        if tail or attributes or children or self.var.wildcard or derived:
            obj = AnyElement(
                qname=qname,
                text=text,
                tail=tail,
                attributes=attributes,
                children=children,
            )
            objects.append((self.var.qname, obj))
        else:
            objects.append((self.var.qname, text))

        return True
コード例 #5
0
ファイル: nodes.py プロジェクト: nimish/xsdata
    def parse_element(self, element: Element, objects: List[Any]) -> Tuple:
        obj = ParserUtils.parse_any_element(element)
        obj.children = ParserUtils.fetch_any_children(self.position, objects)

        return self.qname, obj
コード例 #6
0
 def test_fetch_any_children(self):
     objects = [(x, x) for x in "abc"]
     self.assertEqual(["b", "c"], ParserUtils.fetch_any_children(1, objects))