Exactly!

It just seems like a logical abstraction that i find it hard to believe that someone hasn't done it before. either that, or i am missing something.

I mean, it seems facile to come up with a very basic DTD which only specified column names and a series of regexps which that column data must match in order to be accepted.

Of course, this only allows 'intra' data checking; there is still the 'inter'-data checking - looking up external databases to see if X has been entered before etc etc...

either way, being able to specify column data semantics in an external file certainly has it's virtues -- it would be such a simple thing to wrap this in an object:

package SyntaxChecker; our $Column_Definitions = {}; BEGIN { load_definitions(); } sub new { my $proto = shift; my $column_name = shift || die; my $class = ref $proto || $proto; my $this = { column_name => $column_name, column_definition => $class->_get_definition( $column_name ), regexp => [ $class->_get_regexps( $column_name) ], regexp_cache => [], }; return $this; } sub get_cached_regexps { my $this = shift; return @{ $this->{'regexp_cache'} }; } sub validate { my $this = shift; my $input_data = shift || die; my $matched; if ( my @regexps = $this->_get_cached_regexps() ) { foreach my $regexp_sub ( @regexps ) { $regexp_sub->( $input_data ) || die $this->{'column_definition'}; $matched++; } } else { foreach my $regexp ( @{$this->{'regexp'}} ) { my $code = eval "sub{ $input_data =~ $regexp }"; push @{ $this->{'regexp_cache'} }, $code; } return $this->validate( $input_data ); } return $matched; }

ok, so it's not a complete module -- no error checks or accessors or xml loading/parsing, but that took me all of 20 minutes, so a complete version wouldn't be much extra...

just need a good DTD for the xml description... any takers???

d_i_r_t_y


In reply to Re: Re: Re: representing database schema in XML by d_i_r_t_y
in thread representing database schema in XML by d_i_r_t_y

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.