2
ximファイルを読み取るためにpythonとlxmlを使用し、xsdファイルに対して検証されます。私は属性のxs:タイプを見つけたいと思います。今までlxmlを持つxmlファイル内の属性のタイプ
マイコード: 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'>
のような私はタイプは関係なく、常にXSD仕様をstrさ
self.xmlRoot.child.attrib['number']
を経由してアクセスする属性のために何かを取得します。どのように私は属性の型を取得する?