Home » XML » XML_RDDL » Manual
Class to read RDDL (Resource Directory Description Language) documents.
Introduction
Introduction – Introduction to XML_RDDL
Introduction to XML_RDDL
XML_RDDL is a class that allows the extraction of RDDL resources from an XML document.
The Resource Directory Description Language is an extension of XHTML Basic 1.0 with an added element named resource. This element serves as an XLink to the referenced resource, and contains a human-readable description of the resource and machine readable links which describe the purpose of the link and the nature of the resource being linked to. The nature of the resource being linked to is indicated by the xlink:role attribute and the purpose of the link is indicated by the xlink:arcrole attribute.
For more information on RDDL, visit the RDDL website.
Example
Example – Example for the usage of XML_RDDL
Usage example
As the RDDL website contains RDDL resources embedded in the XHMTL code of the home page, it can be used in the following example.
Fetching resources from www.rddl.org
<?php
require_once "XML/RDDL.php";
// create new RDDL parser
$rddl = &new XML_RDDL();
// parse a document that contains RDDL resources
$result = $rddl->parseRDDL('http://www.rddl.org');
// check for error
if (PEAR::isError($result)) {
echo sprintf( "ERROR: %s (code %d)", $result->getMessage(), $result->getCode());
exit;
}
// get all resources
$resources = $rddl->getAllResources();
echo "<pre>";
print_r($resources);
echo "</pre>";
// get one resource by its Id
$test = $rddl->getResourceById('CSS');
echo "<pre>";
print_r($test);
echo "</pre>";
// get all stylesheets
$test = $rddl->getResourcesByNature('http://www.w3.org/1999/XSL/Transform');
echo "<pre>";
print_r($test);
echo "</pre>";
// get all normative references
$test = $rddl->getResourcesByPurpose('http://www.rddl.org/purposes#normative-reference');
echo "<pre>";
print_r($test);
echo "</pre>";
?>
XML_RDDL::XML_RDDL
XML_RDDL::XML_RDDL() – Constructor
Synopsis
require_once 'XML/RDDL.php';
object XML_RDDL::XML_RDDL (
string $rddlNamespace = "rddl"
, string $xlinkNamespace = "xlink"
)
Description
Creates a new instance of XML_RDDL that can be used to parse RDDL documents.
When instantiating you may specifiy RDDL and XLINK namespaces. This may change, when XML_Parser supports namespaces and XML_RDDL will be able to extract the correct namespace abbrevations.
Parameter
-
string $rddlNamespace- abbrevation for the RDDL namespace. -
string $xlinkNamespace- abbrevation for the XLink namespace.
Note
This function can not be called statically.
XML_RDDL::parseRDDL
XML_RDDL::parseRDDL() – parse a document that contains RDDL resources
Synopsis
require_once 'XML/RDDL.php';
boolean XML_RDDL::parseRDDL (
string $input
, boolean $isFile = true
)
Description
Parses an XML or XHTML document that contains RDDL resources and stores information about them for retrieval by the other methods.
Parameter
-
string $input- input to parse, either a string or a file. If it's a file, you have to set $isFile to true. -
boolean $isFile- flag to indicate whether the $input parameter should be treated as a filename.
Return value
Returns TRUE on success, PEAR_Error on failure.
Note
This function can not be called statically.
XML_RDDL::getAllResources
XML_RDDL::getAllResources() – return all resources that have been found
Synopsis
require_once 'XML/RDDL.php';
array XML_RDDL::getAllResources (
)
Description
Returns an array containing all reources that have been found. You have to call XML_RDDL::parseRDDL() first.
Return value
array array containing all resources
Note
This function can not be called statically.
XML_RDDL::getResourceById
XML_RDDL::getResourceById() – get one resource from the document
Synopsis
require_once 'XML/RDDL.php';
array XML_RDDL::getResourceById (
string $id
)
Description
Gets one resource from a document. You have to call XML_RDDL::parseRDDL() first.
Parameter
-
string $id- ID of the resource you want to get.
Return value
array array containing all information about the specified resource or a PEAR_Error if the resource does not exist.
Note
This function can not be called statically.
XML_RDDL::getResourcesByNature
XML_RDDL::getResourcesByNature() – selects all resources of a specified nature
Synopsis
require_once 'XML/RDDL.php';
array XML_RDDL::getResourcesByNature (
string $nature
)
Description
Gets all resources of a given nature from an RDDL document. You have to call XML_RDDL::parseRDDL() first. The nature of a resource is specified by the 'xlink:role' attribute. A nature can be a stylesheet, a DTD, a HTML document, etc. You can find a list of well known natures at http://www.rddl.org/natures/.
Parameter
-
string $nature- nature of the resources you want to get.
Return value
array array containing all resources with the specified nature.
Note
This function can not be called statically.
Usage example
Getting all stylesheets from a document
<?php
require_once "XML/RDDL.php";
// create new parser
$rddl = &new XML_RDDL();
// parse a document that contains RDDL resources
$result = $rddl->parseRDDL('http://www.rddl.org');
// check for error
if (PEAR::isError($result)) {
echo sprintf( "ERROR: %s (code %d)", $result->getMessage(), $result->getCode());
exit;
}
// get all stylesheets
$xslt = $rddl->getResourcesByNature('http://www.w3.org/1999/XSL/Transform');
echo "<pre>";
print_r($xslt);
echo "</pre>";
?>
XML_RDDL::getResourcesByPurpose
XML_RDDL::getResourcesByPurpose() – selects all resources of a specified nature
Synopsis
require_once 'XML/RDDL.php';
array XML_RDDL::getResourcesByPurpose (
string $purpose
)
Description
Gets all resources of a given purpose from an RDDL document. You have to call XML_RDDL::parseRDDL() first. The purpose of a resource is specified by the 'xlink:arcrole' attribute. The purpose of a resource link determines what the link will be used for. Frequently the purpose of a link can be determined from the nature of the referenced resource. For example the purpose of an XML Schema is typically schema validation, yet a schema may be comprised of a number of included modules and even when included modules are themselves an XML Schema, the purpose is as a module. You can find a list of well known purposes at http://www.rddl.org/purposes/.
Parameter
-
string $purpose- purpose of the resources you want to get.
Return value
array array containing all resources with the specified purpose.
Note
This function can not be called statically.
Usage example
Getting all normative references
<?php
require_once "XML/RDDL.php";
// create new parser
$rddl = &new XML_RDDL();
// parse a document that contains RDDL resources
$result = $rddl->parseRDDL('http://www.rddl.org');
// check for error
if (PEAR::isError($result)) {
echo sprintf( "ERROR: %s (code %d)", $result->getMessage(), $result->getCode());
exit;
}
// get all normative references
$ref = $rddl->getResourcesByPurpose('http://www.rddl.org/purposes#normative-reference');
echo "<pre>";
print_r($ref);
echo "</pre>";
?>
XML_RDDL::getResourcesByLanguage
XML_RDDL::getResourcesByLanguage() – selects all resources of a specified language
Synopsis
require_once 'XML/RDDL.php';
array XML_RDDL::getResourcesByLanguage (
string $language
)
Description
Gets all resources of a given language from an RDDL document. You have to call XML_RDDL::parseRDDL() first. If a resource has no xml:lang attribute, the xml:lang attribute of the root of the document is used.
Parameter
-
string $language- language of the resources you want to get.
Return value
array array containing all resources with the specified language.
Note
This function can not be called statically.
Usage example
Getting all english resource
<?php
require_once "XML/RDDL.php";
// create new parser
$rddl = &new XML_RDDL();
// parse a document that contains RDDL resources
$result = $rddl->parseRDDL('http://www.rddl.org');
// check for error
if (PEAR::isError($result)) {
echo sprintf( "ERROR: %s (code %d)", $result->getMessage(), $result->getCode());
exit;
}
// get all english resources
$en = $rddl->getResourcesByLanguage('en');
echo "<pre>";
print_r($en);
echo "</pre>";
?>
XML_RDDL::apiVersion
XML_RDDL::apiVersion() – return API version
Synopsis
require_once 'XML/RDDL.php';
string XML_RDDL::apiVersion (
)
Description
Returns API version of XML_RDDL.
Return value
string API version
Note
This function can be called statically.