my $country = MyApp::Data::country->from_xml_file('/some/path/to/country.xml'); # retrieve from a file $country = MyApp::Data::country->from_xml_url('http://some/url/to/country.xml'); # or from a URL $country = MyApp::Data::country->from_xml_fh($fh); # or from a file handle $country = MyApp::Data::country->from_xml_dom($dom); # or from DOM (a XML::LibXML::Node or XML::LibXML::Document) # or from an XML string $country = MyApp::Data::country->from_xml_string(<<'EOF'); EOF # or if you don't know if you have a file, URL, FH, or string $country = MyApp::Data::country->from_xml('http://some/url/to/country.xml'); # Now you can manipulate your country object. print $country->name; # prints "France" print $country->city->[0]->name; # prints "Paris" # Let's make some changes $country->code('fr'); $country->name('FRANCE'); my $class=$country->xml_field_class('city'); my $city = $class->new(); $city->code('MRS'); $city->name('Marseille'); push @{$country->city}, $city; print $country->city->[2]->name; # prints "Marseille" # Time to validate our XML $country->xml_validate(); # This one will DIE on failure if ($country->is_xml_valid()) { # This one will not die. print "ok\n"; }else { print "Validation error : $@\n"; # Note that $@ contains the error message } # Time to write the the object back to XML $country->to_xml_file('some/path/to/country.xml'); # To a file $country->to_xml_url('http://some/url/to/country.xml'); # To a URL $country->to_xml_fh($fh); # To a FILE HANDLE my $dom=$country->to_xml_dom(); # To a DOM Node (XML::LibXML::Node) my $dom=$country->to_xml_dom_document(); # To a DOM Document (XML::LibXML::Document) my $xml=$country->to_xml_string(); # To a string my $frag=$country->to_xml_fragment(); # Same thing without the part