Exemple #1
0
    def _parse_xml_data(self):
        """Get remote XML data for this DOV object, parse the raw XML and
        save the results in the data object.

        Raises
        ------
        NotImplementedError
            This is an abstract method that should be implemented in a
            subclass.

        """
        xml = self._get_xml_data()

        try:
            tree = parse_dov_xml(xml)

            for field in self.get_fields(source=('xml', ),
                                         include_subtypes=False).values():
                self.data[field['name']] = self._parse(
                    func=tree.findtext,
                    xpath=field['sourcefield'],
                    namespace=None,
                    returntype=field.get('type', None))

            self._parse_subtypes(xml)
        except XmlParseError:
            warnings.warn(("Failed to parse XML for object '%s'. Resulting "
                           "dataframe will be incomplete.") % self.pkey,
                          XmlParseWarning)
Exemple #2
0
    def from_xml(cls, xml_data):
        """Build instances of this subtype from XML data.

        Parameters
        ----------
        xml_data : bytes
            Raw XML data of the DOV object that contains information about
            this subtype.

        Yields
        ------
            An instance of this type for each occurence of the rootpath in
            the XML document.

        """
        try:
            tree = parse_dov_xml(xml_data)
            for element in tree.findall(cls._rootpath):
                yield cls.from_xml_element(element)
        except XmlParseError:
            # Ignore XmlParseError here in subtypes, assuming it will be
            # reported in the corresponding main type. We can make this
            # assumption safely because both main and subtypes are in a
            # single XML file.
            pass
Exemple #3
0
    def _parse_xml_data(self, session=None):
        """Get remote XML data for this DOV object, parse the raw XML and
        save the results in the data object.

        Parameters
        ----------
        session : requests.Session
            Session to use to perform HTTP requests for data. Defaults to None,
            which means a new session will be created for each request.

        """
        xml = self._get_xml_data(session)

        try:
            tree = parse_dov_xml(xml)

            for field in self.get_fields(source=('xml', ),
                                         include_subtypes=False).values():
                self.data[field['name']] = self._parse(
                    func=tree.findtext,
                    xpath=field['sourcefield'],
                    namespace=None,
                    returntype=field.get('type', None))

            self._parse_subtypes(xml)
        except XmlParseError:
            warnings.warn(("Failed to parse XML for object '{}'. Resulting "
                           "dataframe will be incomplete.").format(self.pkey),
                          XmlParseWarning)