Accessing properties

Properties of XRD files and link elements can be accessed by using its ArrayAccess interface or the getProperties() method. The returned properties are objects of type XML_XRD_Element_Property.

Get a single property

<?php
require_once 'XML/XRD.php';
$xrd = new XML_XRD();
$xrd->loadFile('http://example.org/.well-known/host-meta');
if (isset(
$xrd['http://spec.example.net/type/person'])) {
    echo 
$xrd['http://spec.example.net/type/person'] . "\n";
}
?>

Get all properties

<?php
require_once 'XML/XRD.php';
$xrd = new XML_XRD();
$xrd->loadFile('http://example.org/.well-known/host-meta');
foreach (
$xrd->getProperties() as $property) {
    echo 
$property->type ': ' $property->value "\n";
}
?>

Get all properties of a type

<?php
require_once 'XML/XRD.php';
$xrd = new XML_XRD();
$xrd->loadFile('http://example.org/.well-known/host-meta');
foreach (
$xrd->getProperties('http://spec.example.net/type/person') as $property) {
    echo 
$property->type ': ' $property->value "\n";
}
?>