harmbandstra / edexmllib
PHP 库,用于验证和导入 Edexml 文件。
2.0.0
2022-12-01 21:07 UTC
Requires
- php: ^7.2 || ^8.0
- ext-dom: *
- ext-libxml: *
- goetas-webservices/xsd2php-runtime: ^0.2.16
Requires (Dev)
- goetas-webservices/xsd2php: ^0.4.6
- phpunit/phpunit: ^7.5
README
PHP 库,用于验证和导入 Edexml 文件。
安装
使用 composer 安装
$ composer require harmbandstra/edexmllib
使用方法
$xml = file_get_contents('path_to_file'); try { $edex = EdexmlFactory::load($xml); } catch (ValidationException $exception) { // Handle exception } foreach ($edex->getGroepen()->getGroep() as $groep) { echo $groep->getNaam(); } foreach ($edex->getLeerlingen() as $leerling) { echo $leerling->getGebruikersnaam(); }
如果 Edexml 文件包含在非公共 XSD 中定义类型的元素,您可以在加载 XML 之前删除该块。
$xml = file_get_contents('path_to_file'); try { $edex = EdexmlFactory::load( EdexmlFactory::stripToevoegingen($xml) ); } catch (ValidationException $exception) { // Handle exception }
要跳过验证,将 strict 设置为 false
$xml = file_get_contents('path_to_file'); $edex = EdexmlFactory::load($xml, false);
开发
该库使用 xsd2php 生成 JMS Serializer 定义文件。这些文件用于将 XML 反序列化为小块 PHP 对象。
生成类
要基于 XSD 文件生成新的类和 JMS Serializer 配置,请运行
php vendor/bin/xsd2php convert config.yml src/Resources/xsd/*.xsd
仅在规范更改时需要这样做。