use XML::Pastor; my $pastor = XML::Pastor->new(); # Generate MULTIPLE modules, one module for each class, and put them under destination. $pastor->generate( mode =>'offline', style => 'multiple', schema=>'/some/path/to/schema.xsd', class_prefix=>'MyApp::Data::', destination=>'/tmp/lib/perl/', ); # Generate a SINGLE module which contains all the classes and put it under destination. # Note that the schema may be read from a URL too. $pastor->generate( mode =>'offline', style => 'single', schema=>'http://some/url/to/schema.xsd', class_prefix=>'MyApp::Data::', module => 'Module', destination=>'/tmp/lib/perl/', ); # Generate classes in MEMORY, and EVALUATE the generated code on the fly. # (Run Time code generation) $pastor->generate( mode =>'eval', schema=>'/some/path/to/schema.xsd', class_prefix=>'MyApp::Data::' ); # Same thing, with a maximum of DEBUG output on STDERR $pastor->generate( mode =>'eval', schema=>'/some/path/to/schema.xsd', class_prefix=>'MyApp::Data::', verbose = 9 ); #### 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