alcamo / xpointer
Implementation of XPointer framework with xmlns() and xpointer() schemes
Installs: 141
Dependents: 1
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/alcamo/xpointer
Requires
- php: 7.3 - 8.0
- alcamo/xml: ^0.1
Requires (Dev)
- phpunit/phpunit: ^9.5
- squizlabs/php_codesniffer: 3.*
README
use alcamo\xpointer\Pointer;
$doc = new \DOMDocument();
... load something into the document ...
$urlFragment = 'xmlns(f=http://foo.example.org) xpointer(/*/f:bar[42])';
$pointer = new Pointer($urlFragment);
The following evaluates the XPath /*/f:bar[42]
on the document,
where the prefix f
is registered as the namespace
http://foo.example.org
:
$bar = $pointer->process($doc);
Supplied interfaces and classes
Interface PointerInterface
Simple interface for classes that implement a Pointer. Requires a static factory method to create a Pointer from an URL fragment string and a method to process the pointer on a DOM document.
Class Pointer
Implementation of PointerInterface
supporting Shorthand Pointers as well as the XPointer xmlns()
Scheme and XPointer xpointer()
Scheme.
Interface PartInterface
Simple interface for classes that implement a Pointer
part. Requires
just a process()
method to process the Scheme
data. Processing of
parts stops as soon as this method return a non-null
value.
Class XmlnsPart
Implementation of PartInterface
for the XPointer xmlns()
Scheme. The process()
method
modifies the namespace bindings as described in the specification.
Class XpointerPart
Implementation of PartInterface
for the XPointer xpointer()
Scheme. The process()
method
returns the result of XPath evaluation, if successful.
Extending this package
To add other XPointer schemes:
- Write a new pointer part class that implements
PartInterface
. - Write a class derived from
Pointer
and add your new pointer part class to the class constantSCHEME_MAP
.