According to the specifications, Vdex XML files may include metadata. I understand this to mean that terms may contain attributes. Is my understanding correct? If so, does anyone have a sample vdex file with metadata or a project/module that uses it?
The c.vdexvocabulary module relies on imsvdex which has methods (getVocabMetadata and getTermMetadataById) for getting the metadata. These methods return lists of lxml.etree._Element types. However, I get 'None' using lxml find and xpath.
My console code (vdex registered via c.vdexvocabulary vocabulary type):
>>>from zope.component import getUtility
>>>from zope.schema.interfaces import IVocabularyFactory
>>> factory = getUtility(IVocabularyFactory, 'collective.vdexvocabulary.languages')
>>>mdata = factory.vdex.getTermMetadataById('english')
>>>mdata
[<Element {http://www.imsglobal.org/xsd/imsvdex_v1p0}metadata at 0x7f8b064e0a00>]
>>>element = mdata[0]
>>>type(element)
<type 'lxml.etree._Element'>
>>>element.find('attribute1').text
File "<console>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute ''text'
BTW, the vocabulary that I want to create is a standard geographic code. I want to add metadata like longitude and latitude, This is hardly updated so I figured it might be better if it is implemented as a vocabulary defined in a module.
Your XML document has an (implicitly) associated (XML) namespace (http://www.imsglobal.org/xsd/imsvdex_v1p0). Therefore, you cannot refer to elements with their local name. Try element.find('{http://www.imsglobal.org/xsd/imsvdex_v1p0}attribute1').text.