Author image James A. Duncan
and 1 contributors


XML::DOMBacked - objects backed by a DOM


  package Person;

  use base 'XML::DOMBacked';

                         'foaf' => '',
                         'rdf'  => '',
  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->name('A. N. Other');

  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.


uses_namespace( prefix => uri )

Adds an XML namespace to the object.

has_properties( ARRAY )

Adds XML Elements to the object. These become accessors.

has_attributes( ARRAY )

Adds XML Attributes to the object. These become accessors.

has_a( ARRAY )

Adds 1..1 relationships with other classes to the object. The other classes must also inherit from XML::DOMBacked.

has_many( PLURAL => SINGULAR )

Adds add_SINGULAR, remove_SINGLUAR and PLURAL methods to the class.

has_many( PLURAL => { class => 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 <>


Copyright 2005 Fotango Ltd. All Rights Reserved.