Collective.vdexvocabulary with Metadata

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 vdex:

<?xml version="1.0" encoding="utf-8"?>
<vdex xmlns="http://www.imsglobal.org/xsd/imsvdex_v1p0" orderSignificant="false" language="en">
    <vocabIdentifier>collective.vdexvocabulary.languages</vocabIdentifier>

<term>
    <termIdentifier>english</termIdentifier>
    <caption>
        <langstring language="en">English</langstring>
        <langstring language="it">Inglese</langstring>
    </caption>
    <metadata>
        <attribute1>One</attribute1>
        <attribute2>Two</attribute2>
    </metadata>
</term>

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.

Any leads would be highly appreciated.

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.

Thanks.

This is basic but I did not know.

The underlying imsvdex package supports fetching metadata from vocab, or term


but AFAIK the zope.schema.vocabulary and its terms nor the collective.vdexvocabulary and it's vdexterm does not support metadata.

So, this is something to be added. Pull Requests appreciated.

Plone Foundation Code of Conduct