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 );

And somewhere in an other place of the code ... (Assuming a global XML element 'country' existed in you schema and hence been generated by Pastor).

my $country = MyApp::Data::country->from_xml_file('/some/path/to/cou +ntry.xml'); # retrieve from a file $country = MyApp::Data::country->from_xml_url('http://some/url/to/co +untry.xml'); # or from a URL $country = MyApp::Data::country->from_xml_fh($fh); # or from a f +ile handle $country = MyApp::Data::country->from_xml_dom($dom); # or from DO +M (a XML::LibXML::Node or XML::LibXML::Document) # or from an XML string $country = MyApp::Data::country->from_xml_string(<<'EOF'); <?xml version="1.0"?> <country code="FR" name="France"> <city code="PAR" name="Paris"/> <city code="LYO" name="Lyon"/> </country> 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/countr +y.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 erro +r message } # Time to write the the object back to XML $country->to_xml_file('some/path/to/country.xml'); # To a fil +e $country->to_xml_url('http://some/url/to/country.xml'); # To a UR +L $country->to_xml_fh($fh); # To a FILE HANDLE my $dom=$country->to_xml_dom(); # To a DOM Node (XML::Lib +XML::Node) my $dom=$country->to_xml_dom_document(); # To a DOM Document (XM +L::LibXML::Document) my $xml=$country->to_xml_string(); # To a string my $frag=$country->to_xml_fragment(); # Same thing without th +e <?xml version="1.0?> part

In reply to RFC: XML::Pastor v0.52 is released - A REVOLUTIONARY way to deal with XML by aulusoy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.