• Login
  • Help/Guide
  • About Trac
  • Preferences
  • Wiki
  • Timeline
  • Roadmap
  • Browse Source
  • View Tickets
  • Search

Context Navigation

  • Last Change
  • Annotate
  • Revision Log

root/Xml/Working/analyzeElementsAndAttributes.pl

Revision 42, 2.2 kB (checked in by andrew, 19 months ago)

Changes after consultation.
Adding dummy example files - structure ok, not real data
Adding perl scripts to help with checking element/attribute names

  • Property svn:executable set to *
Line 
1#!/usr/bin/perl
2
3use strict;
4
5my @files = @ARGV;
6
7unless( @files ) {
8        print "usage: \n./analyzeElementsAndAttributes.pl *xsd\n";
9        exit;
10}
11
12print "Analyzing elements & attributes of files:\n\t".join( ', ', @files )."\n\n";
13my @elements;
14my @attributes;
15#my %elements;
16#my %attributes;
17my %elements_files;
18my %attributes_files;
19my %repeatedElements;
20
21foreach my $file (@files ) {
22        open( FILE, "< $file" )
23                or die "Couldn't open $file";
24        while( my $line = <FILE> ) {
25                chomp $line;
26                if( $line =~ m/<(xs:)?element[^>*?]name\s*=\s*"(\w+)"/o ) {
27                        push( @elements, $2 );
28                        push( @{ $elements_files{ $2 } }, $file );
29                        $repeatedElements{ $2 } = undef
30                                if( scalar( @{ $elements_files{ $2 } } ) > 1 );
31                } elsif( $line =~ m/<(xs:)?attribute[^>*?]name\s*=\s*"(\w+)"/o ) {
32                        push( @attributes, $2 );
33                        push( @{ $attributes_files{ $2 } }, $file );
34                }
35        }
36        close( FILE );
37}
38
39print "Elements and attributes with the same names:\n";
40my @el_and_attr = intersect( \@elements, \@attributes );
41foreach my $name ( @el_and_attr ) {
42        print "\t$name: (element in: ".
43                join( ', ', @{ $elements_files{ $name } } ).
44                " attribute in: ".
45                join( ', ', @{ $attributes_files{ $name } } ).
46                ")\n";
47}
48
49if( keys %repeatedElements ) {
50        print "Elements repeated more than once:\n";
51        foreach my $name ( keys %repeatedElements ) {
52                print "\t$name: (repeated in: ".
53                        join( ', ', @{ $elements_files{ $name } } ).
54                        ")\n";
55        }
56}
57
58sub unique {
59        my %a;
60        if( ( scalar( @_ ) eq 1 ) && ( ref( $_[0] ) eq 'ARRAY' ) ) {
61                %a = map{ $_ => undef} @{ $_[0] };
62        } else {
63                %a = map{ $_ => undef} @_;
64        }
65        return sort( keys %a );
66}
67
68sub setdiff {
69        my ($a_in, $b_in) = @_;
70        my %a = map{ $_ => undef} @$a_in;
71        my %b = map{ $_ => undef} @$b_in;
72        my @diff;
73        foreach ( keys %a ){
74                push( @diff, $_ )
75                        if( not exists( $b{ $_ } ) );
76        }
77        return sort( @diff );
78}
79
80sub listdiff {
81        my ($a_in, $b_in) = @_;
82        my %b = map{ $_ => undef} @$b_in;
83        my @diff;
84        foreach ( @$a_in ){
85                push( @diff, $_ )
86                        if( not exists( $b{ $_ } ) );
87        }
88        return sort( @diff );
89}
90
91sub intersect {
92        my ($a_in, $b_in) = @_;
93        my %a = map{ $_ => undef} @$a_in;
94        my %b = map{ $_ => undef} @$b_in;
95        my @intersect;
96        foreach ( keys %a ){
97                push( @intersect, $_ )
98                        if( exists( $b{ $_ } ) );
99        }
100        return sort( @intersect );
101}
Note: See TracBrowser for help on using the browser.

Download in other formats:

  • Plain Text
  • Original Format

Trac Powered

Powered by Trac 0.11
By Edgewall Software.

Visit the Trac open source project at
http://trac.edgewall.org/