| XML-DOMBacked documentation | view source | Contained in the XML-DOMBacked distribution. |
XML::DOMBacked - objects backed by a DOM
package Person;
use base 'XML::DOMBacked';
Person->uses_namespace(
'foaf' => 'http://xmlns.com/foaf/0.1/',
'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
);
Person->has_properties( 'foaf:name','foaf:title','foaf:nick' );
Person->has_attributes( 'rdf:nodeID' );
Person->has_a( 'Person::Knows' );
sub nodename { "foaf:Person" }
package Person::Knows;
use base 'XML::DOMBacked';
Person::Knows->has_many( people => { class => 'Person' } );
package main;
my $p = Person->new;
$p->nodeID("me");
$p->name('A. N. Other');
$p->title('Mr');
$p->nick('another');
my $a = Person->new;
$a->name('Yet Another');
$p->Knows->add_Person( $a );
print $p->as_xml;
$p = Person->from_uri( 'file:person.xml' );
The XML::DOMBacked class lets you back an object on an XML DOM. Think of it as Class::DBI
for XML files. You can specifiy things you want to be properties (nodes), attributes, and
other objects. XML::DOMBacked takes care of the heavy lifting so that you don't have to.
Constructs a new object.
Loads an object from a URI. Expects XML at the other end.
Adds an XML namespace to the object.
Adds XML Elements to the object. These become accessors.
Adds XML Attributes to the object. These become accessors.
Adds 1..1 relationships with other classes to the object. The other classes must also inherit from XML::DOMBacked.
Adds add_SINGULAR, remove_SINGLUAR and PLURAL methods to the class.
Looks up the NODENAME for the class, then creates add_NODENAME, remove_NODENAME, and PLURAL methods to the class.
Probably loads. This is really funky, crazy code. I'd be surprised if there aren't bugs.
James A. Duncan <jduncan@fotango.com>
Copyright 2005 Fotango Ltd. All Rights Reserved.
| XML-DOMBacked documentation | view source | Contained in the XML-DOMBacked distribution. |