logifire / xml
使用SimpleXMLElement内部实现的类型安全的XML读取器
1.2.0
2020-03-26 07:43 UTC
Requires (Dev)
- phpunit/phpunit: ^7.4
README
示例
$xml = <<<XML <root xmlns="https://example.org"> <string attribute="first">Hello World</string> <int>100</int> <string attribute="second">Hello Internet</string> </root> XML; $namespace = 'https://example.org'; $prefix = 'p'; $reader = Reader::create($xml, $namespace, $prefix); // Absolute path $reader->hasNode('/p:root'); // true $reader->getString('/p:root/p:string[@attribute="first"]'); // Hello World $reader->getInt('/p:root/p:int'); // 100 // Relative path $collection = $reader->getCollection('/p:root/p:string'); $string_reader = $collection[0]; $string_reader->getName(); // string $string_reader->getString('@attribute'); // first