deprecated/buildtools/buildsystemtools/lib/XML/Checker/Parser.pm
author lorewang
Thu, 11 Nov 2010 11:26:32 +0800
changeset 677 44e49837144a
parent 655 3f65fd25dfd4
permissions -rw-r--r--
update release info
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
655
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     1
package XML::Checker::Parser;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     2
use strict;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     3
use XML::Parser;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     4
use XML::Checker;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     5
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     6
use vars qw( @ISA @InterceptedHandlers @SGML_SEARCH_PATH %URI_MAP
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     7
	     $_checker $_prevFAIL
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     8
	     $_Init $_Final $_Char $_Start $_End $_Element $_Attlist 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     9
	     $_Doctype $_Unparsed $_Notation $_Entity $_skipInsignifWS
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    10
	     $_EndOfDoc
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    11
	   );
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    12
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    13
@ISA = qw( XML::Parser );
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    14
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    15
@InterceptedHandlers = qw( Init Final Char Start End Element Attlist 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    16
			   Doctype Unparsed Notation Entity );
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    17
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    18
# Where to search for external DTDs (in local file system)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    19
@SGML_SEARCH_PATH = ();
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    20
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    21
# Where to search for external DTDs as referred to by public ID in a 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    22
# <!DOCTYPE ...> statement, e.g. "-//W3C//DTD HTML 4.0//EN"
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    23
# E.g. it could map "-//W3C//DTD HTML 4.0//EN" to "file:/user/html.dtd"
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    24
%URI_MAP = ();
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    25
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    26
sub new
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    27
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    28
    my ($class, %args) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    29
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    30
    my $super = new XML::Parser (%args);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    31
    $super->{Checker} = new XML::Checker (%args);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    32
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    33
    my %handlers = %{$super->{Handlers}};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    34
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    35
    # Don't need Comment handler - assuming comments are allowed anywhere
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    36
#?? What should Default handler do?
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    37
#?? Check XMLDecl, ExternEnt, Proc?  No, for now.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    38
#?? Add CdataStart, CdataEnd support?
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    39
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    40
    for (@InterceptedHandlers)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    41
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    42
	my $func = "XML::Checker::Parser::$_";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    43
	$handlers{$_} = \&$func;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    44
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    45
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    46
    $super->{UserHandlers} = $super->{Handlers};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    47
    $super->{Handlers} = \%handlers;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    48
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    49
    bless $super, $class;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    50
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    51
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    52
sub getChecker
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    53
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    54
    $_[0]->{Checker}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    55
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    56
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    57
sub parse
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    58
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    59
    my $self = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    60
    my $uh = $self->{UserHandlers};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    61
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    62
    local $_checker = $self->{Checker};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    63
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    64
    local $_Init = $uh->{Init};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    65
    local $_Final = $uh->{Final};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    66
    local $_Start = $uh->{Start};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    67
    local $_End = $uh->{End};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    68
    local $_Char = $uh->{Char};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    69
    local $_Element = $uh->{'Element'};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    70
    local $_Attlist = $uh->{'Attlist'};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    71
    local $_Doctype = $uh->{Doctype};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    72
    local $_Unparsed = $uh->{Unparsed};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    73
    local $_Notation = $uh->{Notation};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    74
    local $_Entity = $uh->{Entity};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    75
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    76
    local $_prevFAIL = $XML::Checker::FAIL;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    77
    local $XML::Checker::FAIL = \&fail_add_context;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    78
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    79
    local $XML::Checker::INSIGNIF_WS = 0;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    80
    local $_skipInsignifWS = $self->{SkipInsignifWS};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    81
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    82
    local $_EndOfDoc = 0;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    83
    
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    84
    $self->SUPER::parse (@_);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    85
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    86
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    87
my $LWP_USER_AGENT;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    88
sub set_LWP_UserAgent	# static
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    89
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    90
    $LWP_USER_AGENT = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    91
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    92
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    93
sub load_URL		# static
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    94
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    95
    my ($url, $lwp_user_agent) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    96
    my $result;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    97
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    98
    # Read the file from the web with LWP.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    99
    #
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   100
    # Note that we read in the entire file, which may not be ideal
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   101
    # for large files. LWP::UserAgent also provides a callback style
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   102
    # request, which we could convert to a stream with a fork()...
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   103
    
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   104
    my $response;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   105
    eval
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   106
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   107
	use LWP::UserAgent;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   108
	
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   109
	my $ua = $lwp_user_agent;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   110
	unless (defined $ua)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   111
	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   112
	    unless (defined $LWP_USER_AGENT)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   113
	    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   114
		$LWP_USER_AGENT = LWP::UserAgent->new;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   115
		
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   116
		# Load proxy settings from environment variables, i.e.:
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   117
		# http_proxy, ftp_proxy, no_proxy etc. (see LWP::UserAgent(3))
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   118
		# You need these to go thru firewalls.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   119
		$LWP_USER_AGENT->env_proxy;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   120
	    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   121
	    $ua = $LWP_USER_AGENT;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   122
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   123
	my $req = new HTTP::Request 'GET', $url;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   124
	$response = $LWP_USER_AGENT->request ($req);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   125
	$result = $response->content;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   126
    };
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   127
    if ($@)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   128
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   129
	die "Couldn't load URL [$url] with LWP: $@";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   130
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   131
    if (!$result)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   132
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   133
	my $message = $response->as_string;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   134
	die "Couldn't load URL [$url] with LWP: $message";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   135
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   136
    return $result;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   137
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   138
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   139
sub parsefile
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   140
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   141
    my $self = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   142
    my $url = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   143
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   144
    # Any other URL schemes?
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   145
    if ($url =~ /^(https?|ftp|wais|gopher|file):/)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   146
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   147
	my $xml = load_URL ($url, $self->{LWP_UserAgent});
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   148
	my $result;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   149
	eval
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   150
	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   151
	    # Parse the result of the HTTP request
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   152
	    $result = $self->parse ($xml, @_);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   153
	};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   154
	if ($@)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   155
	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   156
	    die "Couldn't parsefile [$url]: $@";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   157
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   158
	return $result;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   159
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   160
    else
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   161
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   162
	return $self->SUPER::parsefile ($url, @_);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   163
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   164
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   165
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   166
sub Init
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   167
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   168
    my $expat = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   169
    $_checker->{Expat} = $expat;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   170
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   171
    $_checker->Init (@_);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   172
    &$_Init ($expat) if $_Init;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   173
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   174
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   175
sub Final
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   176
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   177
    my $expat = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   178
    $_EndOfDoc = 1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   179
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   180
    $_checker->Final (@_);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   181
    my $result = &$_Final ($expat) if $_Final;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   182
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   183
    # Decouple Expat from Checker
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   184
    delete $_checker->{Expat};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   185
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   186
    # NOTE: Checker is not decoupled
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   187
    return $result;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   188
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   189
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   190
sub Start
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   191
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   192
    my ($expat, $tag, @attr) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   193
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   194
    $_checker->Start ($tag);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   195
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   196
    my $num_spec = $expat->specified_attr;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   197
    for (my $i = 0; $i < @attr; $i++)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   198
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   199
	my $spec = ($i < $num_spec);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   200
	my $attr = $attr[$i];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   201
	my $val = $attr[++$i];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   202
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   203
#	print "--- $tag $attr $val $spec\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   204
	$_checker->Attr ($tag, $attr, $val, $spec);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   205
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   206
    $_checker->EndAttr;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   207
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   208
    &$_Start ($expat, $tag, @attr) if $_Start;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   209
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   210
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   211
sub End
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   212
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   213
    my $expat = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   214
    $_checker->End (@_);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   215
    &$_End ($expat, @_) if $_End;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   216
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   217
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   218
sub Char
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   219
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   220
    my $expat = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   221
    $_checker->Char (@_);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   222
    &$_Char ($expat, @_) 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   223
	if $_Char && !($XML::Checker::INSIGNIF_WS && $_skipInsignifWS);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   224
    # Skip insignificant whitespace
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   225
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   226
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   227
sub Element
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   228
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   229
    my $expat = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   230
    $_checker->Element (@_);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   231
    &$_Element ($expat, @_) if $_Element;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   232
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   233
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   234
sub Attlist
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   235
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   236
    my $expat = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   237
    $_checker->Attlist (@_);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   238
    &$_Attlist ($expat, @_) if $_Attlist;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   239
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   240
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   241
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   242
sub Doctype
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   243
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   244
    my $expat = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   245
    my ($name, $sysid, $pubid, $internal) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   246
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   247
    my $dtd;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   248
    unless ($_checker->{SkipExternalDTD}) 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   249
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   250
	if ($sysid)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   251
	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   252
	    # External DTD...
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   253
	    
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   254
	    #?? I'm not sure if we should die here or keep going?	    
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   255
	    $dtd = load_DTD ($sysid, $expat->{LWP_UserAgent});
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   256
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   257
	elsif ($pubid)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   258
	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   259
	    $dtd = load_DTD ($pubid, $expat->{LWP_UserAgent});
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   260
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   261
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   262
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   263
    if (defined $dtd)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   264
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   265
#?? what about passing ProtocolEncoding, Namespaces, Stream_Delimiter ?
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   266
	my $parser = new XML::Parser (
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   267
	    Checker => $_checker, 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   268
	    ErrorContext => $expat->{ErrorContext},
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   269
	    Handlers => { 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   270
		Entity => \&XML::Checker::Parser::ExternalDTD::Entity,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   271
		Notation => \&XML::Checker::Parser::ExternalDTD::Notation,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   272
		Element => \&XML::Checker::Parser::ExternalDTD::Element,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   273
		Attlist => \&XML::Checker::Parser::ExternalDTD::Attlist,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   274
		Unparsed => \&XML::Checker::Parser::ExternalDTD::Unparsed,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   275
	    });
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   276
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   277
	eval 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   278
	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   279
	    $parser->parse ("<!DOCTYPE $name SYSTEM '$sysid' [\n$dtd\n]>\n<$name/>");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   280
	};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   281
	if ($@)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   282
	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   283
	    die "Couldn't parse contents of external DTD <$sysid> :$@";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   284
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   285
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   286
    $_checker->Doctype (@_);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   287
    &$_Doctype ($expat, @_) if $_Doctype;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   288
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   289
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   290
sub Unparsed
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   291
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   292
    my $expat = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   293
    $_checker->Unparsed (@_);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   294
    &$_Unparsed ($expat, @_) if $_Unparsed;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   295
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   296
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   297
sub Entity
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   298
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   299
    my $expat = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   300
    $_checker->Entity (@_);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   301
    &$_Entity ($expat, @_) if $_Entity;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   302
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   303
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   304
sub Notation
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   305
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   306
    my $expat = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   307
    $_checker->Notation (@_);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   308
    &$_Notation ($expat, @_) if $_Notation;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   309
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   310
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   311
sub Default
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   312
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   313
#?? what can I check here?
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   314
#    print "Default handler got[" . join (", ", @_) . "]";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   315
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   316
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   317
#sub XMLDecl
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   318
#{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   319
#?? support later?
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   320
#}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   321
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   322
sub setHandlers
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   323
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   324
    my ($self, %h) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   325
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   326
    for my $name (@InterceptedHandlers)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   327
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   328
	if (exists $h{$name})
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   329
	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   330
	    eval "\$_$name = \$h{$name}";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   331
	    delete $h{$name};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   332
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   333
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   334
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   335
    # Pass remaining handlers to the parent class (XML::Parser)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   336
    $self->SUPER::setHandlers (%h);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   337
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   338
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   339
# Add (line, column, byte) to error context (unless it's EOF)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   340
sub fail_add_context	# static
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   341
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   342
    my $e = $_checker->{Expat};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   343
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   344
    my $byte = $e->current_byte;	# -1 means: end of XML document
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   345
    if ($byte != -1 && !$_EndOfDoc)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   346
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   347
	push @_, (line => $e->current_line, 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   348
		  column => $e->current_column, 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   349
		  byte => $byte);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   350
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   351
    &$_prevFAIL (@_);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   352
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   353
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   354
#-------- STATIC METHODS related to External DTDs ---------------------------
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   355
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   356
sub load_DTD		# static
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   357
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   358
    my ($sysid, $lwp_user_agent) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   359
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   360
    # See if it is defined in the %URI_MAP
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   361
    # (Public IDs are stored here, e.g. "-//W3C//DTD HTML 4.0//EN")
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   362
    if (exists $URI_MAP{$sysid})
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   363
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   364
	$sysid = $URI_MAP{$sysid};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   365
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   366
    elsif ($sysid !~ /^\w+:/) 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   367
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   368
	# Prefix the sysid with 'file:' if it has no protocol identifier
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   369
	unless ($sysid =~ /^\//) 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   370
	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   371
	    # Not an absolute path. See if it's in SGML_SEARCH_PATH.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   372
	    my $relative_sysid = $sysid;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   373
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   374
	    $sysid = find_in_sgml_search_path ($sysid);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   375
	    if (! $sysid) 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   376
	    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   377
		if ($ENV{'SGML_SEARCH_PATH'}) 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   378
		{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   379
		    die "Couldn't find external DTD [$relative_sysid] in SGML_SEARCH_PATH ($ENV{'SGML_SEARCH_PATH'})";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   380
		}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   381
		else 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   382
		{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   383
		    die "Couldn't find external DTD [$relative_sysid], may be you should set SGML_SEARCH_PATH";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   384
		}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   385
	    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   386
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   387
	$sysid = "file:$sysid";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   388
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   389
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   390
    return load_URL ($sysid, $lwp_user_agent);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   391
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   392
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   393
sub map_uri			# static
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   394
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   395
    %URI_MAP = (%URI_MAP, @_);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   396
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   397
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   398
sub set_sgml_search_path	# static
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   399
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   400
    @SGML_SEARCH_PATH = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   401
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   402
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   403
sub find_in_sgml_search_path	# static
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   404
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   405
    my $file = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   406
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   407
    my @dirs = @SGML_SEARCH_PATH;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   408
    unless (@dirs)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   409
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   410
	my $path = $ENV{SGML_SEARCH_PATH};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   411
	if ($path)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   412
	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   413
	    @dirs = split (':', $path);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   414
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   415
	else
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   416
	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   417
	    my $home = $ENV{HOME};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   418
	    @dirs = (".", "$home/.sgml", "/usr/lib/sgml", "/usr/share/sgml");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   419
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   420
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   421
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   422
    for my $directory (@dirs) 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   423
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   424
	if (-e "$directory/$file") 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   425
	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   426
	    return "$directory/$file";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   427
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   428
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   429
    return undef;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   430
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   431
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   432
package XML::Checker::Parser::ExternalDTD;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   433
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   434
sub Element {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   435
	my $expat = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   436
	$expat->{Checker}->Element(@_);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   437
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   438
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   439
sub Attlist {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   440
	my $expat = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   441
	$expat->{Checker}->Attlist(@_);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   442
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   443
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   444
sub Unparsed {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   445
	my $expat = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   446
	$expat->{Checker}->Unparsed(@_);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   447
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   448
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   449
sub Notation {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   450
	my $expat = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   451
	$expat->{Checker}->Notation(@_);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   452
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   453
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   454
sub Entity {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   455
	my $expat = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   456
#	print "Entity: $expat\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   457
	$expat->{Checker}->Entity(@_);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   458
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   459
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   460
1; # package return code
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   461
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   462
__END__
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   463
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   464
=head1 NAME
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   465
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   466
XML::Checker::Parser - an XML::Parser that validates at parse time
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   467
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   468
=head1 SYNOPSIS
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   469
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   470
 use XML::Checker::Parser;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   471
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   472
 my %expat_options = (KeepCDATA => 1, 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   473
		      Handlers => [ Unparsed => \&my_Unparsed_handler ]);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   474
 my $parser = new XML::Checker::Parser (%expat_options);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   475
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   476
 eval {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   477
     local $XML::Checker::FAIL = \&my_fail;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   478
     $parser->parsefile ("fail.xml");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   479
 };
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   480
 if ($@) {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   481
     # Either XML::Parser (expat) threw an exception or my_fail() died.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   482
     ... your error handling code here ...
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   483
 }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   484
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   485
 # Throws an exception (with die) when an error is encountered, this
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   486
 # will stop the parsing process.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   487
 # Don't die if a warning or info message is encountered, just print a message.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   488
 sub my_fail {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   489
     my $code = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   490
     die XML::Checker::error_string ($code, @_) if $code < 200;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   491
     XML::Checker::print_error ($code, @_);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   492
 }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   493
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   494
=head1 DESCRIPTION
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   495
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   496
XML::Checker::Parser extends L<XML::Parser>
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   497
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   498
I hope the example in the SYNOPSIS says it all, just use 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   499
L<XML::Checker::Parser> as if it were an XML::Parser. 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   500
See L<XML::Parser> for the supported (expat) options.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   501
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   502
You can also derive your parser from XML::Checker::Parser instead of 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   503
from XML::Parser. All you should have to do is replace:
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   504
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   505
 package MyParser;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   506
 @ISA = qw( XML::Parser );
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   507
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   508
with:
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   509
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   510
 package MyParser;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   511
 @ISA = qw( XML::Checker::Parser );
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   512
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   513
=head1 XML::Checker::Parser constructor
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   514
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   515
 $parser = new XML::Checker::Parser (SkipExternalDTD => 1, SkipInsignifWS => 1);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   516
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   517
The constructor takes the same parameters as L<XML::Parser> with the following additions:
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   518
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   519
=over 4
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   520
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   521
=item SkipExternalDTD
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   522
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   523
By default, it will try to load external DTDs using LWP. You can disable this
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   524
by setting SkipExternalDTD to 1. See L<External DTDs|"External DTDs"> for details.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   525
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   526
=item SkipInsignifWS
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   527
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   528
By default, it will treat insignificant whitespace as regular Char data.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   529
By setting SkipInsignifWS to 1, the user Char handler will not be called
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   530
if insignificant whitespace is encountered. 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   531
See L<XML::Checker/INSIGNIFICANT_WHITESPACE> for details.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   532
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   533
=item LWP_UserAgent
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   534
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   535
When calling parsefile() with a URL (instead of a filename) or when loading
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   536
external DTDs, we use LWP to download the
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   537
remote file. By default it will use a L<LWP::UserAgent> that is created as follows:
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   538
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   539
 use LWP::UserAgent;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   540
 $LWP_USER_AGENT = LWP::UserAgent->new;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   541
 $LWP_USER_AGENT->env_proxy;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   542
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   543
Note that L<env_proxy> reads proxy settings from your environment variables, 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   544
which is what I need to do to get thru our firewall. 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   545
If you want to use a different LWP::UserAgent, you can either set
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   546
it globally with:
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   547
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   548
 XML::Checker::Parser::set_LWP_UserAgent ($my_agent);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   549
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   550
or, you can specify it for a specific XML::Checker::Parser by passing it to 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   551
the constructor:
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   552
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   553
 my $parser = new XML::Checker::Parser (LWP_UserAgent => $my_agent);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   554
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   555
Currently, LWP is used when the filename (passed to parsefile) starts with one of
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   556
the following URL schemes: http, https, ftp, wais, gopher, or file 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   557
(followed by a colon.) If I missed one, please let me know. 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   558
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   559
The LWP modules are part of libwww-perl which is available at CPAN.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   560
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   561
=back
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   562
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   563
=head1 External DTDs
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   564
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   565
XML::Checker::Parser will try to load and parse external DTDs that are 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   566
referenced in DOCTYPE definitions unless you set the B<SkipExternalDTD>
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   567
option to 1 (the default setting is 0.) 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   568
See L<CAVEATS|"CAVEATS"> for details on what is not supported by XML::Checker::Parser.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   569
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   570
L<XML::Parser> (version 2.27 and up) does a much better job at reading external 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   571
DTDs, because recently external DTD parsing was added to expat.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   572
Make sure you set the L<XML::Parser> option B<ParseParamEnt> to 1 and the 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   573
XML::Checker::Parser option B<SkipExternalDTD> to 1. 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   574
(They can both be set in the XML::Checker::Parser constructor.)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   575
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   576
When external DTDs are parsed by XML::Checker::Parser, they are
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   577
located in the following order:
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   578
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   579
=over 4
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   580
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   581
=item *
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   582
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   583
With the %URI_MAP, which can be set using B<map_uri>.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   584
This hash maps external resource ids (like system ID's and public ID's)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   585
to full path URI's.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   586
It was meant to aid in resolving PUBLIC IDs found in DOCTYPE declarations 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   587
after the PUBLIC keyword, e.g.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   588
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   589
  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   590
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   591
However, you can also use this to force L<XML::Checker> to read DTDs from a
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   592
different URL than was specified (e.g. from the local file system for
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   593
performance reasons.)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   594
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   595
=item * 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   596
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   597
on the Internet, if their system identifier starts with a protocol 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   598
(like http://...)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   599
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   600
=item *
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   601
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   602
on the local disk, if their system identifier starts with a slash 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   603
(absolute path)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   604
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   605
=item *
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   606
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   607
in the SGML_SEARCH_PATH, if their system identifier is a 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   608
relative file name. It will use @SGML_SEARCH_PATH if it was set with
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   609
B<set_sgml_search_path()>, or the colon-separated $ENV{SGML_SEARCH_PATH},
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   610
or (if that isn't set) the list (".", "$ENV{'HOME'}/.sgml", "/usr/lib/sgml",
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   611
"/usr/share/sgml"), which includes the
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   612
current directory, so it should do the right thing in most cases.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   613
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   614
=back
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   615
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   616
=head2 Static methods related to External DTDs
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   617
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   618
=over 4
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   619
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   620
=item set_sgml_search_path (dir1, dir2, ...)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   621
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   622
External DTDs with relative file paths are looked up using the @SGML_SEARCH_PATH,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   623
which can be set with this method. If @SGML_SEARCH_PATH is never set, it
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   624
will use the colon-separated $ENV{SGML_SEARCH_PATH} instead. If neither are set
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   625
it uses the list: ".", "$ENV{'HOME'}/.sgml", "/usr/lib/sgml",
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   626
"/usr/share/sgml".
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   627
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   628
set_sgml_search_path is a static method.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   629
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   630
=item map_uri (pubid => uri, ...)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   631
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   632
To define the location of PUBLIC ids, as found in DOCTYPE declarations 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   633
after the PUBLIC keyword, e.g.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   634
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   635
  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   636
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   637
call this method, e.g.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   638
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   639
  XML::Checker::Parser::map_uri (
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   640
	"-//W3C//DTD HTML 4.0//EN" => "file:/user/html.dtd");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   641
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   642
See L<External DTDs|"External DTDs"> for more info.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   643
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   644
XML::Checker::Parser::map_uri is a static method.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   645
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   646
=back
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   647
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   648
=head1 Switching user handlers at parse time
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   649
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   650
You should be able to use setHandlers() just as in L<XML::Parser>.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   651
(Using setHandlers has not been tested yet.)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   652
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   653
=head1 Error handling
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   654
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   655
XML::Checker::Parser routes the fail handler through 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   656
XML::Checker::Parser::fail_add_context() before calling your fail handler
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   657
(i.e. the global fail handler: $XML::Checker::FAIL. 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   658
See L<XML::Checker/ERROR_HANDLING>.)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   659
It adds the (line, column, byte) information from L<XML::Parser> to the 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   660
error context (unless it was the end of the XML document.)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   661
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   662
=head1 Supported XML::Parser handlers
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   663
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   664
Only the following L<XML::Parser> handlers are currently routed through
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   665
L<XML::Checker>: Init, Final, Char, Start, End, Element, Attlist, Doctype,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   666
Unparsed, Notation.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   667
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   668
=head1 CAVEATS
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   669
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   670
When using XML::Checker::Parser to parse external DTDs 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   671
(i.e. with SkipExternalDTD => 0),
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   672
expect trouble when your external DTD contains parameter entities inside 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   673
declarations or conditional sections. The external DTD should probably have
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   674
the same encoding as the orignal XML document.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   675
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   676
=head1 AUTHOR
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   677
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   678
Send bug reports, hints, tips, suggestions to Enno Derksen at
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   679
<F<enno@att.com>>.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   680
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   681
=head1 SEE ALSO
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   682
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   683
L<XML::Checker> (L<XML::Checker/SEE_ALSO>), L<XML::Parser>