slub / php-mods-reader
将 MODS 元数据读取到 PHP 对象中,这些对象提供了一些方便的数据提取方法
v0.4.0
2024-06-17 16:17 UTC
Requires
- php: >=7.4
Requires (Dev)
- phpunit/phpunit: ~9.6
This package is auto-updated.
Last update: 2024-09-21 11:11:23 UTC
README
该库旨在简化在 PHP 应用程序中解析和解释 Metadata Object Description Schema (MODS) 元数据。
MODS 是一个广泛使用的元数据标准,用于描述数字资源,如电子文本、图像和多媒体。它提供了一个灵活的框架来描述数字资源的各个方面,包括书目信息、管理元数据和结构元数据。
它为开发者提供了一套工具和函数,以方便地在他们的 PHP 应用程序中提取、操作和利用 MODS 元数据。它使用户能够解析 MODS XML 文档、提取元数据元素和查询元数据。
该库至少需要 PHP 7.4。
用法
-
创建一个新的 reader 实例,并将 MODS XML 作为 SimpleXMLElement 传递。
-
获取所需元素或属性。
-
示例(省略了空和 null 检查)
$modsReader = new ModsReader($this->xml); // get all titleInfo elements $titleInfos = $modsReader->getTitleInfos(); // get first titleInfo element $firstTitleInfo = $modsReader->getFirstTitleInfo(); // get first titleInfo element $lastTitleInfo = $modsReader->getLastTitleInfo(); // get name elements which match to give string query $authors = $modsReader->getNames('[./mods:role/mods:roleTerm[@type="code" and @authority="marcrelator"]="aut"]'); // get nameIdentifier for first name element if its type attribute is equal to 'orcid' $identifier = $authors[0]->getNameIdentifier('[@type="orcid"]'); // get string value of element $value = $identifier->getValue(); // get 'type' attribute of element $type = $identifier->getType(); // get child elements of element $places = []; $originInfos = $this->modsReader->getOriginInfos('[not(./mods:edition="[Electronic ed.]")]'); foreach ($originInfos as $originInfo) { foreach ($originInfo->getPlaces() as $place) { foreach ($place->getPlaceTerms() as $placeTerm) { $places[] = $placeTerm->getValue(); } } }
待办事项
- 添加缺少的元数据读取
- 添加替代函数(使用参数而不是字符串查询)来读取元数据
- 添加日志记录
- 添加测试覆盖率