[Chicago-talk] Navigating an XSD

Jay Strauss me at heyjay.com
Fri Jan 23 06:45:58 PST 2015


Hi john thanks, right now I'm going to try mojo::Dom and see how that goes

Sent from my iPhone

> On Jan 23, 2015, at 8:23 AM, John Kristoff <jtk at depaul.edu> wrote:
> 
>> On Fri, Jan 23, 2015 at 05:12:06AM +0000, Jay Strauss wrote:
>> I have an XSD document like below.  I've been googling and cpan-ing,
>> but can't find what I need (i know there are lots of XML packages),
>> and I don't know how to parse it using regexs (reliably).  I just want
>> to read in this XSD and navigate it like a perl structure, and extract
>> field values like:
> [...]
>> Can anyone recommend a module or a method?
> 
> Hi Jay.  I have found some success using XML::Twig and XML::Writer for reading
> and writing respectively, for relatively simple, but large XML files.
> 
> With XML::Twig, you can give it handlers based on blocks, for instance,
> you're interested in.  For example:
> 
> my $t = XML::Twig->new(
>    twig_handlers => {
>        'person' => \&section,
>    },
> );
> $t->parsefile($xmlfile);
> 
> sub section {
>    my ( $t, $section ) = @_;
> 
>    # interested in a few elements within this section
>    do_something_with( $section->first_child_text('birthdate') );
>    do_somethingelse_with( $section->first_child_text('ssn') );
>    #
>    # ...
> 
>    # do not need that element again
>    $section->purge;
> 
>    return;
> }
> 
> See if that might work for you.
> 
> John
> _______________________________________________
> Chicago-talk mailing list
> Chicago-talk at pm.org
> http://mail.pm.org/mailman/listinfo/chicago-talk


More information about the Chicago-talk mailing list