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";
}
?>
Accessing links (Previous) Error handling (Next)
Last updated: Thu, 30 Oct 2014 — Download Documentation
Do you think that something on this page is wrong? Please file a bug report or add a note.
View this page in:

User Notes:

There are no user contributed notes for this page.