NAME
RDF::RDFa::Parser - RDFa parser using XML::LibXML.
SYNOPSIS
use RDF::RDFa::Parser;
$parser = RDF::RDFa::Parser->new($xhtml, $baseuri);
$parser->consume;
$graph = $parser->graph;
VERSION
0.10
PUBLIC METHODS
- $p = RDF::RDFa::Parser->new($xhtml, $baseuri)
-
This method creates a new
RDF::RDFa::Parser
object and returns it. The XHTML document is parsed usingXML::LibXML
, which will throw an exception if it is not well-formed.RDF::RDFa::Parser
does not catch the exception. The base URI is used to resolve relative URIs found in the document. - $p->xhtml
-
Returns the XHTML source of the document being parsed.
- $p->uri
-
Returns the base URI of the document being parsed. This will usually be the same as the base URI provided to the constructor, but may differ if the document contains a <base> HTML element.
Optionally it may be passed a parameter - an absolute or relative URI - in which case it returns the same URI which it was passed as a parameter, but as an absolute URI, resolved relative to the document's base URI.
This seems like two unrelated functions, but if you consider the consequence of passing a relative URI consisting of a zero-length string, it in fact makes sense.
- $p->dom
-
Returns the parsed
XML::LibXML::Document
. - $p->set_callbacks(\&func1, \&func2)
-
Set callbacks for handling RDF triples extracted from RDFa document. The first function is called when a triple is generated taking the form of (resource, resource, resource). The second function is called when a triple is generated taking the form of (resource, resource, literal).
The parameters passed to the first callback function are:
A reference to the
RDF::RDFa::Parser
objectA reference to the
XML::LibXML element
being parsedSubject URI or bnode
Predicate URI
Resource URI or bnode
Graph URI or bnode (if named graphs feature is enabled)
The parameters passed to the second callback function are:
A reference to the
RDF::RDFa::Parser
objectA reference to the
XML::LibXML element
being parsedSubject URI or bnode
Predicate URI
Resource literal
Datatype URI (possibly undef or '')
Language (possibly undef or '')
Graph URI or bnode (if named graphs feature is enabled)
In place of either or both functions you can use the string
'print'
which sets the callback to a built-in function which prints the triples to STDOUT as Turtle. Either or both can be set to undef, in which case, no callback is called when a triple is found. - $p->named_graphs($xmlns, $attribute, $attributeType)
-
RDF::RDFa::Parser
allows for one RDFa document to generate multiple graphs. A graph is created by enclosing it in an element with an attribute with XML namespace $xmlns and local name $attribute.Each graph is given a URI - if $attributeType is the string 'id', then the URI is generated by treating the attribute like an 'id' attribute - i.e. the URI is the document's base URI, followed by a hash, followed by the attribute value. If $attributeType is the string 'about', then the URI is generated by treating the attribute like an 'about' attribute - i.e. it is treated as an absolute or relative URI, with safe CURIEs being allowed too. If the $attributeType is omitted, then the default behaviour is 'about'.
Calling this method with no parameters will disable the named graph feature. Named graphs are disabled by default.
- $p->thing_described_by(1)
-
RDF::RDFa::Parser
has a feature that allows it to use thing-described-by.org to create URIs for some blank nodes. It is disabled by default. This function can be used to turn it on (1) or off (0). May be called without a parameter, which just returns the current status. - $p->consume
-
The document is parsed for RDFa. Nothing of interest is returned by this function, but the triples extracted from the document are passed to the callbacks as each one is found.
- $p->graph
-
Returns a graph of all RDF triples found in a Perl structure close to RDF/JSON. http://n2.talis.com/wiki/RDF_JSON_Specification
SEE ALSO
RDF::RDFa::Parser::Trine, XML::LibXML.
http://buzzword.org.uk/swignition/rdfa
COPYRIGHT
Copyright 2008, 2009 Toby Inkster
This file is dual licensed under:
The Artistic License
GNU General Public License 3.0
You may choose which of those two licences you are going to honour the
terms of, but you cannot pick and choose the parts which you like of
each. You must fulfil the licensing requirements of at least one of the
two licenses.
The Artistic License
<http://www.perl.com/language/misc/Artistic.html>
GNU General Public License 3.0
<http://www.gnu.org/licenses/gpl-3.0.html>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
1 POD Error
The following errors were encountered while parsing the POD:
- Around line 1220:
'=item' outside of any '=over'