im с использованием python и lxml для чтения xml-файлов, которые проверяются на файл xsd. Я хочу узнать атрибут xs: type.Тип атрибута в XML-файле с lxml
Мой код до сих пор: XSD
...
<xs:complexType name="io" >
<xs:attribute name="number" type="xs:decimal" use="optional" default="5.9"/>
</xs:complexType>
...
XML-
...
<io number="1.1">
...
Тогда Python код:
with open(self.xmlSchemaFilename) as schema:
xmlschema_doc = objectify.parse(schema)
self.xmlschema = etree.XMLSchema(xmlschema_doc)
parser = etree.XMLParser(schema = self.xmlschema,
attribute_defaults = True, remove_blank_text=True)
with open(self.xmlFilename) as myfile:
tree = objectify.parse(myfile, parser)
#this correctly asserts the type from the xsd
root = tree.getroot()
self.xmlRoot = objectify.fromstring(etree.tostring(root))
self.xmlschema.assertValid(self.xmlRoot)
Теперь я могу получить доступ к типу всех дочерних узлов с помощью
type(self.xmlRoot.child)
и возвращает правильный тип из XSD и получает что-то вроде
<type 'lxml.objectify.IntElement'>
, но и для атрибутов, которые я доступ через
self.xmlRoot.child.attrib['number']
тип всегда Str независимо спецификации XSD. Как получить тип атрибутов?