deprecated/buildtools/buildsystemtools/lib/XML/DOM.pm
author lorewang
Wed, 01 Dec 2010 16:05:36 +0800
changeset 715 e0739b8406dd
parent 655 3f65fd25dfd4
permissions -rw-r--r--
Specify extenal tool with path
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
655
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     1
################################################################################
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     2
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     3
# Perl module: XML::DOM
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     4
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     5
# By Enno Derksen <enno@att.com>
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     6
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     7
################################################################################
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     8
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     9
# To do:
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    10
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    11
# * optimize Attr if it only contains 1 Text node to hold the value
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    12
# * fix setDocType!
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    13
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    14
# * BUG: setOwnerDocument - does not process default attr values correctly,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    15
#   they still point to the old doc.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    16
# * change Exception mechanism
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    17
# * maybe: more checking of sysId etc.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    18
# * NoExpand mode (don't know what else is useful)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    19
# * various odds and ends: see comments starting with "??"
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    20
# * normalize(1) could also expand CDataSections and EntityReferences
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    21
# * parse a DocumentFragment?
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    22
# * encoding support
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    23
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    24
######################################################################
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    25
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    26
######################################################################
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    27
package XML::DOM;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    28
######################################################################
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    29
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    30
use strict;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    31
use vars qw( $VERSION @ISA @EXPORT
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    32
	     $IgnoreReadOnly $SafeMode $TagStyle
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    33
	     %DefaultEntities %DecodeDefaultEntity
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    34
	   );
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    35
use Carp;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    36
use XML::RegExp;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    37
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    38
BEGIN
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    39
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    40
    require XML::Parser;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    41
    $VERSION = '1.27';
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    42
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    43
    my $needVersion = '2.23';
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    44
    die "need at least XML::Parser version $needVersion (current=${XML::Parser::VERSION})"
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    45
	unless $XML::Parser::VERSION >= $needVersion;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    46
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    47
    @ISA = qw( Exporter );
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    48
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    49
    # Constants for XML::DOM Node types
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    50
    @EXPORT = qw(
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    51
	     UNKNOWN_NODE
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    52
	     ELEMENT_NODE
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    53
	     ATTRIBUTE_NODE
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    54
	     TEXT_NODE
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    55
	     CDATA_SECTION_NODE
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    56
	     ENTITY_REFERENCE_NODE
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    57
	     ENTITY_NODE
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    58
	     PROCESSING_INSTRUCTION_NODE
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    59
	     COMMENT_NODE
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    60
	     DOCUMENT_NODE
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    61
	     DOCUMENT_TYPE_NODE
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    62
	     DOCUMENT_FRAGMENT_NODE
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    63
	     NOTATION_NODE
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    64
	     ELEMENT_DECL_NODE
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    65
	     ATT_DEF_NODE
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    66
	     XML_DECL_NODE
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    67
	     ATTLIST_DECL_NODE
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    68
	    );
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    69
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    70
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    71
#---- Constant definitions
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    72
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    73
# Node types
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    74
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    75
sub UNKNOWN_NODE                () { 0 }		# not in the DOM Spec
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    76
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    77
sub ELEMENT_NODE                () { 1 }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    78
sub ATTRIBUTE_NODE              () { 2 }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    79
sub TEXT_NODE                   () { 3 }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    80
sub CDATA_SECTION_NODE          () { 4 }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    81
sub ENTITY_REFERENCE_NODE       () { 5 }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    82
sub ENTITY_NODE                 () { 6 }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    83
sub PROCESSING_INSTRUCTION_NODE () { 7 }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    84
sub COMMENT_NODE                () { 8 }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    85
sub DOCUMENT_NODE               () { 9 }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    86
sub DOCUMENT_TYPE_NODE          () { 10}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    87
sub DOCUMENT_FRAGMENT_NODE      () { 11}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    88
sub NOTATION_NODE               () { 12}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    89
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    90
sub ELEMENT_DECL_NODE		() { 13 }	# not in the DOM Spec
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    91
sub ATT_DEF_NODE 		() { 14 }	# not in the DOM Spec
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    92
sub XML_DECL_NODE 		() { 15 }	# not in the DOM Spec
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    93
sub ATTLIST_DECL_NODE		() { 16 }	# not in the DOM Spec
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    94
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    95
%DefaultEntities = 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    96
(
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    97
 "quot"		=> '"',
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    98
 "gt"		=> ">",
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    99
 "lt"		=> "<",
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   100
 "apos"		=> "'",
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   101
 "amp"		=> "&"
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   102
);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   103
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   104
%DecodeDefaultEntity =
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   105
(
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   106
 '"' => "&quot;",
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   107
 ">" => "&gt;",
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   108
 "<" => "&lt;",
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   109
 "'" => "&apos;",
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   110
 "&" => "&amp;"
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   111
);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   112
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   113
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   114
# If you don't want DOM warnings to use 'warn', override this method like this:
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   115
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   116
# { # start block scope
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   117
#	local *XML::DOM::warning = \&my_warn;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   118
#	... your code here ...
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   119
# } # end block scope (old XML::DOM::warning takes effect again)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   120
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   121
sub warning	# static
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   122
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   123
    warn @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   124
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   125
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   126
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   127
# This method defines several things in the caller's package, so you can use named constants to
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   128
# access the array that holds the member data, i.e. $self->[_Data]. It assumes the caller's package
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   129
# defines a class that is implemented as a blessed array reference.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   130
# Note that this is very similar to using 'use fields' and 'use base'.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   131
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   132
# E.g. if $fields eq "Name Model", $parent eq "XML::DOM::Node" and
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   133
# XML::DOM::Node had "A B C" as fields and it was called from package "XML::DOM::ElementDecl",
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   134
# then this code would basically do the following:
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   135
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   136
# package XML::DOM::ElementDecl;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   137
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   138
# sub _Name  () { 3 }	# Note that parent class had three fields
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   139
# sub _Model () { 4 }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   140
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   141
# # Maps constant names (without '_') to constant (int) value
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   142
# %HFIELDS = ( %XML::DOM::Node::HFIELDS, Name => _Name, Model => _Model );
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   143
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   144
# # Define XML:DOM::ElementDecl as a subclass of XML::DOM::Node
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   145
# @ISA = qw{ XML::DOM::Node };
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   146
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   147
# # The following function names can be exported into the user's namespace.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   148
# @EXPORT_OK = qw{ _Name _Model };
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   149
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   150
# # The following function names can be exported into the user's namespace
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   151
# # with: import XML::DOM::ElementDecl qw( :Fields );
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   152
# %EXPORT_TAGS = ( Fields => qw{ _Name _Model } );
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   153
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   154
sub def_fields	# static
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   155
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   156
    my ($fields, $parent) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   157
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   158
    my ($pkg) = caller;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   159
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   160
    no strict 'refs';
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   161
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   162
    my @f = split (/\s+/, $fields);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   163
    my $n = 0;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   164
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   165
    my %hfields;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   166
    if (defined $parent)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   167
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   168
	my %pf = %{"$parent\::HFIELDS"};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   169
	%hfields = %pf;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   170
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   171
	$n = scalar (keys %pf);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   172
	@{"$pkg\::ISA"} = ( $parent );
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
    my $i = $n;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   176
    for (@f)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   177
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   178
	eval "sub $pkg\::_$_ () { $i }";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   179
	$hfields{$_} = $i;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   180
	$i++;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   181
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   182
    %{"$pkg\::HFIELDS"} = %hfields;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   183
    @{"$pkg\::EXPORT_OK"} = map { "_$_" } @f;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   184
    
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   185
    ${"$pkg\::EXPORT_TAGS"}{Fields} = [ map { "_$_" } @f ];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   186
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   187
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   188
# sub blesh
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   189
# {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   190
#     my $hashref = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   191
#     my $class = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   192
#     no strict 'refs';
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   193
#     my $self = bless [\%{"$class\::FIELDS"}], $class;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   194
#     if (defined $hashref)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   195
#     {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   196
# 	for (keys %$hashref)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   197
# 	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   198
# 	    $self->{$_} = $hashref->{$_};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   199
# 	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   200
#     }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   201
#     $self;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   202
# }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   203
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   204
# sub blesh2
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   205
# {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   206
#     my $hashref = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   207
#     my $class = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   208
#     no strict 'refs';
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   209
#     my $self = bless [\%{"$class\::FIELDS"}], $class;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   210
#     if (defined $hashref)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   211
#     {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   212
# 	for (keys %$hashref)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   213
# 	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   214
# 	    eval { $self->{$_} = $hashref->{$_}; };
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   215
# 	    croak "ERROR in field [$_] $@" if $@;
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
#     $self;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   219
#}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   220
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   221
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   222
# CDATA section may not contain "]]>"
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   223
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   224
sub encodeCDATA
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   225
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   226
    my ($str) = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   227
    $str =~ s/]]>/]]&gt;/go;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   228
    $str;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   229
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   230
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   231
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   232
# PI may not contain "?>"
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   233
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   234
sub encodeProcessingInstruction
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   235
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   236
    my ($str) = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   237
    $str =~ s/\?>/?&gt;/go;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   238
    $str;
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
#?? Not sure if this is right - must prevent double minus somehow...
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   243
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   244
sub encodeComment
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   245
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   246
    my ($str) = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   247
    return undef unless defined $str;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   248
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   249
    $str =~ s/--/&#45;&#45;/go;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   250
    $str;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   251
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   252
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   253
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   254
# For debugging
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   255
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   256
sub toHex
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   257
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   258
    my $str = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   259
    my $len = length($str);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   260
    my @a = unpack ("C$len", $str);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   261
    my $s = "";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   262
    for (@a)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   263
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   264
	$s .= sprintf ("%02x", $_);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   265
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   266
    $s;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   267
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   268
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   269
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   270
# 2nd parameter $default: list of Default Entity characters that need to be 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   271
# converted (e.g. "&<" for conversion to "&amp;" and "&lt;" resp.)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   272
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   273
sub encodeText
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   274
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   275
    my ($str, $default) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   276
    return undef unless defined $str;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   277
    
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   278
    $str =~ s/([\xC0-\xDF].|[\xE0-\xEF]..|[\xF0-\xFF]...)|([$default])|(]]>)/
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   279
	defined($1) ? XmlUtf8Decode ($1) : 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   280
	defined ($2) ? $DecodeDefaultEntity{$2} : "]]&gt;" /egs;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   281
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   282
#?? could there be references that should not be expanded?
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   283
# e.g. should not replace &#nn; &#xAF; and &abc;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   284
#    $str =~ s/&(?!($ReName|#[0-9]+|#x[0-9a-fA-F]+);)/&amp;/go;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   285
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   286
    $str;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   287
}
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
# Used by AttDef - default value
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   291
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   292
sub encodeAttrValue
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   293
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   294
    encodeText (shift, '"&<');
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
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   298
# Converts an integer (Unicode - ISO/IEC 10646) to a UTF-8 encoded character 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   299
# sequence.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   300
# Used when converting e.g. &#123; or &#x3ff; to a string value.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   301
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   302
# Algorithm borrowed from expat/xmltok.c/XmlUtf8Encode()
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   303
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   304
# not checking for bad characters: < 0, x00-x08, x0B-x0C, x0E-x1F, xFFFE-xFFFF
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   305
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   306
sub XmlUtf8Encode
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   307
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   308
    my $n = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   309
    if ($n < 0x80)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   310
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   311
	return chr ($n);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   312
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   313
    elsif ($n < 0x800)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   314
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   315
	return pack ("CC", (($n >> 6) | 0xc0), (($n & 0x3f) | 0x80));
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   316
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   317
    elsif ($n < 0x10000)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   318
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   319
	return pack ("CCC", (($n >> 12) | 0xe0), ((($n >> 6) & 0x3f) | 0x80),
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   320
		     (($n & 0x3f) | 0x80));
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   321
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   322
    elsif ($n < 0x110000)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   323
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   324
	return pack ("CCCC", (($n >> 18) | 0xf0), ((($n >> 12) & 0x3f) | 0x80),
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   325
		     ((($n >> 6) & 0x3f) | 0x80), (($n & 0x3f) | 0x80));
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   326
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   327
    croak "number is too large for Unicode [$n] in &XmlUtf8Encode";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   328
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   329
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   330
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   331
# Opposite of XmlUtf8Decode plus it adds prefix "&#" or "&#x" and suffix ";"
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   332
# The 2nd parameter ($hex) indicates whether the result is hex encoded or not.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   333
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   334
sub XmlUtf8Decode
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   335
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   336
    my ($str, $hex) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   337
    my $len = length ($str);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   338
    my $n;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   339
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   340
    if ($len == 2)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   341
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   342
	my @n = unpack "C2", $str;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   343
	$n = (($n[0] & 0x3f) << 6) + ($n[1] & 0x3f);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   344
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   345
    elsif ($len == 3)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   346
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   347
	my @n = unpack "C3", $str;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   348
	$n = (($n[0] & 0x1f) << 12) + (($n[1] & 0x3f) << 6) + 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   349
		($n[2] & 0x3f);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   350
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   351
    elsif ($len == 4)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   352
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   353
	my @n = unpack "C4", $str;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   354
	$n = (($n[0] & 0x0f) << 18) + (($n[1] & 0x3f) << 12) + 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   355
		(($n[2] & 0x3f) << 6) + ($n[3] & 0x3f);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   356
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   357
    elsif ($len == 1)	# just to be complete...
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   358
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   359
	$n = ord ($str);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   360
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   361
    else
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   362
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   363
	croak "bad value [$str] for XmlUtf8Decode";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   364
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   365
    $hex ? sprintf ("&#x%x;", $n) : "&#$n;";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   366
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   367
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   368
$IgnoreReadOnly = 0;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   369
$SafeMode = 1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   370
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   371
sub getIgnoreReadOnly
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   372
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   373
    $IgnoreReadOnly;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   374
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   375
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   376
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   377
# The global flag $IgnoreReadOnly is set to the specified value and the old 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   378
# value of $IgnoreReadOnly is returned.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   379
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   380
# To temporarily disable read-only related exceptions (i.e. when parsing
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   381
# XML or temporarily), do the following:
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   382
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   383
# my $oldIgnore = XML::DOM::ignoreReadOnly (1);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   384
# ... do whatever you want ...
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   385
# XML::DOM::ignoreReadOnly ($oldIgnore);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   386
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   387
sub ignoreReadOnly
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   388
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   389
    my $i = $IgnoreReadOnly;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   390
    $IgnoreReadOnly = $_[0];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   391
    return $i;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   392
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   393
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   394
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   395
# XML spec seems to break its own rules... (see ENTITY xmlpio)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   396
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   397
sub forgiving_isValidName
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   398
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   399
    $_[0] =~ /^$XML::RegExp::Name$/o;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   400
}
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
# Don't allow names starting with xml (either case)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   404
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   405
sub picky_isValidName
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   406
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   407
    $_[0] =~ /^$XML::RegExp::Name$/o and $_[0] !~ /^xml/i;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   408
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   409
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   410
# Be forgiving by default, 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   411
*isValidName = \&forgiving_isValidName;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   412
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   413
sub allowReservedNames		# static
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   414
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   415
    *isValidName = ($_[0] ? \&forgiving_isValidName : \&picky_isValidName);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   416
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   417
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   418
sub getAllowReservedNames	# static
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   419
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   420
    *isValidName == \&forgiving_isValidName;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   421
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   422
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   423
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   424
# Always compress empty tags by default
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   425
# This is used by Element::print.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   426
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   427
$TagStyle = sub { 0 };
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   428
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   429
sub setTagCompression
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   430
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   431
    $TagStyle = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   432
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   433
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   434
######################################################################
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   435
package XML::DOM::PrintToFileHandle;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   436
######################################################################
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
# Used by XML::DOM::Node::printToFileHandle
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   440
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   441
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   442
sub new
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   443
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   444
    my($class, $fn) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   445
    bless $fn, $class;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   446
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   447
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   448
sub print
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   449
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   450
    my ($self, $str) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   451
    print $self $str;
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
######################################################################
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   455
package XML::DOM::PrintToString;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   456
######################################################################
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   457
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   458
use vars qw{ $Singleton };
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   459
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   460
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   461
# Used by XML::DOM::Node::toString to concatenate strings
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   462
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   463
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   464
sub new
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   465
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   466
    my($class) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   467
    my $str = "";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   468
    bless \$str, $class;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   469
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   470
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   471
sub print
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   472
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   473
    my ($self, $str) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   474
    $$self .= $str;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   475
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   476
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   477
sub toString
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   478
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   479
    my $self = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   480
    $$self;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   481
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   482
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   483
sub reset
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   484
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   485
    ${$_[0]} = "";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   486
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   487
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   488
$Singleton = new XML::DOM::PrintToString;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   489
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   490
######################################################################
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   491
package XML::DOM::DOMImplementation;
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
$XML::DOM::DOMImplementation::Singleton =
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   495
  bless \$XML::DOM::DOMImplementation::Singleton, 'XML::DOM::DOMImplementation';
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   496
 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   497
sub hasFeature 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   498
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   499
    my ($self, $feature, $version) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   500
 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   501
    $feature eq 'XML' and $version eq '1.0';
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   502
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   503
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   504
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   505
######################################################################
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   506
package XML::XQL::Node;		# forward declaration
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   507
######################################################################
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   508
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   509
######################################################################
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   510
package XML::DOM::Node;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   511
######################################################################
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   512
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   513
use vars qw( @NodeNames @EXPORT @ISA %HFIELDS @EXPORT_OK @EXPORT_TAGS );
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   514
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   515
BEGIN 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   516
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   517
  use XML::DOM::DOMException;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   518
  import Carp;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   519
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   520
  require FileHandle;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   521
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   522
  @ISA = qw( Exporter XML::XQL::Node );
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   523
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   524
  # NOTE: SortKey is used in XML::XQL::Node. 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   525
  #       UserData is reserved for users (Hang your data here!)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   526
  XML::DOM::def_fields ("C A Doc Parent ReadOnly UsedIn Hidden SortKey UserData");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   527
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   528
  push (@EXPORT, qw(
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   529
		    UNKNOWN_NODE
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   530
		    ELEMENT_NODE
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   531
		    ATTRIBUTE_NODE
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   532
		    TEXT_NODE
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   533
		    CDATA_SECTION_NODE
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   534
		    ENTITY_REFERENCE_NODE
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   535
		    ENTITY_NODE
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   536
		    PROCESSING_INSTRUCTION_NODE
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   537
		    COMMENT_NODE
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   538
		    DOCUMENT_NODE
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   539
		    DOCUMENT_TYPE_NODE
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   540
		    DOCUMENT_FRAGMENT_NODE
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   541
		    NOTATION_NODE
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   542
		    ELEMENT_DECL_NODE
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   543
		    ATT_DEF_NODE
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   544
		    XML_DECL_NODE
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   545
		    ATTLIST_DECL_NODE
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   546
		   ));
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   547
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   548
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   549
#---- Constant definitions
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   550
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   551
# Node types
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   552
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   553
sub UNKNOWN_NODE                () {0;}		# not in the DOM Spec
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   554
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   555
sub ELEMENT_NODE                () {1;}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   556
sub ATTRIBUTE_NODE              () {2;}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   557
sub TEXT_NODE                   () {3;}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   558
sub CDATA_SECTION_NODE          () {4;}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   559
sub ENTITY_REFERENCE_NODE       () {5;}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   560
sub ENTITY_NODE                 () {6;}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   561
sub PROCESSING_INSTRUCTION_NODE () {7;}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   562
sub COMMENT_NODE                () {8;}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   563
sub DOCUMENT_NODE               () {9;}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   564
sub DOCUMENT_TYPE_NODE          () {10;}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   565
sub DOCUMENT_FRAGMENT_NODE      () {11;}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   566
sub NOTATION_NODE               () {12;}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   567
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   568
sub ELEMENT_DECL_NODE		() {13;}	# not in the DOM Spec
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   569
sub ATT_DEF_NODE 		() {14;}	# not in the DOM Spec
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   570
sub XML_DECL_NODE 		() {15;}	# not in the DOM Spec
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   571
sub ATTLIST_DECL_NODE		() {16;}	# not in the DOM Spec
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   572
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   573
@NodeNames = (
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   574
	      "UNKNOWN_NODE",	# not in the DOM Spec!
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   575
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   576
	      "ELEMENT_NODE",
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   577
	      "ATTRIBUTE_NODE",
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   578
	      "TEXT_NODE",
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   579
	      "CDATA_SECTION_NODE",
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   580
	      "ENTITY_REFERENCE_NODE",
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   581
	      "ENTITY_NODE",
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   582
	      "PROCESSING_INSTRUCTION_NODE",
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   583
	      "COMMENT_NODE",
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   584
	      "DOCUMENT_NODE",
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   585
	      "DOCUMENT_TYPE_NODE",
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   586
	      "DOCUMENT_FRAGMENT_NODE",
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   587
	      "NOTATION_NODE",
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   588
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   589
	      "ELEMENT_DECL_NODE",
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   590
	      "ATT_DEF_NODE",
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   591
	      "XML_DECL_NODE",
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   592
	      "ATTLIST_DECL_NODE"
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   593
	     );
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   594
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   595
sub decoupleUsedIn
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   596
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   597
    my $self = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   598
    undef $self->[_UsedIn]; # was delete
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   599
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   600
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   601
sub getParentNode
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   602
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   603
    $_[0]->[_Parent];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   604
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   605
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   606
sub appendChild
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   607
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   608
    my ($self, $node) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   609
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   610
    # REC 7473
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   611
    if ($XML::DOM::SafeMode)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   612
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   613
	croak new XML::DOM::DOMException (NO_MODIFICATION_ALLOWED_ERR,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   614
					  "node is ReadOnly")
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   615
	    if $self->isReadOnly;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   616
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   617
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   618
    my $doc = $self->[_Doc];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   619
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   620
    if ($node->isDocumentFragmentNode)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   621
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   622
	if ($XML::DOM::SafeMode)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   623
	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   624
	    for my $n (@{$node->[_C]})
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   625
	    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   626
		croak new XML::DOM::DOMException (WRONG_DOCUMENT_ERR,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   627
						  "nodes belong to different documents")
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   628
		    if $doc != $n->[_Doc];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   629
		
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   630
		croak new XML::DOM::DOMException (HIERARCHY_REQUEST_ERR,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   631
						  "node is ancestor of parent node")
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   632
		    if $n->isAncestor ($self);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   633
		
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   634
		croak new XML::DOM::DOMException (HIERARCHY_REQUEST_ERR,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   635
						  "bad node type")
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   636
		    if $self->rejectChild ($n);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   637
	    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   638
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   639
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   640
	my @list = @{$node->[_C]};	# don't try to compress this
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   641
	for my $n (@list)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   642
	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   643
	    $n->setParentNode ($self);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   644
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   645
	push @{$self->[_C]}, @list;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   646
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   647
    else
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   648
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   649
	if ($XML::DOM::SafeMode)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   650
	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   651
	    croak new XML::DOM::DOMException (WRONG_DOCUMENT_ERR,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   652
						  "nodes belong to different documents")
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   653
		if $doc != $node->[_Doc];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   654
		
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   655
	    croak new XML::DOM::DOMException (HIERARCHY_REQUEST_ERR,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   656
						  "node is ancestor of parent node")
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   657
		if $node->isAncestor ($self);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   658
		
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   659
	    croak new XML::DOM::DOMException (HIERARCHY_REQUEST_ERR,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   660
						  "bad node type")
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   661
		if $self->rejectChild ($node);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   662
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   663
	$node->setParentNode ($self);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   664
	push @{$self->[_C]}, $node;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   665
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   666
    $node;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   667
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   668
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   669
sub getChildNodes
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   670
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   671
    # NOTE: if node can't have children, $self->[_C] is undef.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   672
    my $kids = $_[0]->[_C];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   673
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   674
    # Return a list if called in list context.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   675
    wantarray ? (defined ($kids) ? @{ $kids } : ()) :
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   676
	        (defined ($kids) ? $kids : $XML::DOM::NodeList::EMPTY);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   677
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   678
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   679
sub hasChildNodes
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   680
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   681
    my $kids = $_[0]->[_C];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   682
    defined ($kids) && @$kids > 0;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   683
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   684
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   685
# This method is overriden in Document
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   686
sub getOwnerDocument
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   687
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   688
    $_[0]->[_Doc];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   689
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   690
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   691
sub getFirstChild
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   692
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   693
    my $kids = $_[0]->[_C];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   694
    defined $kids ? $kids->[0] : undef; 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   695
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   696
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   697
sub getLastChild
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   698
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   699
    my $kids = $_[0]->[_C];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   700
    defined $kids ? $kids->[-1] : undef; 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   701
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   702
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   703
sub getPreviousSibling
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   704
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   705
    my $self = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   706
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   707
    my $pa = $self->[_Parent];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   708
    return undef unless $pa;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   709
    my $index = $pa->getChildIndex ($self);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   710
    return undef unless $index;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   711
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   712
    $pa->getChildAtIndex ($index - 1);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   713
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   714
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   715
sub getNextSibling
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   716
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   717
    my $self = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   718
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   719
    my $pa = $self->[_Parent];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   720
    return undef unless $pa;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   721
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   722
    $pa->getChildAtIndex ($pa->getChildIndex ($self) + 1);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   723
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   724
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   725
sub insertBefore
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   726
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   727
    my ($self, $node, $refNode) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   728
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   729
    return $self->appendChild ($node) unless $refNode;	# append at the end
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   730
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   731
    croak new XML::DOM::DOMException (NO_MODIFICATION_ALLOWED_ERR,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   732
				      "node is ReadOnly")
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   733
	if $self->isReadOnly;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   734
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   735
    my @nodes = ($node);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   736
    @nodes = @{$node->[_C]}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   737
	if $node->getNodeType == DOCUMENT_FRAGMENT_NODE;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   738
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   739
    my $doc = $self->[_Doc];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   740
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   741
    for my $n (@nodes)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   742
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   743
	croak new XML::DOM::DOMException (WRONG_DOCUMENT_ERR,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   744
					  "nodes belong to different documents")
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   745
	    if $doc != $n->[_Doc];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   746
	
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   747
	croak new XML::DOM::DOMException (HIERARCHY_REQUEST_ERR,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   748
					  "node is ancestor of parent node")
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   749
	    if $n->isAncestor ($self);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   750
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   751
	croak new XML::DOM::DOMException (HIERARCHY_REQUEST_ERR,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   752
					  "bad node type")
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   753
	    if $self->rejectChild ($n);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   754
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   755
    my $index = $self->getChildIndex ($refNode);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   756
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   757
    croak new XML::DOM::DOMException (NOT_FOUND_ERR,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   758
				      "reference node not found")
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   759
	if $index == -1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   760
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   761
    for my $n (@nodes)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   762
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   763
	$n->setParentNode ($self);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   764
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   765
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   766
    splice (@{$self->[_C]}, $index, 0, @nodes);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   767
    $node;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   768
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   769
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   770
sub replaceChild
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   771
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   772
    my ($self, $node, $refNode) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   773
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   774
    croak new XML::DOM::DOMException (NO_MODIFICATION_ALLOWED_ERR,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   775
				      "node is ReadOnly")
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   776
	if $self->isReadOnly;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   777
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   778
    my @nodes = ($node);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   779
    @nodes = @{$node->[_C]}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   780
	if $node->getNodeType == DOCUMENT_FRAGMENT_NODE;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   781
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   782
    for my $n (@nodes)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   783
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   784
	croak new XML::DOM::DOMException (WRONG_DOCUMENT_ERR,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   785
					  "nodes belong to different documents")
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   786
	    if $self->[_Doc] != $n->[_Doc];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   787
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   788
	croak new XML::DOM::DOMException (HIERARCHY_REQUEST_ERR,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   789
					  "node is ancestor of parent node")
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   790
	    if $n->isAncestor ($self);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   791
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   792
	croak new XML::DOM::DOMException (HIERARCHY_REQUEST_ERR,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   793
					  "bad node type")
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   794
	    if $self->rejectChild ($n);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   795
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   796
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   797
    my $index = $self->getChildIndex ($refNode);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   798
    croak new XML::DOM::DOMException (NOT_FOUND_ERR,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   799
				      "reference node not found")
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   800
	if $index == -1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   801
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   802
    for my $n (@nodes)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   803
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   804
	$n->setParentNode ($self);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   805
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   806
    splice (@{$self->[_C]}, $index, 1, @nodes);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   807
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   808
    $refNode->removeChildHoodMemories;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   809
    $refNode;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   810
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   811
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   812
sub removeChild
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   813
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   814
    my ($self, $node) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   815
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   816
    croak new XML::DOM::DOMException (NO_MODIFICATION_ALLOWED_ERR,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   817
				      "node is ReadOnly")
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   818
	if $self->isReadOnly;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   819
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   820
    my $index = $self->getChildIndex ($node);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   821
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   822
    croak new XML::DOM::DOMException (NOT_FOUND_ERR,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   823
				      "reference node not found")
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   824
	if $index == -1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   825
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   826
    splice (@{$self->[_C]}, $index, 1, ());
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   827
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   828
    $node->removeChildHoodMemories;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   829
    $node;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   830
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   831
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   832
# Merge all subsequent Text nodes in this subtree
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   833
sub normalize
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   834
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   835
    my ($self) = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   836
    my $prev = undef;	# previous Text node
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   837
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   838
    return unless defined $self->[_C];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   839
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   840
    my @nodes = @{$self->[_C]};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   841
    my $i = 0;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   842
    my $n = @nodes;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   843
    while ($i < $n)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   844
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   845
	my $node = $self->getChildAtIndex($i);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   846
	my $type = $node->getNodeType;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   847
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   848
	if (defined $prev)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   849
	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   850
	    # It should not merge CDATASections. Dom Spec says:
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   851
	    #  Adjacent CDATASections nodes are not merged by use
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   852
	    #  of the Element.normalize() method.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   853
	    if ($type == TEXT_NODE)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   854
	    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   855
		$prev->appendData ($node->getData);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   856
		$self->removeChild ($node);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   857
		$i--;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   858
		$n--;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   859
	    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   860
	    else
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   861
	    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   862
		$prev = undef;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   863
		if ($type == ELEMENT_NODE)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   864
		{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   865
		    $node->normalize;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   866
		    if (defined $node->[_A])
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   867
		    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   868
			for my $attr (@{$node->[_A]->getValues})
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   869
			{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   870
			    $attr->normalize;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   871
			}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   872
		    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   873
		}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   874
	    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   875
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   876
	else
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   877
	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   878
	    if ($type == TEXT_NODE)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   879
	    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   880
		$prev = $node;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   881
	    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   882
	    elsif ($type == ELEMENT_NODE)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   883
	    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   884
		$node->normalize;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   885
		if (defined $node->[_A])
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   886
		{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   887
		    for my $attr (@{$node->[_A]->getValues})
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   888
		    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   889
			$attr->normalize;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   890
		    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   891
		}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   892
	    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   893
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   894
	$i++;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   895
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   896
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   897
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   898
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   899
# Return all Element nodes in the subtree that have the specified tagName.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   900
# If tagName is "*", all Element nodes are returned.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   901
# NOTE: the DOM Spec does not specify a 3rd or 4th parameter
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   902
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   903
sub getElementsByTagName
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   904
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   905
    my ($self, $tagName, $recurse, $list) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   906
    $recurse = 1 unless defined $recurse;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   907
    $list = (wantarray ? [] : new XML::DOM::NodeList) unless defined $list;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   908
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   909
    return unless defined $self->[_C];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   910
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   911
    # preorder traversal: check parent node first
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   912
    for my $kid (@{$self->[_C]})
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   913
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   914
	if ($kid->isElementNode)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   915
	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   916
	    if ($tagName eq "*" || $tagName eq $kid->getTagName)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   917
	    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   918
		push @{$list}, $kid;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   919
	    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   920
	    $kid->getElementsByTagName ($tagName, $recurse, $list) if $recurse;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   921
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   922
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   923
    wantarray ? @{ $list } : $list;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   924
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   925
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   926
sub getNodeValue
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   927
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   928
    undef;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   929
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   930
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   931
sub setNodeValue
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   932
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   933
    # no-op
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   934
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   935
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   936
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   937
# Redefined by XML::DOM::Element
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   938
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   939
sub getAttributes
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   940
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   941
    undef;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   942
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   943
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   944
#------------------------------------------------------------
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   945
# Extra method implementations
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   946
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   947
sub setOwnerDocument
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   948
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   949
    my ($self, $doc) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   950
    $self->[_Doc] = $doc;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   951
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   952
    return unless defined $self->[_C];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   953
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   954
    for my $kid (@{$self->[_C]})
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   955
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   956
	$kid->setOwnerDocument ($doc);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   957
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   958
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   959
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   960
sub cloneChildren
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   961
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   962
    my ($self, $node, $deep) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   963
    return unless $deep;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   964
    
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   965
    return unless defined $self->[_C];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   966
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   967
    local $XML::DOM::IgnoreReadOnly = 1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   968
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   969
    for my $kid (@{$node->[_C]})
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   970
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   971
	my $newNode = $kid->cloneNode ($deep);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   972
	push @{$self->[_C]}, $newNode;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   973
	$newNode->setParentNode ($self);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   974
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   975
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   976
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   977
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   978
# For internal use only!
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   979
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   980
sub removeChildHoodMemories
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   981
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   982
    my ($self) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   983
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   984
    undef $self->[_Parent]; # was delete
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   985
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   986
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   987
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   988
# Remove circular dependencies. The Node and its children should
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   989
# not be used afterwards.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   990
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   991
sub dispose
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   992
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   993
    my $self = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   994
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   995
    $self->removeChildHoodMemories;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   996
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   997
    if (defined $self->[_C])
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   998
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   999
	$self->[_C]->dispose;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1000
	undef $self->[_C]; # was delete
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1001
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1002
    undef $self->[_Doc]; # was delete
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1003
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1004
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1005
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1006
# For internal use only!
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1007
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1008
sub setParentNode
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1009
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1010
    my ($self, $parent) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1011
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1012
    # REC 7473
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1013
    my $oldParent = $self->[_Parent];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1014
    if (defined $oldParent)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1015
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1016
	# remove from current parent
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1017
	my $index = $oldParent->getChildIndex ($self);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1018
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1019
	# NOTE: we don't have to check if [_C] is defined,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1020
	# because were removing a child here!
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1021
	splice (@{$oldParent->[_C]}, $index, 1, ());
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1022
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1023
	$self->removeChildHoodMemories;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1024
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1025
    $self->[_Parent] = $parent;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1026
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1027
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1028
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1029
# This function can return 3 values:
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1030
# 1: always readOnly
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1031
# 0: never readOnly
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1032
# undef: depends on parent node 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1033
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1034
# Returns 1 for DocumentType, Notation, Entity, EntityReference, Attlist, 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1035
# ElementDecl, AttDef. 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1036
# The first 4 are readOnly according to the DOM Spec, the others are always 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1037
# children of DocumentType. (Naturally, children of a readOnly node have to be
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1038
# readOnly as well...)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1039
# These nodes are always readOnly regardless of who their ancestors are.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1040
# Other nodes, e.g. Comment, are readOnly only if their parent is readOnly,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1041
# which basically means that one of its ancestors has to be one of the
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1042
# aforementioned node types.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1043
# Document and DocumentFragment return 0 for obvious reasons.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1044
# Attr, Element, CDATASection, Text return 0. The DOM spec says that they can 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1045
# be children of an Entity, but I don't think that that's possible
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1046
# with the current XML::Parser.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1047
# Attr uses a {ReadOnly} property, which is only set if it's part of a AttDef.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1048
# Always returns 0 if ignoreReadOnly is set.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1049
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1050
sub isReadOnly
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1051
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1052
    # default implementation for Nodes that are always readOnly
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1053
    ! $XML::DOM::IgnoreReadOnly;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1054
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1055
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1056
sub rejectChild
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1057
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1058
    1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1059
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1060
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1061
sub getNodeTypeName
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1062
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1063
    $NodeNames[$_[0]->getNodeType];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1064
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1065
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1066
sub getChildIndex
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1067
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1068
    my ($self, $node) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1069
    my $i = 0;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1070
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1071
    return -1 unless defined $self->[_C];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1072
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1073
    for my $kid (@{$self->[_C]})
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1074
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1075
	return $i if $kid == $node;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1076
	$i++;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1077
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1078
    -1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1079
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1080
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1081
sub getChildAtIndex
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1082
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1083
    my $kids = $_[0]->[_C];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1084
    defined ($kids) ? $kids->[$_[1]] : undef;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1085
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1086
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1087
sub isAncestor
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1088
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1089
    my ($self, $node) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1090
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1091
    do
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1092
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1093
	return 1 if $self == $node;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1094
	$node = $node->[_Parent];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1095
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1096
    while (defined $node);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1097
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1098
    0;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1099
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1100
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1101
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1102
# Added for optimization. Overriden in XML::DOM::Text
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1103
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1104
sub isTextNode
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1105
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1106
    0;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1107
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1108
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1109
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1110
# Added for optimization. Overriden in XML::DOM::DocumentFragment
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1111
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1112
sub isDocumentFragmentNode
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1113
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1114
    0;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1115
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1116
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1117
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1118
# Added for optimization. Overriden in XML::DOM::Element
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1119
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1120
sub isElementNode
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1121
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1122
    0;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1123
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1124
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1125
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1126
# Add a Text node with the specified value or append the text to the
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1127
# previous Node if it is a Text node.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1128
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1129
sub addText
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1130
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1131
    # REC 9456 (if it was called)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1132
    my ($self, $str) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1133
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1134
    my $node = ${$self->[_C]}[-1];	# $self->getLastChild
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1135
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1136
    if (defined ($node) && $node->isTextNode)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1137
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1138
	# REC 5475 (if it was called)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1139
	$node->appendData ($str);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1140
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1141
    else
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1142
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1143
	$node = $self->[_Doc]->createTextNode ($str);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1144
	$self->appendChild ($node);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1145
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1146
    $node;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1147
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1148
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1149
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1150
# Add a CDATASection node with the specified value or append the text to the
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1151
# previous Node if it is a CDATASection node.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1152
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1153
sub addCDATA
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1154
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1155
    my ($self, $str) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1156
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1157
    my $node = ${$self->[_C]}[-1];	# $self->getLastChild
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1158
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1159
    if (defined ($node) && $node->getNodeType == CDATA_SECTION_NODE)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1160
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1161
	$node->appendData ($str);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1162
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1163
    else
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1164
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1165
	$node = $self->[_Doc]->createCDATASection ($str);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1166
	$self->appendChild ($node);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1167
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1168
    $node;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1169
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1170
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1171
sub removeChildNodes
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1172
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1173
    my $self = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1174
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1175
    my $cref = $self->[_C];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1176
    return unless defined $cref;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1177
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1178
    my $kid;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1179
    while ($kid = pop @{$cref})
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1180
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1181
	undef $kid->[_Parent]; # was delete
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1182
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1183
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1184
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1185
sub toString
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1186
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1187
    my $self = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1188
    my $pr = $XML::DOM::PrintToString::Singleton;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1189
    $pr->reset;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1190
    $self->print ($pr);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1191
    $pr->toString;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1192
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1193
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1194
sub to_sax
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1195
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1196
    my $self = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1197
    unshift @_, 'Handler' if (@_ == 1);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1198
    my %h = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1199
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1200
    my $doch = exists ($h{DocumentHandler}) ? $h{DocumentHandler} 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1201
					    : $h{Handler};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1202
    my $dtdh = exists ($h{DTDHandler}) ? $h{DTDHandler} 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1203
				       : $h{Handler};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1204
    my $enth = exists ($h{EntityResolver}) ? $h{EntityResolver} 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1205
					   : $h{Handler};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1206
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1207
    $self->_to_sax ($doch, $dtdh, $enth);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1208
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1209
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1210
sub printToFile
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1211
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1212
    my ($self, $fileName) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1213
    my $fh = new FileHandle ($fileName, "w") || 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1214
	croak "printToFile - can't open output file $fileName";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1215
    
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1216
    $self->print ($fh);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1217
    $fh->close;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1218
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1219
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1220
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1221
# Use print to print to a FileHandle object (see printToFile code)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1222
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1223
sub printToFileHandle
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1224
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1225
    my ($self, $FH) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1226
    my $pr = new XML::DOM::PrintToFileHandle ($FH);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1227
    $self->print ($pr);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1228
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1229
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1230
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1231
# Used by AttDef::setDefault to convert unexpanded default attribute value
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1232
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1233
sub expandEntityRefs
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1234
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1235
    my ($self, $str) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1236
    my $doctype = $self->[_Doc]->getDoctype;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1237
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1238
    $str =~ s/&($XML::RegExp::Name|(#([0-9]+)|#x([0-9a-fA-F]+)));/
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1239
	defined($2) ? XML::DOM::XmlUtf8Encode ($3 || hex ($4)) 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1240
		    : expandEntityRef ($1, $doctype)/ego;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1241
    $str;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1242
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1243
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1244
sub expandEntityRef
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1245
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1246
    my ($entity, $doctype) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1247
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1248
    my $expanded = $XML::DOM::DefaultEntities{$entity};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1249
    return $expanded if defined $expanded;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1250
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1251
    $expanded = $doctype->getEntity ($entity);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1252
    return $expanded->getValue if (defined $expanded);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1253
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1254
#?? is this an error?
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1255
    croak "Could not expand entity reference of [$entity]\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1256
#    return "&$entity;";	# entity not found
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1257
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1258
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1259
sub isHidden
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1260
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1261
    $_[0]->[_Hidden];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1262
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1263
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1264
######################################################################
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1265
package XML::DOM::Attr;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1266
######################################################################
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1267
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1268
use vars qw{ @ISA @EXPORT_OK %EXPORT_TAGS %HFIELDS };
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1269
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1270
BEGIN
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1271
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1272
    import XML::DOM::Node qw( :DEFAULT :Fields );
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1273
    XML::DOM::def_fields ("Name Specified", "XML::DOM::Node");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1274
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1275
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1276
use XML::DOM::DOMException;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1277
use Carp;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1278
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1279
sub new
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1280
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1281
    my ($class, $doc, $name, $value, $specified) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1282
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1283
    if ($XML::DOM::SafeMode)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1284
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1285
	croak new XML::DOM::DOMException (INVALID_CHARACTER_ERR,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1286
					  "bad Attr name [$name]")
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1287
	    unless XML::DOM::isValidName ($name);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1288
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1289
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1290
    my $self = bless [], $class;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1291
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1292
    $self->[_Doc] = $doc;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1293
    $self->[_C] = new XML::DOM::NodeList;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1294
    $self->[_Name] = $name;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1295
    
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1296
    if (defined $value)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1297
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1298
	$self->setValue ($value);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1299
	$self->[_Specified] = (defined $specified) ? $specified : 1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1300
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1301
    else
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1302
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1303
	$self->[_Specified] = 0;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1304
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1305
    $self;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1306
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1307
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1308
sub getNodeType
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1309
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1310
    ATTRIBUTE_NODE;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1311
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1312
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1313
sub isSpecified
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1314
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1315
    $_[0]->[_Specified];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1316
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1317
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1318
sub getName
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1319
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1320
    $_[0]->[_Name];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1321
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1322
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1323
sub getValue
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1324
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1325
    my $self = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1326
    my $value = "";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1327
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1328
    for my $kid (@{$self->[_C]})
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1329
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1330
	$value .= $kid->getData;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1331
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1332
    $value;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1333
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1334
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1335
sub setValue
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1336
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1337
    my ($self, $value) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1338
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1339
    # REC 1147
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1340
    $self->removeChildNodes;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1341
    $self->appendChild ($self->[_Doc]->createTextNode ($value));
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1342
    $self->[_Specified] = 1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1343
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1344
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1345
sub getNodeName
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1346
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1347
    $_[0]->getName;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1348
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1349
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1350
sub getNodeValue
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1351
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1352
    $_[0]->getValue;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1353
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1354
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1355
sub setNodeValue
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1356
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1357
    $_[0]->setValue ($_[1]);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1358
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1359
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1360
sub cloneNode
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1361
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1362
    my ($self) = @_;	# parameter deep is ignored
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1363
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1364
    my $node = $self->[_Doc]->createAttribute ($self->getName);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1365
    $node->[_Specified] = $self->[_Specified];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1366
    $node->[_ReadOnly] = 1 if $self->[_ReadOnly];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1367
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1368
    $node->cloneChildren ($self, 1);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1369
    $node;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1370
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1371
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1372
#------------------------------------------------------------
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1373
# Extra method implementations
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1374
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1375
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1376
sub isReadOnly
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1377
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1378
    # ReadOnly property is set if it's part of a AttDef
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1379
    ! $XML::DOM::IgnoreReadOnly && defined ($_[0]->[_ReadOnly]);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1380
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1381
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1382
sub print
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1383
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1384
    my ($self, $FILE) = @_;    
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1385
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1386
    my $name = $self->[_Name];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1387
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1388
    $FILE->print ("$name=\"");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1389
    for my $kid (@{$self->[_C]})
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1390
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1391
	if ($kid->getNodeType == TEXT_NODE)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1392
	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1393
	    $FILE->print (XML::DOM::encodeAttrValue ($kid->getData));
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1394
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1395
	else	# ENTITY_REFERENCE_NODE
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1396
	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1397
	    $kid->print ($FILE);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1398
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1399
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1400
    $FILE->print ("\"");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1401
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1402
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1403
sub rejectChild
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1404
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1405
    my $t = $_[1]->getNodeType;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1406
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1407
    $t != TEXT_NODE 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1408
    && $t != ENTITY_REFERENCE_NODE;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1409
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1410
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1411
######################################################################
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1412
package XML::DOM::ProcessingInstruction;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1413
######################################################################
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1414
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1415
use vars qw{ @ISA @EXPORT_OK %EXPORT_TAGS %HFIELDS };
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1416
BEGIN
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1417
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1418
    import XML::DOM::Node qw( :DEFAULT :Fields );
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1419
    XML::DOM::def_fields ("Target Data", "XML::DOM::Node");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1420
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1421
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1422
use XML::DOM::DOMException;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1423
use Carp;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1424
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1425
sub new
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1426
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1427
    my ($class, $doc, $target, $data, $hidden) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1428
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1429
    croak new XML::DOM::DOMException (INVALID_CHARACTER_ERR,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1430
			      "bad ProcessingInstruction Target [$target]")
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1431
	unless (XML::DOM::isValidName ($target) && $target !~ /^xml$/io);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1432
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1433
    my $self = bless [], $class;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1434
  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1435
    $self->[_Doc] = $doc;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1436
    $self->[_Target] = $target;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1437
    $self->[_Data] = $data;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1438
    $self->[_Hidden] = $hidden;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1439
    $self;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1440
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1441
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1442
sub getNodeType
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1443
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1444
    PROCESSING_INSTRUCTION_NODE;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1445
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1446
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1447
sub getTarget
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1448
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1449
    $_[0]->[_Target];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1450
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1451
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1452
sub getData
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1453
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1454
    $_[0]->[_Data];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1455
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1456
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1457
sub setData
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1458
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1459
    my ($self, $data) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1460
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1461
    croak new XML::DOM::DOMException (NO_MODIFICATION_ALLOWED_ERR,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1462
				      "node is ReadOnly")
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1463
	if $self->isReadOnly;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1464
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1465
    $self->[_Data] = $data;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1466
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1467
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1468
sub getNodeName
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1469
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1470
    $_[0]->[_Target];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1471
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1472
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1473
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1474
# Same as getData
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1475
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1476
sub getNodeValue
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1477
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1478
    $_[0]->[_Data];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1479
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1480
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1481
sub setNodeValue
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1482
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1483
    $_[0]->setData ($_[1]);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1484
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1485
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1486
sub cloneNode
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1487
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1488
    my $self = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1489
    $self->[_Doc]->createProcessingInstruction ($self->getTarget, 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1490
						$self->getData,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1491
						$self->isHidden);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1492
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1493
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1494
#------------------------------------------------------------
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1495
# Extra method implementations
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1496
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1497
sub isReadOnly
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1498
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1499
    return 0 if $XML::DOM::IgnoreReadOnly;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1500
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1501
    my $pa = $_[0]->[_Parent];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1502
    defined ($pa) ? $pa->isReadOnly : 0;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1503
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1504
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1505
sub print
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1506
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1507
    my ($self, $FILE) = @_;    
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1508
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1509
    $FILE->print ("<?");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1510
    $FILE->print ($self->[_Target]);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1511
    $FILE->print (" ");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1512
    $FILE->print (XML::DOM::encodeProcessingInstruction ($self->[_Data]));
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1513
    $FILE->print ("?>");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1514
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1515
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1516
######################################################################
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1517
package XML::DOM::Notation;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1518
######################################################################
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1519
use vars qw{ @ISA @EXPORT_OK %EXPORT_TAGS %HFIELDS };
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1520
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1521
BEGIN
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1522
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1523
    import XML::DOM::Node qw( :DEFAULT :Fields );
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1524
    XML::DOM::def_fields ("Name Base SysId PubId", "XML::DOM::Node");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1525
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1526
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1527
use XML::DOM::DOMException;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1528
use Carp;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1529
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1530
sub new
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1531
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1532
    my ($class, $doc, $name, $base, $sysId, $pubId, $hidden) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1533
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1534
    croak new XML::DOM::DOMException (INVALID_CHARACTER_ERR, 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1535
				      "bad Notation Name [$name]")
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1536
	unless XML::DOM::isValidName ($name);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1537
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1538
    my $self = bless [], $class;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1539
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1540
    $self->[_Doc] = $doc;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1541
    $self->[_Name] = $name;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1542
    $self->[_Base] = $base;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1543
    $self->[_SysId] = $sysId;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1544
    $self->[_PubId] = $pubId;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1545
    $self->[_Hidden] = $hidden;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1546
    $self;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1547
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1548
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1549
sub getNodeType
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1550
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1551
    NOTATION_NODE;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1552
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1553
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1554
sub getPubId
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1555
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1556
    $_[0]->[_PubId];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1557
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1558
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1559
sub setPubId
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1560
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1561
    $_[0]->[_PubId] = $_[1];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1562
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1563
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1564
sub getSysId
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1565
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1566
    $_[0]->[_SysId];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1567
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1568
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1569
sub setSysId
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1570
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1571
    $_[0]->[_SysId] = $_[1];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1572
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1573
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1574
sub getName
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1575
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1576
    $_[0]->[_Name];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1577
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1578
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1579
sub setName
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1580
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1581
    $_[0]->[_Name] = $_[1];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1582
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1583
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1584
sub getBase
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1585
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1586
    $_[0]->[_Base];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1587
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1588
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1589
sub getNodeName
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1590
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1591
    $_[0]->[_Name];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1592
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1593
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1594
sub print
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1595
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1596
    my ($self, $FILE) = @_;    
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1597
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1598
    my $name = $self->[_Name];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1599
    my $sysId = $self->[_SysId];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1600
    my $pubId = $self->[_PubId];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1601
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1602
    $FILE->print ("<!NOTATION $name ");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1603
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1604
    if (defined $pubId)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1605
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1606
	$FILE->print (" PUBLIC \"$pubId\"");	
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1607
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1608
    if (defined $sysId)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1609
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1610
	$FILE->print (" SYSTEM \"$sysId\"");	
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1611
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1612
    $FILE->print (">");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1613
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1614
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1615
sub cloneNode
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1616
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1617
    my ($self) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1618
    $self->[_Doc]->createNotation ($self->[_Name], $self->[_Base], 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1619
				   $self->[_SysId], $self->[_PubId],
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1620
				   $self->[_Hidden]);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1621
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1622
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1623
sub to_expat
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1624
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1625
    my ($self, $iter) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1626
    $iter->Notation ($self->getName, $self->getBase, 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1627
		     $self->getSysId, $self->getPubId);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1628
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1629
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1630
sub _to_sax
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1631
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1632
    my ($self, $doch, $dtdh, $enth) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1633
    $dtdh->notation_decl ( { Name => $self->getName, 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1634
			     Base => $self->getBase, 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1635
			     SystemId => $self->getSysId, 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1636
			     PublicId => $self->getPubId });
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1637
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1638
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1639
######################################################################
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1640
package XML::DOM::Entity;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1641
######################################################################
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1642
use vars qw{ @ISA @EXPORT_OK %EXPORT_TAGS %HFIELDS };
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1643
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1644
BEGIN
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1645
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1646
    import XML::DOM::Node qw( :DEFAULT :Fields );
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1647
    XML::DOM::def_fields ("NotationName Parameter Value Ndata SysId PubId", "XML::DOM::Node");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1648
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1649
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1650
use XML::DOM::DOMException;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1651
use Carp;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1652
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1653
sub new
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1654
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1655
    my ($class, $doc, $par, $notationName, $value, $sysId, $pubId, $ndata, $hidden) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1656
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1657
    croak new XML::DOM::DOMException (INVALID_CHARACTER_ERR, 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1658
				      "bad Entity Name [$notationName]")
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1659
	unless XML::DOM::isValidName ($notationName);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1660
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1661
    my $self = bless [], $class;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1662
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1663
    $self->[_Doc] = $doc;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1664
    $self->[_NotationName] = $notationName;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1665
    $self->[_Parameter] = $par;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1666
    $self->[_Value] = $value;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1667
    $self->[_Ndata] = $ndata;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1668
    $self->[_SysId] = $sysId;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1669
    $self->[_PubId] = $pubId;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1670
    $self->[_Hidden] = $hidden;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1671
    $self;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1672
#?? maybe Value should be a Text node
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1673
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1674
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1675
sub getNodeType
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1676
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1677
    ENTITY_NODE;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1678
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1679
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1680
sub getPubId
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1681
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1682
    $_[0]->[_PubId];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1683
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1684
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1685
sub getSysId
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1686
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1687
    $_[0]->[_SysId];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1688
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1689
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1690
# Dom Spec says: 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1691
#  For unparsed entities, the name of the notation for the
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1692
#  entity. For parsed entities, this is null.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1693
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1694
#?? do we have unparsed entities?
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1695
sub getNotationName
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1696
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1697
    $_[0]->[_NotationName];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1698
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1699
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1700
sub getNodeName
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1701
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1702
    $_[0]->[_NotationName];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1703
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1704
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1705
sub cloneNode
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1706
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1707
    my $self = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1708
    $self->[_Doc]->createEntity ($self->[_Parameter], 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1709
				 $self->[_NotationName], $self->[_Value], 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1710
				 $self->[_SysId], $self->[_PubId], 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1711
				 $self->[_Ndata], $self->[_Hidden]);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1712
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1713
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1714
sub rejectChild
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1715
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1716
    return 1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1717
#?? if value is split over subnodes, recode this section
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1718
# also add:				   C => new XML::DOM::NodeList,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1719
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1720
    my $t = $_[1];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1721
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1722
    return $t == TEXT_NODE
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1723
	|| $t == ENTITY_REFERENCE_NODE 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1724
	|| $t == PROCESSING_INSTRUCTION_NODE
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1725
	|| $t == COMMENT_NODE
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1726
	|| $t == CDATA_SECTION_NODE
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1727
	|| $t == ELEMENT_NODE;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1728
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1729
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1730
sub getValue
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1731
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1732
    $_[0]->[_Value];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1733
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1734
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1735
sub isParameterEntity
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1736
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1737
    $_[0]->[_Parameter];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1738
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1739
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1740
sub getNdata
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1741
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1742
    $_[0]->[_Ndata];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1743
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1744
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1745
sub print
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1746
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1747
    my ($self, $FILE) = @_;    
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1748
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1749
    my $name = $self->[_NotationName];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1750
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1751
    my $par = $self->isParameterEntity ? "% " : "";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1752
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1753
    $FILE->print ("<!ENTITY $par$name");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1754
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1755
    my $value = $self->[_Value];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1756
    my $sysId = $self->[_SysId];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1757
    my $pubId = $self->[_PubId];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1758
    my $ndata = $self->[_Ndata];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1759
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1760
    if (defined $value)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1761
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1762
#?? Not sure what to do if it contains both single and double quote
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1763
	$value = ($value =~ /\"/) ? "'$value'" : "\"$value\"";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1764
	$FILE->print (" $value");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1765
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1766
    if (defined $pubId)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1767
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1768
	$FILE->print (" PUBLIC \"$pubId\"");	
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1769
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1770
    elsif (defined $sysId)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1771
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1772
	$FILE->print (" SYSTEM");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1773
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1774
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1775
    if (defined $sysId)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1776
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1777
	$FILE->print (" \"$sysId\"");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1778
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1779
    $FILE->print (" NDATA $ndata") if defined $ndata;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1780
    $FILE->print (">");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1781
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1782
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1783
sub to_expat
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1784
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1785
    my ($self, $iter) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1786
    my $name = ($self->isParameterEntity ? '%' : "") . $self->getNotationName; 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1787
    $iter->Entity ($name,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1788
		   $self->getValue, $self->getSysId, $self->getPubId, 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1789
		   $self->getNdata);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1790
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1791
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1792
sub _to_sax
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1793
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1794
    my ($self, $doch, $dtdh, $enth) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1795
    my $name = ($self->isParameterEntity ? '%' : "") . $self->getNotationName; 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1796
    $dtdh->entity_decl ( { Name => $name, 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1797
			   Value => $self->getValue, 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1798
			   SystemId => $self->getSysId, 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1799
			   PublicId => $self->getPubId, 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1800
			   Notation => $self->getNdata } );
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1801
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1802
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1803
######################################################################
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1804
package XML::DOM::EntityReference;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1805
######################################################################
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1806
use vars qw{ @ISA @EXPORT_OK %EXPORT_TAGS %HFIELDS };
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1807
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1808
BEGIN
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1809
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1810
    import XML::DOM::Node qw( :DEFAULT :Fields );
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1811
    XML::DOM::def_fields ("EntityName Parameter", "XML::DOM::Node");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1812
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1813
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1814
use XML::DOM::DOMException;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1815
use Carp;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1816
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1817
sub new
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1818
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1819
    my ($class, $doc, $name, $parameter) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1820
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1821
    croak new XML::DOM::DOMException (INVALID_CHARACTER_ERR, 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1822
		      "bad Entity Name [$name] in EntityReference")
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1823
	unless XML::DOM::isValidName ($name);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1824
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1825
    my $self = bless [], $class;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1826
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1827
    $self->[_Doc] = $doc;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1828
    $self->[_EntityName] = $name;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1829
    $self->[_Parameter] = ($parameter || 0);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1830
    $self;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1831
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1832
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1833
sub getNodeType
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1834
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1835
    ENTITY_REFERENCE_NODE;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1836
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1837
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1838
sub getNodeName
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1839
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1840
    $_[0]->[_EntityName];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1841
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1842
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1843
#------------------------------------------------------------
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1844
# Extra method implementations
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1845
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1846
sub getEntityName
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1847
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1848
    $_[0]->[_EntityName];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1849
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1850
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1851
sub isParameterEntity
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1852
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1853
    $_[0]->[_Parameter];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1854
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1855
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1856
sub getData
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1857
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1858
    my $self = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1859
    my $name = $self->[_EntityName];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1860
    my $parameter = $self->[_Parameter];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1861
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1862
    my $data = $self->[_Doc]->expandEntity ($name, $parameter);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1863
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1864
    unless (defined $data)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1865
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1866
#?? this is probably an error
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1867
	my $pc = $parameter ? "%" : "&";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1868
	$data = "$pc$name;";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1869
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1870
    $data;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1871
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1872
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1873
sub print
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1874
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1875
    my ($self, $FILE) = @_;    
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1876
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1877
    my $name = $self->[_EntityName];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1878
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1879
#?? or do we expand the entities?
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1880
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1881
    my $pc = $self->[_Parameter] ? "%" : "&";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1882
    $FILE->print ("$pc$name;");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1883
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1884
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1885
# Dom Spec says:
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1886
#     [...] but if such an Entity exists, then
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1887
#     the child list of the EntityReference node is the same as that of the
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1888
#     Entity node. 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1889
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1890
#     The resolution of the children of the EntityReference (the replacement
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1891
#     value of the referenced Entity) may be lazily evaluated; actions by the
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1892
#     user (such as calling the childNodes method on the EntityReference
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1893
#     node) are assumed to trigger the evaluation.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1894
sub getChildNodes
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1895
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1896
    my $self = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1897
    my $entity = $self->[_Doc]->getEntity ($self->[_EntityName]);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1898
    defined ($entity) ? $entity->getChildNodes : new XML::DOM::NodeList;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1899
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1900
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1901
sub cloneNode
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1902
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1903
    my $self = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1904
    $self->[_Doc]->createEntityReference ($self->[_EntityName], 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1905
					 $self->[_Parameter]);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1906
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1907
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1908
sub to_expat
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1909
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1910
    my ($self, $iter) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1911
    $iter->EntityRef ($self->getEntityName, $self->isParameterEntity);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1912
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1913
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1914
sub _to_sax
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1915
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1916
    my ($self, $doch, $dtdh, $enth) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1917
    my @par = $self->isParameterEntity ? (Parameter => 1) : ();
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1918
#?? not supported by PerlSAX: $self->isParameterEntity
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1919
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1920
    $doch->entity_reference ( { Name => $self->getEntityName, @par } );
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1921
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1922
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1923
# NOTE: an EntityReference can't really have children, so rejectChild
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1924
# is not reimplemented (i.e. it always returns 0.)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1925
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1926
######################################################################
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1927
package XML::DOM::AttDef;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1928
######################################################################
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1929
use vars qw{ @ISA @EXPORT_OK %EXPORT_TAGS %HFIELDS };
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1930
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1931
BEGIN
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1932
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1933
    import XML::DOM::Node qw( :DEFAULT :Fields );
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1934
    XML::DOM::def_fields ("Name Type Fixed Default Required Implied Quote", "XML::DOM::Node");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1935
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1936
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1937
use XML::DOM::DOMException;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1938
use Carp;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1939
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1940
#------------------------------------------------------------
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1941
# Extra method implementations
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1942
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1943
# AttDef is not part of DOM Spec
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1944
sub new
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1945
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1946
    my ($class, $doc, $name, $attrType, $default, $fixed, $hidden) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1947
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1948
    croak new XML::DOM::DOMException (INVALID_CHARACTER_ERR,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1949
				      "bad Attr name in AttDef [$name]")
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1950
	unless XML::DOM::isValidName ($name);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1951
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1952
    my $self = bless [], $class;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1953
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1954
    $self->[_Doc] = $doc;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1955
    $self->[_Name] = $name;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1956
    $self->[_Type] = $attrType;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1957
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1958
    if (defined $default)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1959
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1960
	if ($default eq "#REQUIRED")
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1961
	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1962
	    $self->[_Required] = 1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1963
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1964
	elsif ($default eq "#IMPLIED")
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1965
	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1966
	    $self->[_Implied] = 1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1967
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1968
	else
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1969
	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1970
	    # strip off quotes - see Attlist handler in XML::Parser
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1971
	    $default =~ m#^(["'])(.*)['"]$#;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1972
	    
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1973
	    $self->[_Quote] = $1;	# keep track of the quote character
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1974
	    $self->[_Default] = $self->setDefault ($2);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1975
	    
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1976
#?? should default value be decoded - what if it contains e.g. "&amp;"
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1977
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1978
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1979
    $self->[_Fixed] = $fixed if defined $fixed;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1980
    $self->[_Hidden] = $hidden if defined $hidden;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1981
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1982
    $self;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1983
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1984
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1985
sub getNodeType
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1986
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1987
    ATT_DEF_NODE;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1988
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1989
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1990
sub getName
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1991
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1992
    $_[0]->[_Name];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1993
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1994
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1995
# So it can be added to a NamedNodeMap
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1996
sub getNodeName
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1997
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1998
    $_[0]->[_Name];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  1999
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2000
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2001
sub getType
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2002
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2003
    $_[0]->[_Type];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2004
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2005
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2006
sub setType
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2007
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2008
    $_[0]->[_Type] = $_[1];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2009
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2010
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2011
sub getDefault
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2012
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2013
    $_[0]->[_Default];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2014
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2015
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2016
sub setDefault
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2017
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2018
    my ($self, $value) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2019
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2020
    # specified=0, it's the default !
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2021
    my $attr = $self->[_Doc]->createAttribute ($self->[_Name], undef, 0);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2022
    $attr->[_ReadOnly] = 1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2023
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2024
#?? this should be split over Text and EntityReference nodes, just like other
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2025
# Attr nodes - just expand the text for now
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2026
    $value = $self->expandEntityRefs ($value);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2027
    $attr->addText ($value);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2028
#?? reimplement in NoExpand mode!
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2029
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2030
    $attr;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2031
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2032
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2033
sub isFixed
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2034
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2035
    $_[0]->[_Fixed] || 0;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2036
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2037
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2038
sub isRequired
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2039
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2040
    $_[0]->[_Required] || 0;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2041
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2042
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2043
sub isImplied
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2044
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2045
    $_[0]->[_Implied] || 0;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2046
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2047
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2048
sub print
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2049
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2050
    my ($self, $FILE) = @_;    
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2051
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2052
    my $name = $self->[_Name];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2053
    my $type = $self->[_Type];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2054
    my $fixed = $self->[_Fixed];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2055
    my $default = $self->[_Default];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2056
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2057
    $FILE->print ("$name $type");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2058
    $FILE->print (" #FIXED") if defined $fixed;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2059
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2060
    if ($self->[_Required])
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2061
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2062
	$FILE->print (" #REQUIRED");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2063
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2064
    elsif ($self->[_Implied])
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2065
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2066
	$FILE->print (" #IMPLIED");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2067
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2068
    elsif (defined ($default))
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2069
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2070
	my $quote = $self->[_Quote];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2071
	$FILE->print (" $quote");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2072
	for my $kid (@{$default->[_C]})
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2073
	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2074
	    $kid->print ($FILE);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2075
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2076
	$FILE->print ($quote);	
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2077
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2078
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2079
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2080
sub getDefaultString
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2081
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2082
    my $self = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2083
    my $default;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2084
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2085
    if ($self->[_Required])
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2086
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2087
	return "#REQUIRED";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2088
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2089
    elsif ($self->[_Implied])
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2090
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2091
	return "#IMPLIED";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2092
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2093
    elsif (defined ($default = $self->[_Default]))
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2094
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2095
	my $quote = $self->[_Quote];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2096
	$default = $default->toString;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2097
	return "$quote$default$quote";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2098
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2099
    undef;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2100
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2101
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2102
sub cloneNode
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2103
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2104
    my $self = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2105
    my $node = new XML::DOM::AttDef ($self->[_Doc], $self->[_Name], $self->[_Type],
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2106
				     undef, $self->[_Fixed]);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2107
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2108
    $node->[_Required] = 1 if $self->[_Required];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2109
    $node->[_Implied] = 1 if $self->[_Implied];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2110
    $node->[_Fixed] = $self->[_Fixed] if defined $self->[_Fixed];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2111
    $node->[_Hidden] = $self->[_Hidden] if defined $self->[_Hidden];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2112
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2113
    if (defined $self->[_Default])
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2114
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2115
	$node->[_Default] = $self->[_Default]->cloneNode(1);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2116
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2117
    $node->[_Quote] = $self->[_Quote];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2118
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2119
    $node;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2120
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2121
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2122
sub setOwnerDocument
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2123
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2124
    my ($self, $doc) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2125
    $self->SUPER::setOwnerDocument ($doc);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2126
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2127
    if (defined $self->[_Default])
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2128
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2129
	$self->[_Default]->setOwnerDocument ($doc);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2130
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2131
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2132
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2133
######################################################################
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2134
package XML::DOM::AttlistDecl;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2135
######################################################################
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2136
use vars qw{ @ISA @EXPORT_OK %EXPORT_TAGS %HFIELDS };
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2137
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2138
BEGIN
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2139
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2140
    import XML::DOM::Node qw( :DEFAULT :Fields );
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2141
    import XML::DOM::AttDef qw{ :Fields };
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2142
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2143
    XML::DOM::def_fields ("ElementName", "XML::DOM::Node");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2144
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2145
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2146
use XML::DOM::DOMException;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2147
use Carp;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2148
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2149
#------------------------------------------------------------
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2150
# Extra method implementations
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2151
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2152
# AttlistDecl is not part of the DOM Spec
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2153
sub new
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2154
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2155
    my ($class, $doc, $name) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2156
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2157
    croak new XML::DOM::DOMException (INVALID_CHARACTER_ERR, 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2158
			      "bad Element TagName [$name] in AttlistDecl")
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2159
	unless XML::DOM::isValidName ($name);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2160
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2161
    my $self = bless [], $class;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2162
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2163
    $self->[_Doc] = $doc;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2164
    $self->[_C] = new XML::DOM::NodeList;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2165
    $self->[_ReadOnly] = 1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2166
    $self->[_ElementName] = $name;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2167
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2168
    $self->[_A] = new XML::DOM::NamedNodeMap (Doc	=> $doc,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2169
					      ReadOnly	=> 1,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2170
					      Parent	=> $self);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2171
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2172
    $self;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2173
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2174
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2175
sub getNodeType
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2176
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2177
    ATTLIST_DECL_NODE;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2178
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2179
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2180
sub getName
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2181
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2182
    $_[0]->[_ElementName];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2183
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2184
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2185
sub getNodeName
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2186
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2187
    $_[0]->[_ElementName];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2188
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2189
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2190
sub getAttDef
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2191
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2192
    my ($self, $attrName) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2193
    $self->[_A]->getNamedItem ($attrName);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2194
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2195
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2196
sub addAttDef
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2197
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2198
    my ($self, $attrName, $type, $default, $fixed, $hidden) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2199
    my $node = $self->getAttDef ($attrName);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2200
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2201
    if (defined $node)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2202
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2203
	# data will be ignored if already defined
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2204
	my $elemName = $self->getName;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2205
	XML::DOM::warning ("multiple definitions of attribute $attrName for element $elemName, only first one is recognized");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2206
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2207
    else
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2208
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2209
	$node = new XML::DOM::AttDef ($self->[_Doc], $attrName, $type, 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2210
				      $default, $fixed, $hidden);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2211
	$self->[_A]->setNamedItem ($node);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2212
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2213
    $node;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2214
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2215
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2216
sub getDefaultAttrValue
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2217
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2218
    my ($self, $attr) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2219
    my $attrNode = $self->getAttDef ($attr);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2220
    (defined $attrNode) ? $attrNode->getDefault : undef;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2221
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2222
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2223
sub cloneNode
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2224
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2225
    my ($self, $deep) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2226
    my $node = $self->[_Doc]->createAttlistDecl ($self->[_ElementName]);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2227
    
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2228
    $node->[_A] = $self->[_A]->cloneNode ($deep);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2229
    $node;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2230
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2231
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2232
sub setOwnerDocument
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2233
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2234
    my ($self, $doc) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2235
    $self->SUPER::setOwnerDocument ($doc);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2236
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2237
    $self->[_A]->setOwnerDocument ($doc);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2238
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2239
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2240
sub print
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2241
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2242
    my ($self, $FILE) = @_;    
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2243
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2244
    my $name = $self->getName;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2245
    my @attlist = @{$self->[_A]->getValues};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2246
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2247
    my $hidden = 1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2248
    for my $att (@attlist)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2249
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2250
	unless ($att->[_Hidden])
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2251
	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2252
	    $hidden = 0;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2253
	    last;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2254
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2255
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2256
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2257
    unless ($hidden)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2258
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2259
	$FILE->print ("<!ATTLIST $name");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2260
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2261
	if (@attlist == 1)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2262
	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2263
	    $FILE->print (" ");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2264
	    $attlist[0]->print ($FILE);	    
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2265
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2266
	else
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2267
	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2268
	    for my $attr (@attlist)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2269
	    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2270
		next if $attr->[_Hidden];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2271
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2272
		$FILE->print ("\x0A  ");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2273
		$attr->print ($FILE);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2274
	    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2275
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2276
	$FILE->print (">");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2277
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2278
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2279
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2280
sub to_expat
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2281
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2282
    my ($self, $iter) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2283
    my $tag = $self->getName;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2284
    for my $a ($self->[_A]->getValues)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2285
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2286
	my $default = $a->isImplied ? '#IMPLIED' :
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2287
	    ($a->isRequired ? '#REQUIRED' : 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2288
	     ($a->[_Quote] . $a->getDefault->getValue . $a->[_Quote]));
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2289
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2290
	$iter->Attlist ($tag, $a->getName, $a->getType, $default, $a->isFixed); 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2291
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2292
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2293
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2294
sub _to_sax
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2295
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2296
    my ($self, $doch, $dtdh, $enth) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2297
    my $tag = $self->getName;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2298
    for my $a ($self->[_A]->getValues)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2299
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2300
	my $default = $a->isImplied ? '#IMPLIED' :
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2301
	    ($a->isRequired ? '#REQUIRED' : 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2302
	     ($a->[_Quote] . $a->getDefault->getValue . $a->[_Quote]));
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2303
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2304
	$dtdh->attlist_decl ({ ElementName => $tag, 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2305
			       AttributeName => $a->getName, 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2306
			       Type => $a->[_Type], 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2307
			       Default => $default, 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2308
			       Fixed => $a->isFixed }); 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2309
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2310
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2311
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2312
######################################################################
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2313
package XML::DOM::ElementDecl;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2314
######################################################################
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2315
use vars qw{ @ISA @EXPORT_OK %EXPORT_TAGS %HFIELDS };
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2316
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2317
BEGIN
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2318
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2319
    import XML::DOM::Node qw( :DEFAULT :Fields );
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2320
    XML::DOM::def_fields ("Name Model", "XML::DOM::Node");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2321
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2322
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2323
use XML::DOM::DOMException;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2324
use Carp;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2325
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2326
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2327
#------------------------------------------------------------
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2328
# Extra method implementations
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2329
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2330
# ElementDecl is not part of the DOM Spec
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2331
sub new
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2332
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2333
    my ($class, $doc, $name, $model, $hidden) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2334
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2335
    croak new XML::DOM::DOMException (INVALID_CHARACTER_ERR, 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2336
			      "bad Element TagName [$name] in ElementDecl")
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2337
	unless XML::DOM::isValidName ($name);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2338
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2339
    my $self = bless [], $class;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2340
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2341
    $self->[_Doc] = $doc;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2342
    $self->[_Name] = $name;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2343
    $self->[_ReadOnly] = 1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2344
    $self->[_Model] = $model;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2345
    $self->[_Hidden] = $hidden;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2346
    $self;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2347
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2348
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2349
sub getNodeType
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2350
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2351
    ELEMENT_DECL_NODE;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2352
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2353
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2354
sub getName
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2355
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2356
    $_[0]->[_Name];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2357
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2358
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2359
sub getNodeName
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2360
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2361
    $_[0]->[_Name];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2362
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2363
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2364
sub getModel
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2365
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2366
    $_[0]->[_Model];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2367
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2368
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2369
sub setModel
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2370
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2371
    my ($self, $model) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2372
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2373
    $self->[_Model] = $model;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2374
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2375
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2376
sub print
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2377
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2378
    my ($self, $FILE) = @_;    
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2379
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2380
    my $name = $self->[_Name];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2381
    my $model = $self->[_Model];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2382
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2383
    $FILE->print ("<!ELEMENT $name $model>")
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2384
	unless $self->[_Hidden];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2385
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2386
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2387
sub cloneNode
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2388
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2389
    my $self = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2390
    $self->[_Doc]->createElementDecl ($self->[_Name], $self->[_Model], 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2391
				      $self->[_Hidden]);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2392
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2393
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2394
sub to_expat
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2395
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2396
#?? add support for Hidden?? (allover, also in _to_sax!!)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2397
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2398
    my ($self, $iter) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2399
    $iter->Element ($self->getName, $self->getModel);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2400
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2401
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2402
sub _to_sax
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2403
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2404
    my ($self, $doch, $dtdh, $enth) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2405
    $dtdh->element_decl ( { Name => $self->getName, 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2406
			    Model => $self->getModel } );
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2407
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2408
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2409
######################################################################
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2410
package XML::DOM::Element;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2411
######################################################################
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2412
use vars qw{ @ISA @EXPORT_OK %EXPORT_TAGS %HFIELDS };
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2413
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2414
BEGIN
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2415
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2416
    import XML::DOM::Node qw( :DEFAULT :Fields );
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2417
    XML::DOM::def_fields ("TagName", "XML::DOM::Node");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2418
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2419
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2420
use XML::DOM::DOMException;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2421
use XML::DOM::NamedNodeMap;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2422
use Carp;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2423
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2424
sub new
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2425
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2426
    my ($class, $doc, $tagName) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2427
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2428
    if ($XML::DOM::SafeMode)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2429
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2430
	croak new XML::DOM::DOMException (INVALID_CHARACTER_ERR, 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2431
				      "bad Element TagName [$tagName]")
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2432
	    unless XML::DOM::isValidName ($tagName);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2433
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2434
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2435
    my $self = bless [], $class;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2436
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2437
    $self->[_Doc] = $doc;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2438
    $self->[_C] = new XML::DOM::NodeList;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2439
    $self->[_TagName] = $tagName;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2440
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2441
# Now we're creating the NamedNodeMap only when needed (REC 2313 => 1147)    
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2442
#    $self->[_A] = new XML::DOM::NamedNodeMap (Doc	=> $doc,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2443
#					     Parent	=> $self);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2444
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2445
    $self;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2446
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2447
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2448
sub getNodeType
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2449
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2450
    ELEMENT_NODE;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2451
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2452
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2453
sub getTagName
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2454
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2455
    $_[0]->[_TagName];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2456
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2457
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2458
sub getNodeName
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2459
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2460
    $_[0]->[_TagName];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2461
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2462
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2463
sub getAttributeNode
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2464
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2465
    my ($self, $name) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2466
    return undef unless defined $self->[_A];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2467
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2468
    $self->getAttributes->{$name};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2469
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2470
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2471
sub getAttribute
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2472
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2473
    my ($self, $name) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2474
    my $attr = $self->getAttributeNode ($name);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2475
    (defined $attr) ? $attr->getValue : "";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2476
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2477
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2478
sub setAttribute
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2479
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2480
    my ($self, $name, $val) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2481
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2482
    croak new XML::DOM::DOMException (INVALID_CHARACTER_ERR,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2483
				      "bad Attr Name [$name]")
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2484
	unless XML::DOM::isValidName ($name);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2485
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2486
    croak new XML::DOM::DOMException (NO_MODIFICATION_ALLOWED_ERR,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2487
				      "node is ReadOnly")
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2488
	if $self->isReadOnly;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2489
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2490
    my $node = $self->getAttributes->{$name};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2491
    if (defined $node)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2492
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2493
	$node->setValue ($val);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2494
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2495
    else
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2496
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2497
	$node = $self->[_Doc]->createAttribute ($name, $val);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2498
	$self->[_A]->setNamedItem ($node);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2499
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2500
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2501
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2502
sub setAttributeNode
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2503
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2504
    my ($self, $node) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2505
    my $attr = $self->getAttributes;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2506
    my $name = $node->getNodeName;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2507
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2508
    # REC 1147
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2509
    if ($XML::DOM::SafeMode)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2510
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2511
	croak new XML::DOM::DOMException (WRONG_DOCUMENT_ERR,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2512
					  "nodes belong to different documents")
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2513
	    if $self->[_Doc] != $node->[_Doc];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2514
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2515
	croak new XML::DOM::DOMException (NO_MODIFICATION_ALLOWED_ERR,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2516
					  "node is ReadOnly")
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2517
	    if $self->isReadOnly;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2518
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2519
	my $attrParent = $node->[_UsedIn];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2520
	croak new XML::DOM::DOMException (INUSE_ATTRIBUTE_ERR,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2521
					  "Attr is already used by another Element")
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2522
	    if (defined ($attrParent) && $attrParent != $attr);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2523
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2524
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2525
    my $other = $attr->{$name};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2526
    $attr->removeNamedItem ($name) if defined $other;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2527
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2528
    $attr->setNamedItem ($node);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2529
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2530
    $other;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2531
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2532
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2533
sub removeAttributeNode
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2534
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2535
    my ($self, $node) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2536
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2537
    croak new XML::DOM::DOMException (NO_MODIFICATION_ALLOWED_ERR,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2538
				      "node is ReadOnly")
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2539
	if $self->isReadOnly;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2540
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2541
    my $attr = $self->[_A];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2542
    unless (defined $attr)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2543
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2544
	croak new XML::DOM::DOMException (NOT_FOUND_ERR);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2545
	return undef;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2546
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2547
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2548
    my $name = $node->getNodeName;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2549
    my $attrNode = $attr->getNamedItem ($name);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2550
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2551
#?? should it croak if it's the default value?
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2552
    croak new XML::DOM::DOMException (NOT_FOUND_ERR)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2553
	unless $node == $attrNode;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2554
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2555
    # Not removing anything if it's the default value already
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2556
    return undef unless $node->isSpecified;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2557
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2558
    $attr->removeNamedItem ($name);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2559
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2560
    # Substitute with default value if it's defined
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2561
    my $default = $self->getDefaultAttrValue ($name);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2562
    if (defined $default)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2563
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2564
	local $XML::DOM::IgnoreReadOnly = 1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2565
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2566
	$default = $default->cloneNode (1);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2567
	$attr->setNamedItem ($default);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2568
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2569
    $node;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2570
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2571
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2572
sub removeAttribute
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2573
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2574
    my ($self, $name) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2575
    my $attr = $self->[_A];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2576
    unless (defined $attr)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2577
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2578
	croak new XML::DOM::DOMException (NOT_FOUND_ERR);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2579
	return;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2580
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2581
    
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2582
    my $node = $attr->getNamedItem ($name);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2583
    if (defined $node)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2584
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2585
#?? could use dispose() to remove circular references for gc, but what if
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2586
#?? somebody is referencing it?
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2587
	$self->removeAttributeNode ($node);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2588
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2589
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2590
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2591
sub cloneNode
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2592
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2593
    my ($self, $deep) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2594
    my $node = $self->[_Doc]->createElement ($self->getTagName);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2595
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2596
    # Always clone the Attr nodes, even if $deep == 0
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2597
    if (defined $self->[_A])
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2598
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2599
	$node->[_A] = $self->[_A]->cloneNode (1);	# deep=1
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2600
	$node->[_A]->setParentNode ($node);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2601
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2602
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2603
    $node->cloneChildren ($self, $deep);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2604
    $node;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2605
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2606
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2607
sub getAttributes
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2608
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2609
    $_[0]->[_A] ||= XML::DOM::NamedNodeMap->new (Doc	=> $_[0]->[_Doc],
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2610
						 Parent	=> $_[0]);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2611
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2612
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2613
#------------------------------------------------------------
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2614
# Extra method implementations
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2615
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2616
# Added for convenience
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2617
sub setTagName
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2618
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2619
    my ($self, $tagName) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2620
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2621
    croak new XML::DOM::DOMException (INVALID_CHARACTER_ERR, 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2622
				      "bad Element TagName [$tagName]")
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2623
        unless XML::DOM::isValidName ($tagName);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2624
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2625
    $self->[_TagName] = $tagName;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2626
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2627
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2628
sub isReadOnly
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2629
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2630
    0;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2631
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2632
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2633
# Added for optimization.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2634
sub isElementNode
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2635
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2636
    1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2637
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2638
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2639
sub rejectChild
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2640
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2641
    my $t = $_[1]->getNodeType;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2642
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2643
    $t != TEXT_NODE
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2644
    && $t != ENTITY_REFERENCE_NODE 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2645
    && $t != PROCESSING_INSTRUCTION_NODE
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2646
    && $t != COMMENT_NODE
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2647
    && $t != CDATA_SECTION_NODE
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2648
    && $t != ELEMENT_NODE;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2649
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2650
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2651
sub getDefaultAttrValue
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2652
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2653
    my ($self, $attr) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2654
    $self->[_Doc]->getDefaultAttrValue ($self->[_TagName], $attr);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2655
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2656
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2657
sub dispose
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2658
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2659
    my $self = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2660
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2661
    $self->[_A]->dispose if defined $self->[_A];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2662
    $self->SUPER::dispose;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2663
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2664
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2665
sub setOwnerDocument
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2666
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2667
    my ($self, $doc) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2668
    $self->SUPER::setOwnerDocument ($doc);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2669
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2670
    $self->[_A]->setOwnerDocument ($doc) if defined $self->[_A];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2671
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2672
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2673
sub print
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2674
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2675
    my ($self, $FILE) = @_;    
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2676
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2677
    my $name = $self->[_TagName];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2678
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2679
    $FILE->print ("<$name");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2680
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2681
    if (defined $self->[_A])
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2682
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2683
	for my $att (@{$self->[_A]->getValues})
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2684
	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2685
	    # skip un-specified (default) Attr nodes
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2686
	    if ($att->isSpecified)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2687
	    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2688
		$FILE->print (" ");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2689
		$att->print ($FILE);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2690
	    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2691
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2692
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2693
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2694
    my @kids = @{$self->[_C]};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2695
    if (@kids > 0)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2696
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2697
	$FILE->print (">");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2698
	for my $kid (@kids)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2699
	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2700
	    $kid->print ($FILE);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2701
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2702
	$FILE->print ("</$name>");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2703
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2704
    else
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2705
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2706
	my $style = &$XML::DOM::TagStyle ($name, $self);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2707
	if ($style == 0)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2708
	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2709
	    $FILE->print ("/>");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2710
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2711
	elsif ($style == 1)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2712
	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2713
	    $FILE->print ("></$name>");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2714
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2715
	else
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2716
	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2717
	    $FILE->print (" />");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2718
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2719
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2720
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2721
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2722
sub check
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2723
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2724
    my ($self, $checker) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2725
    die "Usage: \$xml_dom_elem->check (\$checker)" unless $checker; 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2726
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2727
    $checker->InitDomElem;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2728
    $self->to_expat ($checker);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2729
    $checker->FinalDomElem;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2730
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2731
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2732
sub to_expat
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2733
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2734
    my ($self, $iter) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2735
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2736
    my $tag = $self->getTagName;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2737
    $iter->Start ($tag);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2738
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2739
    if (defined $self->[_A])
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2740
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2741
	for my $attr ($self->[_A]->getValues)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2742
	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2743
	    $iter->Attr ($tag, $attr->getName, $attr->getValue, $attr->isSpecified);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2744
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2745
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2746
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2747
    $iter->EndAttr;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2748
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2749
    for my $kid ($self->getChildNodes)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2750
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2751
	$kid->to_expat ($iter);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2752
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2753
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2754
    $iter->End;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2755
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2756
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2757
sub _to_sax
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2758
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2759
    my ($self, $doch, $dtdh, $enth) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2760
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2761
    my $tag = $self->getTagName;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2762
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2763
    my @attr = ();
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2764
    my $attrOrder;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2765
    my $attrDefaulted;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2766
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2767
    if (defined $self->[_A])
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2768
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2769
	my @spec = ();		# names of specified attributes
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2770
	my @unspec = ();	# names of defaulted attributes
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2771
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2772
	for my $attr ($self->[_A]->getValues) 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2773
	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2774
	    my $attrName = $attr->getName;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2775
	    push @attr, $attrName, $attr->getValue;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2776
	    if ($attr->isSpecified)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2777
	    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2778
		push @spec, $attrName;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2779
	    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2780
	    else
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2781
	    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2782
		push @unspec, $attrName;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2783
	    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2784
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2785
	$attrOrder = [ @spec, @unspec ];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2786
	$attrDefaulted = @spec;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2787
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2788
    $doch->start_element (defined $attrOrder ? 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2789
			  { Name => $tag, 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2790
			    Attributes => { @attr },
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2791
			    AttributeOrder => $attrOrder,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2792
			    Defaulted => $attrDefaulted
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2793
			  } :
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2794
			  { Name => $tag, 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2795
			    Attributes => { @attr } 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2796
			  }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2797
			 );
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2798
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2799
    for my $kid ($self->getChildNodes)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2800
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2801
	$kid->_to_sax ($doch, $dtdh, $enth);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2802
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2803
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2804
    $doch->end_element ( { Name => $tag } );
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2805
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2806
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2807
######################################################################
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2808
package XML::DOM::CharacterData;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2809
######################################################################
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2810
use vars qw{ @ISA @EXPORT_OK %EXPORT_TAGS %HFIELDS };
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2811
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2812
BEGIN
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2813
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2814
    import XML::DOM::Node qw( :DEFAULT :Fields );
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2815
    XML::DOM::def_fields ("Data", "XML::DOM::Node");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2816
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2817
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2818
use XML::DOM::DOMException;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2819
use Carp;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2820
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2821
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2822
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2823
# CharacterData nodes should never be created directly, only subclassed!
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2824
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2825
sub new
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2826
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2827
    my ($class, $doc, $data) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2828
    my $self = bless [], $class;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2829
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2830
    $self->[_Doc] = $doc;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2831
    $self->[_Data] = $data;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2832
    $self;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2833
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2834
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2835
sub appendData
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2836
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2837
    my ($self, $data) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2838
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2839
    if ($XML::DOM::SafeMode)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2840
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2841
	croak new XML::DOM::DOMException (NO_MODIFICATION_ALLOWED_ERR,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2842
					  "node is ReadOnly")
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2843
	    if $self->isReadOnly;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2844
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2845
    $self->[_Data] .= $data;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2846
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2847
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2848
sub deleteData
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2849
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2850
    my ($self, $offset, $count) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2851
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2852
    croak new XML::DOM::DOMException (INDEX_SIZE_ERR,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2853
				      "bad offset [$offset]")
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2854
	if ($offset < 0 || $offset >= length ($self->[_Data]));
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2855
#?? DOM Spec says >, but >= makes more sense!
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2856
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2857
    croak new XML::DOM::DOMException (INDEX_SIZE_ERR,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2858
				      "negative count [$count]")
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2859
	if $count < 0;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2860
 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2861
    croak new XML::DOM::DOMException (NO_MODIFICATION_ALLOWED_ERR,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2862
				      "node is ReadOnly")
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2863
	if $self->isReadOnly;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2864
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2865
    substr ($self->[_Data], $offset, $count) = "";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2866
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2867
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2868
sub getData
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2869
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2870
    $_[0]->[_Data];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2871
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2872
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2873
sub getLength
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2874
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2875
    length $_[0]->[_Data];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2876
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2877
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2878
sub insertData
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2879
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2880
    my ($self, $offset, $data) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2881
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2882
    croak new XML::DOM::DOMException (INDEX_SIZE_ERR,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2883
				      "bad offset [$offset]")
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2884
	if ($offset < 0 || $offset >= length ($self->[_Data]));
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2885
#?? DOM Spec says >, but >= makes more sense!
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2886
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2887
    croak new XML::DOM::DOMException (NO_MODIFICATION_ALLOWED_ERR,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2888
				      "node is ReadOnly")
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2889
	if $self->isReadOnly;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2890
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2891
    substr ($self->[_Data], $offset, 0) = $data;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2892
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2893
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2894
sub replaceData
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2895
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2896
    my ($self, $offset, $count, $data) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2897
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2898
    croak new XML::DOM::DOMException (INDEX_SIZE_ERR,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2899
				      "bad offset [$offset]")
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2900
	if ($offset < 0 || $offset >= length ($self->[_Data]));
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2901
#?? DOM Spec says >, but >= makes more sense!
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2902
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2903
    croak new XML::DOM::DOMException (INDEX_SIZE_ERR,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2904
				      "negative count [$count]")
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2905
	if $count < 0;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2906
 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2907
    croak new XML::DOM::DOMException (NO_MODIFICATION_ALLOWED_ERR,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2908
				      "node is ReadOnly")
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2909
	if $self->isReadOnly;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2910
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2911
    substr ($self->[_Data], $offset, $count) = $data;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2912
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2913
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2914
sub setData
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2915
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2916
    my ($self, $data) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2917
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2918
    croak new XML::DOM::DOMException (NO_MODIFICATION_ALLOWED_ERR,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2919
				      "node is ReadOnly")
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2920
	if $self->isReadOnly;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2921
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2922
    $self->[_Data] = $data;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2923
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2924
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2925
sub substringData
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2926
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2927
    my ($self, $offset, $count) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2928
    my $data = $self->[_Data];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2929
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2930
    croak new XML::DOM::DOMException (INDEX_SIZE_ERR,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2931
				      "bad offset [$offset]")
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2932
	if ($offset < 0 || $offset >= length ($data));
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2933
#?? DOM Spec says >, but >= makes more sense!
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2934
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2935
    croak new XML::DOM::DOMException (INDEX_SIZE_ERR,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2936
				      "negative count [$count]")
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2937
	if $count < 0;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2938
    
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2939
    substr ($data, $offset, $count);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2940
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2941
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2942
sub getNodeValue
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2943
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2944
    $_[0]->getData;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2945
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2946
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2947
sub setNodeValue
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2948
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2949
    $_[0]->setData ($_[1]);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2950
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2951
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2952
######################################################################
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2953
package XML::DOM::CDATASection;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2954
######################################################################
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2955
use vars qw{ @ISA @EXPORT_OK %EXPORT_TAGS %HFIELDS };
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2956
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2957
BEGIN
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2958
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2959
    import XML::DOM::CharacterData qw( :DEFAULT :Fields );
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2960
    import XML::DOM::Node qw( :DEFAULT :Fields );
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2961
    XML::DOM::def_fields ("", "XML::DOM::CharacterData");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2962
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2963
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2964
use XML::DOM::DOMException;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2965
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2966
sub getNodeName
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2967
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2968
    "#cdata-section";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2969
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2970
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2971
sub getNodeType
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2972
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2973
    CDATA_SECTION_NODE;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2974
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2975
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2976
sub cloneNode
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2977
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2978
    my $self = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2979
    $self->[_Doc]->createCDATASection ($self->getData);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2980
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2981
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2982
#------------------------------------------------------------
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2983
# Extra method implementations
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2984
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2985
sub isReadOnly
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2986
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2987
    0;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2988
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2989
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2990
sub print
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2991
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2992
    my ($self, $FILE) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2993
    $FILE->print ("<![CDATA[");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2994
    $FILE->print (XML::DOM::encodeCDATA ($self->getData));
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2995
    $FILE->print ("]]>");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2996
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2997
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2998
sub to_expat
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  2999
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3000
    my ($self, $iter) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3001
    $iter->CData ($self->getData);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3002
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3003
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3004
sub _to_sax
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3005
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3006
    my ($self, $doch, $dtdh, $enth) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3007
    $doch->start_cdata;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3008
    $doch->characters ( { Data => $self->getData } );
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3009
    $doch->end_cdata;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3010
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3011
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3012
######################################################################
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3013
package XML::DOM::Comment;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3014
######################################################################
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3015
use vars qw{ @ISA @EXPORT_OK %EXPORT_TAGS %HFIELDS };
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3016
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3017
BEGIN
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3018
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3019
    import XML::DOM::CharacterData qw( :DEFAULT :Fields );
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3020
    import XML::DOM::Node qw( :DEFAULT :Fields );
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3021
    XML::DOM::def_fields ("", "XML::DOM::CharacterData");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3022
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3023
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3024
use XML::DOM::DOMException;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3025
use Carp;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3026
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3027
#?? setData - could check comment for double minus
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3028
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3029
sub getNodeType
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3030
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3031
    COMMENT_NODE;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3032
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3033
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3034
sub getNodeName
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3035
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3036
    "#comment";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3037
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3038
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3039
sub cloneNode
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3040
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3041
    my $self = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3042
    $self->[_Doc]->createComment ($self->getData);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3043
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3044
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3045
#------------------------------------------------------------
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3046
# Extra method implementations
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3047
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3048
sub isReadOnly
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3049
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3050
    return 0 if $XML::DOM::IgnoreReadOnly;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3051
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3052
    my $pa = $_[0]->[_Parent];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3053
    defined ($pa) ? $pa->isReadOnly : 0;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3054
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3055
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3056
sub print
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3057
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3058
    my ($self, $FILE) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3059
    my $comment = XML::DOM::encodeComment ($self->[_Data]);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3060
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3061
    $FILE->print ("<!--$comment-->");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3062
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3063
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3064
sub to_expat
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3065
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3066
    my ($self, $iter) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3067
    $iter->Comment ($self->getData);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3068
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3069
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3070
sub _to_sax
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3071
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3072
    my ($self, $doch, $dtdh, $enth) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3073
    $doch->Comment ( { Data => $self->getData });
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3074
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3075
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3076
######################################################################
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3077
package XML::DOM::Text;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3078
######################################################################
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3079
use vars qw{ @ISA @EXPORT_OK %EXPORT_TAGS %HFIELDS };
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3080
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3081
BEGIN
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3082
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3083
    import XML::DOM::CharacterData qw( :DEFAULT :Fields );
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3084
    import XML::DOM::Node qw( :DEFAULT :Fields );
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3085
    XML::DOM::def_fields ("", "XML::DOM::CharacterData");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3086
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3087
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3088
use XML::DOM::DOMException;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3089
use Carp;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3090
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3091
sub getNodeType
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3092
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3093
    TEXT_NODE;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3094
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3095
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3096
sub getNodeName
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3097
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3098
    "#text";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3099
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3100
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3101
sub splitText
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3102
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3103
    my ($self, $offset) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3104
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3105
    my $data = $self->getData;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3106
    croak new XML::DOM::DOMException (INDEX_SIZE_ERR,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3107
				      "bad offset [$offset]")
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3108
	if ($offset < 0 || $offset >= length ($data));
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3109
#?? DOM Spec says >, but >= makes more sense!
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3110
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3111
    croak new XML::DOM::DOMException (NO_MODIFICATION_ALLOWED_ERR,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3112
				      "node is ReadOnly")
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3113
	if $self->isReadOnly;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3114
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3115
    my $rest = substring ($data, $offset);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3116
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3117
    $self->setData (substring ($data, 0, $offset));
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3118
    my $node = $self->[_Doc]->createTextNode ($rest);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3119
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3120
    # insert new node after this node
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3121
    $self->[_Parent]->insertAfter ($node, $self);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3122
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3123
    $node;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3124
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3125
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3126
sub cloneNode
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3127
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3128
    my $self = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3129
    $self->[_Doc]->createTextNode ($self->getData);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3130
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3131
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3132
#------------------------------------------------------------
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3133
# Extra method implementations
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3134
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3135
sub isReadOnly
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3136
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3137
    0;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3138
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3139
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3140
sub print
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3141
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3142
    my ($self, $FILE) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3143
    $FILE->print (XML::DOM::encodeText ($self->getData, "<&"));
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3144
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3145
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3146
sub isTextNode
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3147
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3148
    1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3149
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3150
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3151
sub to_expat
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3152
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3153
    my ($self, $iter) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3154
    $iter->Char ($self->getData);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3155
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3156
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3157
sub _to_sax
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3158
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3159
    my ($self, $doch, $dtdh, $enth) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3160
    $doch->characters ( { Data => $self->getData } );
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3161
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3162
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3163
######################################################################
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3164
package XML::DOM::XMLDecl;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3165
######################################################################
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3166
use vars qw{ @ISA @EXPORT_OK %EXPORT_TAGS %HFIELDS };
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3167
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3168
BEGIN
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3169
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3170
    import XML::DOM::Node qw( :DEFAULT :Fields );
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3171
    XML::DOM::def_fields ("Version Encoding Standalone", "XML::DOM::Node");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3172
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3173
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3174
use XML::DOM::DOMException;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3175
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3176
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3177
#------------------------------------------------------------
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3178
# Extra method implementations
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3179
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3180
# XMLDecl is not part of the DOM Spec
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3181
sub new
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3182
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3183
    my ($class, $doc, $version, $encoding, $standalone) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3184
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3185
    my $self = bless [], $class;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3186
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3187
    $self->[_Doc] = $doc;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3188
    $self->[_Version] = $version if defined $version;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3189
    $self->[_Encoding] = $encoding if defined $encoding;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3190
    $self->[_Standalone] = $standalone if defined $standalone;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3191
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3192
    $self;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3193
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3194
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3195
sub setVersion
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3196
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3197
    if (defined $_[1])
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3198
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3199
	$_[0]->[_Version] = $_[1];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3200
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3201
    else
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3202
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3203
	undef $_[0]->[_Version]; # was delete
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3204
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3205
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3206
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3207
sub getVersion
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3208
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3209
    $_[0]->[_Version];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3210
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3211
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3212
sub setEncoding
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3213
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3214
    if (defined $_[1])
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3215
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3216
	$_[0]->[_Encoding] = $_[1];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3217
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3218
    else
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3219
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3220
	undef $_[0]->[_Encoding]; # was delete
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3221
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3222
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3223
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3224
sub getEncoding
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3225
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3226
    $_[0]->[_Encoding];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3227
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3228
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3229
sub setStandalone
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3230
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3231
    if (defined $_[1])
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3232
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3233
	$_[0]->[_Standalone] = $_[1];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3234
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3235
    else
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3236
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3237
	undef $_[0]->[_Standalone]; # was delete
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3238
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3239
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3240
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3241
sub getStandalone
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3242
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3243
    $_[0]->[_Standalone];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3244
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3245
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3246
sub getNodeType
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3247
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3248
    XML_DECL_NODE;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3249
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3250
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3251
sub cloneNode
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3252
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3253
    my $self = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3254
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3255
    new XML::DOM::XMLDecl ($self->[_Doc], $self->[_Version], 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3256
			   $self->[_Encoding], $self->[_Standalone]);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3257
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3258
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3259
sub print
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3260
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3261
    my ($self, $FILE) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3262
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3263
    my $version = $self->[_Version];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3264
    my $encoding = $self->[_Encoding];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3265
    my $standalone = $self->[_Standalone];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3266
    $standalone = ($standalone ? "yes" : "no") if defined $standalone;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3267
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3268
    $FILE->print ("<?xml");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3269
    $FILE->print (" version=\"$version\"")	 if defined $version;    
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3270
    $FILE->print (" encoding=\"$encoding\"")	 if defined $encoding;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3271
    $FILE->print (" standalone=\"$standalone\"") if defined $standalone;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3272
    $FILE->print ("?>");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3273
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3274
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3275
sub to_expat
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3276
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3277
    my ($self, $iter) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3278
    $iter->XMLDecl ($self->getVersion, $self->getEncoding, $self->getStandalone);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3279
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3280
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3281
sub _to_sax
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3282
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3283
    my ($self, $doch, $dtdh, $enth) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3284
    $dtdh->xml_decl ( { Version => $self->getVersion, 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3285
			Encoding => $self->getEncoding, 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3286
			Standalone => $self->getStandalone } );
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3287
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3288
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3289
######################################################################
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3290
package XML::DOM::DocumentFragment;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3291
######################################################################
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3292
use vars qw{ @ISA @EXPORT_OK %EXPORT_TAGS %HFIELDS };
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3293
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3294
BEGIN
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3295
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3296
    import XML::DOM::Node qw( :DEFAULT :Fields );
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3297
    XML::DOM::def_fields ("", "XML::DOM::Node");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3298
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3299
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3300
use XML::DOM::DOMException;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3301
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3302
sub new
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3303
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3304
    my ($class, $doc) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3305
    my $self = bless [], $class;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3306
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3307
    $self->[_Doc] = $doc;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3308
    $self->[_C] = new XML::DOM::NodeList;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3309
    $self;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3310
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3311
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3312
sub getNodeType
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3313
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3314
    DOCUMENT_FRAGMENT_NODE;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3315
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3316
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3317
sub getNodeName
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3318
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3319
    "#document-fragment";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3320
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3321
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3322
sub cloneNode
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3323
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3324
    my ($self, $deep) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3325
    my $node = $self->[_Doc]->createDocumentFragment;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3326
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3327
    $node->cloneChildren ($self, $deep);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3328
    $node;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3329
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3330
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3331
#------------------------------------------------------------
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3332
# Extra method implementations
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3333
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3334
sub isReadOnly
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3335
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3336
    0;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3337
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3338
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3339
sub print
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3340
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3341
    my ($self, $FILE) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3342
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3343
    for my $node (@{$self->[_C]})
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3344
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3345
	$node->print ($FILE);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3346
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3347
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3348
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3349
sub rejectChild
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3350
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3351
    my $t = $_[1]->getNodeType;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3352
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3353
    $t != TEXT_NODE
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3354
	&& $t != ENTITY_REFERENCE_NODE 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3355
	&& $t != PROCESSING_INSTRUCTION_NODE
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3356
	&& $t != COMMENT_NODE
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3357
	&& $t != CDATA_SECTION_NODE
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3358
	&& $t != ELEMENT_NODE;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3359
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3360
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3361
sub isDocumentFragmentNode
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3362
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3363
    1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3364
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3365
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3366
######################################################################
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3367
package XML::DOM::Document;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3368
######################################################################
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3369
use vars qw{ @ISA @EXPORT_OK %EXPORT_TAGS %HFIELDS };
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3370
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3371
BEGIN
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3372
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3373
    import XML::DOM::Node qw( :DEFAULT :Fields );
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3374
    XML::DOM::def_fields ("Doctype XmlDecl", "XML::DOM::Node");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3375
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3376
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3377
use Carp;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3378
use XML::DOM::NodeList;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3379
use XML::DOM::DOMException;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3380
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3381
sub new
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3382
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3383
    my ($class) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3384
    my $self = bless [], $class;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3385
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3386
    # keep Doc pointer, even though getOwnerDocument returns undef
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3387
    $self->[_Doc] = $self;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3388
    $self->[_C] = new XML::DOM::NodeList;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3389
    $self;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3390
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3391
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3392
sub getNodeType
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3393
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3394
    DOCUMENT_NODE;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3395
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3396
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3397
sub getNodeName
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3398
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3399
    "#document";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3400
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3401
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3402
#?? not sure about keeping a fixed order of these nodes....
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3403
sub getDoctype
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3404
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3405
    $_[0]->[_Doctype];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3406
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3407
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3408
sub getDocumentElement
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3409
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3410
    my ($self) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3411
    for my $kid (@{$self->[_C]})
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3412
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3413
	return $kid if $kid->isElementNode;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3414
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3415
    undef;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3416
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3417
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3418
sub getOwnerDocument
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3419
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3420
    undef;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3421
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3422
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3423
sub getImplementation 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3424
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3425
    $XML::DOM::DOMImplementation::Singleton;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3426
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3427
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3428
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3429
# Added extra parameters ($val, $specified) that are passed straight to the
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3430
# Attr constructor
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3431
# 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3432
sub createAttribute
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3433
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3434
    new XML::DOM::Attr (@_);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3435
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3436
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3437
sub createCDATASection
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3438
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3439
    new XML::DOM::CDATASection (@_);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3440
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3441
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3442
sub createComment
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3443
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3444
    new XML::DOM::Comment (@_);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3445
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3446
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3447
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3448
sub createElement
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3449
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3450
    new XML::DOM::Element (@_);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3451
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3452
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3453
sub createTextNode
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3454
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3455
    new XML::DOM::Text (@_);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3456
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3457
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3458
sub createProcessingInstruction
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3459
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3460
    new XML::DOM::ProcessingInstruction (@_);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3461
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3462
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3463
sub createEntityReference
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3464
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3465
    new XML::DOM::EntityReference (@_);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3466
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3467
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3468
sub createDocumentFragment
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3469
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3470
    new XML::DOM::DocumentFragment (@_);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3471
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3472
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3473
sub createDocumentType
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3474
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3475
    new XML::DOM::DocumentType (@_);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3476
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3477
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3478
sub cloneNode
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3479
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3480
    my ($self, $deep) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3481
    my $node = new XML::DOM::Document;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3482
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3483
    $node->cloneChildren ($self, $deep);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3484
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3485
    my $xmlDecl = $self->[_XmlDecl];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3486
    $node->[_XmlDecl] = $xmlDecl->cloneNode ($deep) if defined $xmlDecl;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3487
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3488
    $node;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3489
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3490
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3491
sub appendChild
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3492
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3493
    my ($self, $node) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3494
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3495
    # Extra check: make sure we don't end up with more than one Element.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3496
    # Don't worry about multiple DocType nodes, because DocumentFragment
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3497
    # can't contain DocType nodes.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3498
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3499
    my @nodes = ($node);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3500
    @nodes = @{$node->[_C]}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3501
        if $node->getNodeType == DOCUMENT_FRAGMENT_NODE;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3502
    
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3503
    my $elem = 0;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3504
    for my $n (@nodes)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3505
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3506
	$elem++ if $n->isElementNode;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3507
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3508
    
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3509
    if ($elem > 0 && defined ($self->getDocumentElement))
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3510
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3511
	croak new XML::DOM::DOMException (HIERARCHY_REQUEST_ERR,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3512
					  "document can have only one Element");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3513
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3514
    $self->SUPER::appendChild ($node);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3515
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3516
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3517
sub insertBefore
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3518
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3519
    my ($self, $node, $refNode) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3520
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3521
    # Extra check: make sure sure we don't end up with more than 1 Elements.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3522
    # Don't worry about multiple DocType nodes, because DocumentFragment
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3523
    # can't contain DocType nodes.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3524
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3525
    my @nodes = ($node);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3526
    @nodes = @{$node->[_C]}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3527
	if $node->getNodeType == DOCUMENT_FRAGMENT_NODE;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3528
    
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3529
    my $elem = 0;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3530
    for my $n (@nodes)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3531
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3532
	$elem++ if $n->isElementNode;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3533
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3534
    
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3535
    if ($elem > 0 && defined ($self->getDocumentElement))
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3536
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3537
	croak new XML::DOM::DOMException (HIERARCHY_REQUEST_ERR,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3538
					  "document can have only one Element");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3539
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3540
    $self->SUPER::insertBefore ($node, $refNode);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3541
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3542
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3543
sub replaceChild
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3544
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3545
    my ($self, $node, $refNode) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3546
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3547
    # Extra check: make sure sure we don't end up with more than 1 Elements.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3548
    # Don't worry about multiple DocType nodes, because DocumentFragment
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3549
    # can't contain DocType nodes.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3550
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3551
    my @nodes = ($node);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3552
    @nodes = @{$node->[_C]}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3553
	if $node->getNodeType == DOCUMENT_FRAGMENT_NODE;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3554
    
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3555
    my $elem = 0;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3556
    $elem-- if $refNode->isElementNode;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3557
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3558
    for my $n (@nodes)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3559
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3560
	$elem++ if $n->isElementNode;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3561
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3562
    
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3563
    if ($elem > 0 && defined ($self->getDocumentElement))
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3564
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3565
	croak new XML::DOM::DOMException (HIERARCHY_REQUEST_ERR,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3566
					  "document can have only one Element");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3567
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3568
    $self->SUPER::appendChild ($node, $refNode);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3569
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3570
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3571
#------------------------------------------------------------
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3572
# Extra method implementations
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3573
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3574
sub isReadOnly
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3575
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3576
    0;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3577
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3578
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3579
sub print
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3580
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3581
    my ($self, $FILE) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3582
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3583
    my $xmlDecl = $self->getXMLDecl;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3584
    if (defined $xmlDecl)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3585
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3586
	$xmlDecl->print ($FILE);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3587
	$FILE->print ("\x0A");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3588
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3589
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3590
    for my $node (@{$self->[_C]})
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3591
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3592
	$node->print ($FILE);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3593
	$FILE->print ("\x0A");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3594
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3595
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3596
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3597
sub setDoctype
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3598
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3599
    my ($self, $doctype) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3600
    my $oldDoctype = $self->[_Doctype];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3601
    if (defined $oldDoctype)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3602
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3603
	$self->replaceChild ($doctype, $oldDoctype);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3604
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3605
    else
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3606
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3607
#?? before root element, but after XmlDecl !
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3608
	$self->appendChild ($doctype);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3609
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3610
    $_[0]->[_Doctype] = $_[1];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3611
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3612
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3613
sub removeDoctype
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3614
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3615
    my $self = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3616
    my $doctype = $self->removeChild ($self->[_Doctype]);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3617
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3618
    undef $self->[_Doctype]; # was delete
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3619
    $doctype;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3620
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3621
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3622
sub rejectChild
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3623
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3624
    my $t = $_[1]->getNodeType;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3625
    $t != ELEMENT_NODE
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3626
	&& $t != PROCESSING_INSTRUCTION_NODE
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3627
	&& $t != COMMENT_NODE
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3628
	&& $t != DOCUMENT_TYPE_NODE;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3629
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3630
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3631
sub expandEntity
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3632
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3633
    my ($self, $ent, $param) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3634
    my $doctype = $self->getDoctype;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3635
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3636
    (defined $doctype) ? $doctype->expandEntity ($ent, $param) : undef;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3637
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3638
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3639
sub getDefaultAttrValue
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3640
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3641
    my ($self, $elem, $attr) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3642
    
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3643
    my $doctype = $self->getDoctype;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3644
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3645
    (defined $doctype) ? $doctype->getDefaultAttrValue ($elem, $attr) : undef;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3646
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3647
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3648
sub getEntity
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3649
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3650
    my ($self, $entity) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3651
    
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3652
    my $doctype = $self->getDoctype;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3653
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3654
    (defined $doctype) ? $doctype->getEntity ($entity) : undef;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3655
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3656
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3657
sub dispose
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3658
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3659
    my $self = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3660
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3661
    $self->[_XmlDecl]->dispose if defined $self->[_XmlDecl];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3662
    undef $self->[_XmlDecl]; # was delete
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3663
    undef $self->[_Doctype]; # was delete
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3664
    $self->SUPER::dispose;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3665
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3666
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3667
sub setOwnerDocument
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3668
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3669
    # Do nothing, you can't change the owner document!
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3670
#?? could throw exception...
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3671
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3672
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3673
sub getXMLDecl
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3674
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3675
    $_[0]->[_XmlDecl];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3676
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3677
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3678
sub setXMLDecl
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3679
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3680
    $_[0]->[_XmlDecl] = $_[1];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3681
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3682
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3683
sub createXMLDecl
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3684
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3685
    new XML::DOM::XMLDecl (@_);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3686
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3687
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3688
sub createNotation
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3689
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3690
    new XML::DOM::Notation (@_);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3691
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3692
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3693
sub createElementDecl
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3694
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3695
    new XML::DOM::ElementDecl (@_);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3696
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3697
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3698
sub createAttlistDecl
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3699
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3700
    new XML::DOM::AttlistDecl (@_);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3701
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3702
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3703
sub createEntity
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3704
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3705
    new XML::DOM::Entity (@_);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3706
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3707
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3708
sub createChecker
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3709
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3710
    my $self = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3711
    my $checker = XML::Checker->new;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3712
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3713
    $checker->Init;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3714
    my $doctype = $self->getDoctype;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3715
    $doctype->to_expat ($checker) if $doctype;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3716
    $checker->Final;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3717
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3718
    $checker;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3719
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3720
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3721
sub check
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3722
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3723
    my ($self, $checker) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3724
    $checker ||= XML::Checker->new;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3725
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3726
    $self->to_expat ($checker);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3727
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3728
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3729
sub to_expat
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3730
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3731
    my ($self, $iter) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3732
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3733
    $iter->Init;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3734
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3735
    for my $kid ($self->getChildNodes)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3736
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3737
	$kid->to_expat ($iter);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3738
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3739
    $iter->Final;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3740
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3741
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3742
sub check_sax
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3743
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3744
    my ($self, $checker) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3745
    $checker ||= XML::Checker->new;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3746
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3747
    $self->to_sax (Handler => $checker);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3748
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3749
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3750
sub _to_sax
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3751
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3752
    my ($self, $doch, $dtdh, $enth) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3753
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3754
    $doch->start_document;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3755
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3756
    for my $kid ($self->getChildNodes)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3757
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3758
	$kid->_to_sax ($doch, $dtdh, $enth);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3759
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3760
    $doch->end_document;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3761
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3762
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3763
######################################################################
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3764
package XML::DOM::DocumentType;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3765
######################################################################
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3766
use vars qw{ @ISA @EXPORT_OK %EXPORT_TAGS %HFIELDS };
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3767
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3768
BEGIN
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3769
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3770
    import XML::DOM::Node qw( :DEFAULT :Fields );
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3771
    import XML::DOM::Document qw( :Fields );
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3772
    XML::DOM::def_fields ("Entities Notations Name SysId PubId Internal", "XML::DOM::Node");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3773
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3774
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3775
use XML::DOM::DOMException;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3776
use XML::DOM::NamedNodeMap;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3777
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3778
sub new
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3779
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3780
    my $class = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3781
    my $doc = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3782
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3783
    my $self = bless [], $class;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3784
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3785
    $self->[_Doc] = $doc;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3786
    $self->[_ReadOnly] = 1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3787
    $self->[_C] = new XML::DOM::NodeList;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3788
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3789
    $self->[_Entities] =  new XML::DOM::NamedNodeMap (Doc	=> $doc,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3790
						      Parent	=> $self,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3791
						      ReadOnly	=> 1);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3792
    $self->[_Notations] = new XML::DOM::NamedNodeMap (Doc	=> $doc,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3793
						      Parent	=> $self,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3794
						      ReadOnly	=> 1);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3795
    $self->setParams (@_);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3796
    $self;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3797
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3798
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3799
sub getNodeType
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3800
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3801
    DOCUMENT_TYPE_NODE;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3802
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3803
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3804
sub getNodeName
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3805
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3806
    $_[0]->[_Name];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3807
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3808
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3809
sub getName
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3810
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3811
    $_[0]->[_Name];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3812
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3813
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3814
sub getEntities
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3815
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3816
    $_[0]->[_Entities];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3817
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3818
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3819
sub getNotations
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3820
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3821
    $_[0]->[_Notations];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3822
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3823
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3824
sub setParentNode
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3825
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3826
    my ($self, $parent) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3827
    $self->SUPER::setParentNode ($parent);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3828
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3829
    $parent->[_Doctype] = $self 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3830
	if $parent->getNodeType == DOCUMENT_NODE;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3831
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3832
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3833
sub cloneNode
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3834
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3835
    my ($self, $deep) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3836
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3837
    my $node = new XML::DOM::DocumentType ($self->[_Doc], $self->[_Name], 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3838
					   $self->[_SysId], $self->[_PubId], 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3839
					   $self->[_Internal]);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3840
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3841
#?? does it make sense to make a shallow copy?
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3842
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3843
    # clone the NamedNodeMaps
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3844
    $node->[_Entities] = $self->[_Entities]->cloneNode ($deep);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3845
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3846
    $node->[_Notations] = $self->[_Notations]->cloneNode ($deep);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3847
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3848
    $node->cloneChildren ($self, $deep);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3849
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3850
    $node;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3851
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3852
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3853
#------------------------------------------------------------
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3854
# Extra method implementations
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3855
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3856
sub getSysId
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3857
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3858
    $_[0]->[_SysId];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3859
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3860
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3861
sub getPubId
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3862
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3863
    $_[0]->[_PubId];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3864
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3865
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3866
sub getInternal
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3867
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3868
    $_[0]->[_Internal];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3869
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3870
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3871
sub setSysId
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3872
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3873
    $_[0]->[_SysId] = $_[1];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3874
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3875
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3876
sub setPubId
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3877
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3878
    $_[0]->[_PubId] = $_[1];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3879
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3880
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3881
sub setInternal
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3882
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3883
    $_[0]->[_Internal] = $_[1];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3884
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3885
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3886
sub setName
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3887
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3888
    $_[0]->[_Name] = $_[1];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3889
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3890
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3891
sub removeChildHoodMemories
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3892
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3893
    my ($self, $dontWipeReadOnly) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3894
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3895
    my $parent = $self->[_Parent];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3896
    if (defined $parent && $parent->getNodeType == DOCUMENT_NODE)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3897
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3898
	undef $parent->[_Doctype]; # was delete
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3899
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3900
    $self->SUPER::removeChildHoodMemories;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3901
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3902
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3903
sub dispose
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3904
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3905
    my $self = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3906
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3907
    $self->[_Entities]->dispose;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3908
    $self->[_Notations]->dispose;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3909
    $self->SUPER::dispose;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3910
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3911
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3912
sub setOwnerDocument
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3913
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3914
    my ($self, $doc) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3915
    $self->SUPER::setOwnerDocument ($doc);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3916
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3917
    $self->[_Entities]->setOwnerDocument ($doc);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3918
    $self->[_Notations]->setOwnerDocument ($doc);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3919
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3920
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3921
sub expandEntity
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3922
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3923
    my ($self, $ent, $param) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3924
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3925
    my $kid = $self->[_Entities]->getNamedItem ($ent);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3926
    return $kid->getValue
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3927
	if (defined ($kid) && $param == $kid->isParameterEntity);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3928
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3929
    undef;	# entity not found
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3930
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3931
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3932
sub getAttlistDecl
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3933
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3934
    my ($self, $elemName) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3935
    for my $kid (@{$_[0]->[_C]})
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3936
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3937
	return $kid if ($kid->getNodeType == ATTLIST_DECL_NODE &&
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3938
			$kid->getName eq $elemName);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3939
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3940
    undef;	# not found
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3941
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3942
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3943
sub getElementDecl
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3944
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3945
    my ($self, $elemName) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3946
    for my $kid (@{$_[0]->[_C]})
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3947
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3948
	return $kid if ($kid->getNodeType == ELEMENT_DECL_NODE &&
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3949
			$kid->getName eq $elemName);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3950
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3951
    undef;	# not found
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3952
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3953
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3954
sub addElementDecl
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3955
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3956
    my ($self, $name, $model, $hidden) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3957
    my $node = $self->getElementDecl ($name);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3958
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3959
#?? could warn
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3960
    unless (defined $node)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3961
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3962
	$node = $self->[_Doc]->createElementDecl ($name, $model, $hidden);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3963
	$self->appendChild ($node);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3964
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3965
    $node;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3966
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3967
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3968
sub addAttlistDecl
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3969
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3970
    my ($self, $name) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3971
    my $node = $self->getAttlistDecl ($name);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3972
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3973
    unless (defined $node)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3974
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3975
	$node = $self->[_Doc]->createAttlistDecl ($name);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3976
	$self->appendChild ($node);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3977
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3978
    $node;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3979
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3980
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3981
sub addNotation
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3982
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3983
    my $self = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3984
    my $node = $self->[_Doc]->createNotation (@_);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3985
    $self->[_Notations]->setNamedItem ($node);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3986
    $node;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3987
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3988
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3989
sub addEntity
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3990
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3991
    my $self = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3992
    my $node = $self->[_Doc]->createEntity (@_);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3993
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3994
    $self->[_Entities]->setNamedItem ($node);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3995
    $node;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3996
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3997
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3998
# All AttDefs for a certain Element are merged into a single ATTLIST
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  3999
sub addAttDef
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4000
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4001
    my $self = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4002
    my $elemName = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4003
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4004
    # create the AttlistDecl if it doesn't exist yet
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4005
    my $attListDecl = $self->addAttlistDecl ($elemName);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4006
    $attListDecl->addAttDef (@_);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4007
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4008
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4009
sub getDefaultAttrValue
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4010
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4011
    my ($self, $elem, $attr) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4012
    my $elemNode = $self->getAttlistDecl ($elem);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4013
    (defined $elemNode) ? $elemNode->getDefaultAttrValue ($attr) : undef;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4014
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4015
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4016
sub getEntity
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4017
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4018
    my ($self, $entity) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4019
    $self->[_Entities]->getNamedItem ($entity);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4020
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4021
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4022
sub setParams
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4023
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4024
    my ($self, $name, $sysid, $pubid, $internal) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4025
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4026
    $self->[_Name] = $name;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4027
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4028
#?? not sure if we need to hold on to these...
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4029
    $self->[_SysId] = $sysid if defined $sysid;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4030
    $self->[_PubId] = $pubid if defined $pubid;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4031
    $self->[_Internal] = $internal if defined $internal;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4032
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4033
    $self;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4034
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4035
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4036
sub rejectChild
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4037
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4038
    # DOM Spec says: DocumentType -- no children
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4039
    not $XML::DOM::IgnoreReadOnly;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4040
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4041
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4042
sub print
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4043
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4044
    my ($self, $FILE) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4045
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4046
    my $name = $self->[_Name];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4047
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4048
    my $sysId = $self->[_SysId];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4049
    my $pubId = $self->[_PubId];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4050
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4051
    $FILE->print ("<!DOCTYPE $name");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4052
    if (defined $pubId)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4053
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4054
	$FILE->print (" PUBLIC \"$pubId\" \"$sysId\"");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4055
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4056
    elsif (defined $sysId)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4057
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4058
	$FILE->print (" SYSTEM \"$sysId\"");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4059
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4060
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4061
    my @entities = @{$self->[_Entities]->getValues};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4062
    my @notations = @{$self->[_Notations]->getValues};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4063
    my @kids = @{$self->[_C]};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4064
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4065
    if (@entities || @notations || @kids)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4066
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4067
	$FILE->print (" [\x0A");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4068
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4069
	for my $kid (@entities)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4070
	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4071
	    next if $kid->[_Hidden];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4072
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4073
	    $FILE->print (" ");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4074
	    $kid->print ($FILE);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4075
	    $FILE->print ("\x0A");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4076
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4077
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4078
	for my $kid (@notations)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4079
	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4080
	    next if $kid->[_Hidden];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4081
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4082
	    $FILE->print (" ");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4083
	    $kid->print ($FILE);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4084
	    $FILE->print ("\x0A");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4085
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4086
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4087
	for my $kid (@kids)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4088
	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4089
	    next if $kid->[_Hidden];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4090
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4091
	    $FILE->print (" ");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4092
	    $kid->print ($FILE);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4093
	    $FILE->print ("\x0A");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4094
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4095
	$FILE->print ("]");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4096
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4097
    $FILE->print (">");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4098
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4099
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4100
sub to_expat
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4101
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4102
    my ($self, $iter) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4103
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4104
    $iter->Doctype ($self->getName, $self->getSysId, $self->getPubId, $self->getInternal);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4105
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4106
    for my $ent ($self->getEntities->getValues)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4107
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4108
	next if $ent->[_Hidden];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4109
	$ent->to_expat ($iter);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4110
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4111
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4112
    for my $nota ($self->getNotations->getValues)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4113
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4114
	next if $nota->[_Hidden];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4115
	$nota->to_expat ($iter);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4116
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4117
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4118
    for my $kid ($self->getChildNodes)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4119
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4120
	next if $kid->[_Hidden];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4121
	$kid->to_expat ($iter);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4122
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4123
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4124
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4125
sub _to_sax
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4126
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4127
    my ($self, $doch, $dtdh, $enth) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4128
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4129
    $dtdh->doctype_decl ( { Name => $self->getName, 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4130
			    SystemId => $self->getSysId, 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4131
			    PublicId => $self->getPubId, 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4132
			    Internal => $self->getInternal });
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4133
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4134
    for my $ent ($self->getEntities->getValues)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4135
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4136
	next if $ent->[_Hidden];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4137
	$ent->_to_sax ($doch, $dtdh, $enth);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4138
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4139
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4140
    for my $nota ($self->getNotations->getValues)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4141
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4142
	next if $nota->[_Hidden];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4143
	$nota->_to_sax ($doch, $dtdh, $enth);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4144
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4145
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4146
    for my $kid ($self->getChildNodes)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4147
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4148
	next if $kid->[_Hidden];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4149
	$kid->_to_sax ($doch, $dtdh, $enth);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4150
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4151
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4152
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4153
######################################################################
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4154
package XML::DOM::Parser;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4155
######################################################################
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4156
use vars qw ( @ISA );
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4157
@ISA = qw( XML::Parser );
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4158
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4159
sub new
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4160
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4161
    my ($class, %args) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4162
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4163
    $args{Style} = 'Dom';
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4164
    $class->SUPER::new (%args);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4165
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4166
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4167
# This method needed to be overriden so we can restore some global 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4168
# variables when an exception is thrown
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4169
sub parse
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4170
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4171
    my $self = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4172
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4173
    local $XML::Parser::Dom::_DP_doc;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4174
    local $XML::Parser::Dom::_DP_elem;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4175
    local $XML::Parser::Dom::_DP_doctype;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4176
    local $XML::Parser::Dom::_DP_in_prolog;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4177
    local $XML::Parser::Dom::_DP_end_doc;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4178
    local $XML::Parser::Dom::_DP_saw_doctype;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4179
    local $XML::Parser::Dom::_DP_in_CDATA;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4180
    local $XML::Parser::Dom::_DP_keep_CDATA;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4181
    local $XML::Parser::Dom::_DP_last_text;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4182
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4183
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4184
    # Temporarily disable checks that Expat already does (for performance)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4185
    local $XML::DOM::SafeMode = 0;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4186
    # Temporarily disable ReadOnly checks
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4187
    local $XML::DOM::IgnoreReadOnly = 1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4188
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4189
    my $ret;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4190
    eval {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4191
	$ret = $self->SUPER::parse (@_);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4192
    };
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4193
    my $err = $@;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4194
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4195
    if ($err)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4196
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4197
	my $doc = $XML::Parser::Dom::_DP_doc;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4198
	if ($doc)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4199
	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4200
	    $doc->dispose;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4201
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4202
	die $err;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4203
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4204
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4205
    $ret;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4206
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4207
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4208
my $LWP_USER_AGENT;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4209
sub set_LWP_UserAgent
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4210
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4211
    $LWP_USER_AGENT = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4212
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4213
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4214
sub parsefile
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4215
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4216
    my $self = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4217
    my $url = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4218
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4219
    # Any other URL schemes?
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4220
    if ($url =~ /^(https?|ftp|wais|gopher|file):/)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4221
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4222
	# Read the file from the web with LWP.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4223
	#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4224
	# Note that we read in the entire file, which may not be ideal
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4225
	# for large files. LWP::UserAgent also provides a callback style
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4226
	# request, which we could convert to a stream with a fork()...
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4227
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4228
	my $result;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4229
	eval
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4230
	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4231
	    use LWP::UserAgent;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4232
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4233
	    my $ua = $self->{LWP_UserAgent};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4234
	    unless (defined $ua)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4235
	    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4236
		unless (defined $LWP_USER_AGENT)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4237
		{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4238
		    $LWP_USER_AGENT = LWP::UserAgent->new;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4239
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4240
		    # Load proxy settings from environment variables, i.e.:
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4241
		    # http_proxy, ftp_proxy, no_proxy etc. (see LWP::UserAgent(3))
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4242
		    # You need these to go thru firewalls.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4243
		    $LWP_USER_AGENT->env_proxy;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4244
		}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4245
		$ua = $LWP_USER_AGENT;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4246
	    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4247
	    my $req = new HTTP::Request 'GET', $url;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4248
	    my $response = $LWP_USER_AGENT->request ($req);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4249
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4250
	    # Parse the result of the HTTP request
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4251
	    $result = $self->parse ($response->content, @_);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4252
	};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4253
	if ($@)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4254
	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4255
	    die "Couldn't parsefile [$url] with LWP: $@";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4256
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4257
	return $result;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4258
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4259
    else
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4260
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4261
	return $self->SUPER::parsefile ($url, @_);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4262
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4263
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4264
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4265
######################################################################
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4266
package XML::Parser::Dom;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4267
######################################################################
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4268
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4269
BEGIN
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4270
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4271
    import XML::DOM::Node qw( :Fields );
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4272
    import XML::DOM::CharacterData qw( :Fields );
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4273
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4274
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4275
use vars qw( $_DP_doc
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4276
	     $_DP_elem
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4277
	     $_DP_doctype
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4278
	     $_DP_in_prolog
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4279
	     $_DP_end_doc
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4280
	     $_DP_saw_doctype
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4281
	     $_DP_in_CDATA
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4282
	     $_DP_keep_CDATA
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4283
	     $_DP_last_text
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4284
	     $_DP_level
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4285
	     $_DP_expand_pent
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4286
	   );
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4287
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4288
# This adds a new Style to the XML::Parser class.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4289
# From now on you can say: $parser = new XML::Parser ('Style' => 'Dom' );
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4290
# but that is *NOT* how a regular user should use it!
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4291
$XML::Parser::Built_In_Styles{Dom} = 1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4292
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4293
sub Init
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4294
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4295
    $_DP_elem = $_DP_doc = new XML::DOM::Document();
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4296
    $_DP_doctype = new XML::DOM::DocumentType ($_DP_doc);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4297
    $_DP_doc->setDoctype ($_DP_doctype);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4298
    $_DP_keep_CDATA = $_[0]->{KeepCDATA};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4299
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4300
    # Prepare for document prolog
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4301
    $_DP_in_prolog = 1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4302
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4303
    # We haven't passed the root element yet
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4304
    $_DP_end_doc = 0;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4305
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4306
    # Expand parameter entities in the DTD by default
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4307
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4308
    $_DP_expand_pent = defined $_[0]->{ExpandParamEnt} ? 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4309
					$_[0]->{ExpandParamEnt} : 1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4310
    if ($_DP_expand_pent)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4311
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4312
	$_[0]->{DOM_Entity} = {};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4313
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4314
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4315
    $_DP_level = 0;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4316
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4317
    undef $_DP_last_text;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4318
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4319
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4320
sub Final
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4321
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4322
    unless ($_DP_saw_doctype)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4323
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4324
	my $doctype = $_DP_doc->removeDoctype;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4325
	$doctype->dispose;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4326
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4327
    $_DP_doc;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4328
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4329
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4330
sub Char
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4331
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4332
    my $str = $_[1];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4333
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4334
    if ($_DP_in_CDATA && $_DP_keep_CDATA)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4335
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4336
	undef $_DP_last_text;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4337
	# Merge text with previous node if possible
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4338
	$_DP_elem->addCDATA ($str);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4339
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4340
    else
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4341
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4342
	# Merge text with previous node if possible
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4343
	# Used to be:	$expat->{DOM_Element}->addText ($str);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4344
	if ($_DP_last_text)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4345
	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4346
	    $_DP_last_text->[_Data] .= $str;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4347
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4348
	else
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4349
	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4350
	    $_DP_last_text = $_DP_doc->createTextNode ($str);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4351
	    $_DP_last_text->[_Parent] = $_DP_elem;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4352
	    push @{$_DP_elem->[_C]}, $_DP_last_text;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4353
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4354
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4355
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4356
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4357
sub Start
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4358
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4359
    my ($expat, $elem, @attr) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4360
    my $parent = $_DP_elem;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4361
    my $doc = $_DP_doc;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4362
    
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4363
    if ($parent == $doc)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4364
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4365
	# End of document prolog, i.e. start of first Element
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4366
	$_DP_in_prolog = 0;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4367
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4368
    
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4369
    undef $_DP_last_text;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4370
    my $node = $doc->createElement ($elem);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4371
    $_DP_elem = $node;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4372
    $parent->appendChild ($node);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4373
    
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4374
    my $n = @attr;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4375
    return unless $n;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4376
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4377
    # Add attributes
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4378
    my $first_default = $expat->specified_attr;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4379
    my $i = 0;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4380
    while ($i < $n)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4381
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4382
	my $specified = $i < $first_default;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4383
	my $name = $attr[$i++];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4384
	undef $_DP_last_text;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4385
	my $attr = $doc->createAttribute ($name, $attr[$i++], $specified);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4386
	$node->setAttributeNode ($attr);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4387
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4388
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4389
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4390
sub End
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4391
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4392
    $_DP_elem = $_DP_elem->[_Parent];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4393
    undef $_DP_last_text;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4394
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4395
    # Check for end of root element
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4396
    $_DP_end_doc = 1 if ($_DP_elem == $_DP_doc);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4397
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4398
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4399
# Called at end of file, i.e. whitespace following last closing tag
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4400
# Also for Entity references
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4401
# May also be called at other times...
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4402
sub Default
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4403
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4404
    my ($expat, $str) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4405
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4406
#    shift; deb ("Default", @_);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4407
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4408
    if ($_DP_in_prolog)	# still processing Document prolog...
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4409
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4410
#?? could try to store this text later
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4411
#?? I've only seen whitespace here so far
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4412
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4413
    elsif (!$_DP_end_doc)	# ignore whitespace at end of Document
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4414
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4415
#	if ($expat->{NoExpand})
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4416
#	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4417
	    $str =~ /^&(.+);$/os;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4418
	    return unless defined ($1);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4419
	    # Got a TextDecl (<?xml ...?>) from an external entity here once
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4420
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4421
	    $_DP_elem->appendChild (
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4422
			$_DP_doc->createEntityReference ($1));
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4423
	    undef $_DP_last_text;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4424
#	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4425
#	else
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4426
#	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4427
#	    $expat->{DOM_Element}->addText ($str);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4428
#	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4429
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4430
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4431
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4432
# XML::Parser 2.19 added support for CdataStart and CdataEnd handlers
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4433
# If they are not defined, the Default handler is called instead
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4434
# with the text "<![CDATA[" and "]]"
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4435
sub CdataStart
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4436
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4437
    $_DP_in_CDATA = 1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4438
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4439
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4440
sub CdataEnd
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4441
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4442
    $_DP_in_CDATA = 0;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4443
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4444
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4445
my $START_MARKER = "__DOM__START__ENTITY__";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4446
my $END_MARKER = "__DOM__END__ENTITY__";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4447
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4448
sub Comment
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4449
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4450
    undef $_DP_last_text;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4451
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4452
    # These comments were inserted by ExternEnt handler
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4453
    if ($_[1] =~ /(?:($START_MARKER)|($END_MARKER))/)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4454
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4455
	if ($1)	 # START
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4456
	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4457
	    $_DP_level++;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4458
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4459
	else
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4460
	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4461
	    $_DP_level--;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4462
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4463
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4464
    else
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4465
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4466
	my $comment = $_DP_doc->createComment ($_[1]);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4467
	$_DP_elem->appendChild ($comment);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4468
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4469
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4470
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4471
sub deb
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4472
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4473
#    return;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4474
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4475
    my $name = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4476
    print "$name (" . join(",", map {defined($_)?$_ : "(undef)"} @_) . ")\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4477
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4478
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4479
sub Doctype
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4480
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4481
    my $expat = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4482
#    deb ("Doctype", @_);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4483
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4484
    $_DP_doctype->setParams (@_);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4485
    $_DP_saw_doctype = 1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4486
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4487
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4488
sub Attlist
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4489
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4490
    my $expat = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4491
#    deb ("Attlist", @_);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4492
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4493
    $_[5] = "Hidden" unless $_DP_expand_pent || $_DP_level == 0;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4494
    $_DP_doctype->addAttDef (@_);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4495
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4496
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4497
sub XMLDecl
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4498
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4499
    my $expat = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4500
#    deb ("XMLDecl", @_);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4501
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4502
    undef $_DP_last_text;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4503
    $_DP_doc->setXMLDecl (new XML::DOM::XMLDecl ($_DP_doc, @_));
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4504
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4505
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4506
sub Entity
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4507
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4508
    my $expat = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4509
#    deb ("Entity", @_);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4510
    
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4511
    # Parameter Entities names are passed starting with '%'
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4512
    my $parameter = 0;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4513
    if ($_[0] =~ /^%(.*)/s)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4514
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4515
	$_[0] = $1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4516
	$parameter = 1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4517
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4518
	if (defined $_[2])	# was sysid specified?
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4519
	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4520
	    # Store the Entity mapping for use in ExternEnt
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4521
	    if (exists $expat->{DOM_Entity}->{$_[2]})
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4522
	    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4523
		# If this ever happens, the name of entity may be the wrong one
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4524
		# when writing out the Document.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4525
		XML::DOM::warning ("Entity $_[2] is known as %$_[0] and %" .
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4526
				   $expat->{DOM_Entity}->{$_[2]});
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4527
	    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4528
	    else
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4529
	    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4530
		$expat->{DOM_Entity}->{$_[2]} = $_[0];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4531
	    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4532
	    #?? remove this block when XML::Parser has better support
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4533
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4534
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4535
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4536
    undef $_DP_last_text;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4537
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4538
    $_[5] = "Hidden" unless $_DP_expand_pent || $_DP_level == 0;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4539
    $_DP_doctype->addEntity ($parameter, @_);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4540
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4541
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4542
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4543
# Unparsed is called when it encounters e.g:
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4544
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4545
#   <!ENTITY logo SYSTEM "http://server/logo.gif" NDATA gif>
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4546
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4547
sub Unparsed
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4548
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4549
    Entity (@_);	# same as regular ENTITY, as far as DOM is concerned
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4550
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4551
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4552
sub Element
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4553
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4554
    shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4555
#    deb ("Element", @_);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4556
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4557
    undef $_DP_last_text;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4558
    push @_, "Hidden" unless $_DP_expand_pent || $_DP_level == 0;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4559
    $_DP_doctype->addElementDecl (@_);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4560
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4561
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4562
sub Notation
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4563
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4564
    shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4565
#    deb ("Notation", @_);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4566
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4567
    undef $_DP_last_text;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4568
    $_[4] = "Hidden" unless $_DP_expand_pent || $_DP_level == 0;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4569
    $_DP_doctype->addNotation (@_);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4570
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4571
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4572
sub Proc
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4573
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4574
    shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4575
#    deb ("Proc", @_);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4576
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4577
    undef $_DP_last_text;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4578
    push @_, "Hidden" unless $_DP_expand_pent || $_DP_level == 0;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4579
    $_DP_elem->appendChild ($_DP_doc->createProcessingInstruction (@_));
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4580
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4581
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4582
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4583
# ExternEnt is called when an external entity, such as:
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4584
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4585
#	<!ENTITY externalEntity PUBLIC "-//Enno//TEXT Enno's description//EN" 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4586
#	                        "http://server/descr.txt">
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4587
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4588
# is referenced in the document, e.g. with: &externalEntity;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4589
# If ExternEnt is not specified, the entity reference is passed to the Default
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4590
# handler as e.g. "&externalEntity;", where an EntityReference object is added.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4591
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4592
# Also for %externalEntity; references in the DTD itself.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4593
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4594
# It can also be called when XML::Parser parses the DOCTYPE header
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4595
# (just before calling the DocType handler), when it contains a
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4596
# reference like "docbook.dtd" below:
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4597
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4598
#    <!DOCTYPE book PUBLIC "-//Norman Walsh//DTD DocBk XML V3.1.3//EN" 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4599
#	"docbook.dtd" [
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4600
#     ... rest of DTD ...
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4601
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4602
sub ExternEnt
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4603
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4604
    my ($expat, $base, $sysid, $pubid) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4605
#    deb ("ExternEnt", @_);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4606
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4607
    # Invoke XML::Parser's default ExternEnt handler
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4608
    my $content;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4609
    if ($XML::Parser::have_LWP)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4610
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4611
	$content = XML::Parser::lwp_ext_ent_handler (@_);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4612
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4613
    else
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4614
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4615
	$content = XML::Parser::file_ext_ent_handler (@_);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4616
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4617
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4618
    if ($_DP_expand_pent)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4619
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4620
	return $content;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4621
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4622
    else
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4623
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4624
	my $entname = $expat->{DOM_Entity}->{$sysid};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4625
	if (defined $entname)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4626
	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4627
	    $_DP_doctype->appendChild ($_DP_doc->createEntityReference ($entname, 1));
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4628
            # Wrap the contents in special comments, so we know when we reach the
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4629
	    # end of parsing the entity. This way we can omit the contents from
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4630
	    # the DTD, when ExpandParamEnt is set to 0.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4631
     
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4632
	    return "<!-- $START_MARKER sysid=[$sysid] -->" .
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4633
		$content . "<!-- $END_MARKER sysid=[$sysid] -->";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4634
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4635
	else
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4636
	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4637
	    # We either read the entity ref'd by the system id in the 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4638
	    # <!DOCTYPE> header, or the entity was undefined.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4639
	    # In either case, don't bother with maintaining the entity
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4640
	    # reference, just expand the contents.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4641
	    return "<!-- $START_MARKER sysid=[DTD] -->" .
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4642
		$content . "<!-- $END_MARKER sysid=[DTD] -->";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4643
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4644
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4645
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4646
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4647
1; # module return code
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4648
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4649
__END__
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4650
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4651
=head1 NAME
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4652
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4653
XML::DOM - A perl module for building DOM Level 1 compliant document structures
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4654
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4655
=head1 SYNOPSIS
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4656
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4657
 use XML::DOM;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4658
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4659
 my $parser = new XML::DOM::Parser;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4660
 my $doc = $parser->parsefile ("file.xml");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4661
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4662
 # print all HREF attributes of all CODEBASE elements
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4663
 my $nodes = $doc->getElementsByTagName ("CODEBASE");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4664
 my $n = $nodes->getLength;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4665
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4666
 for (my $i = 0; $i < $n; $i++)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4667
 {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4668
     my $node = $nodes->item ($i);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4669
     my $href = $node->getAttributeNode ("HREF");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4670
     print $href->getValue . "\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4671
 }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4672
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4673
 # Print doc file
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4674
 $doc->printToFile ("out.xml");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4675
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4676
 # Print to string
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4677
 print $doc->toString;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4678
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4679
 # Avoid memory leaks - cleanup circular references for garbage collection
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4680
 $doc->dispose;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4681
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4682
=head1 DESCRIPTION
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4683
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4684
This module extends the XML::Parser module by Clark Cooper. 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4685
The XML::Parser module is built on top of XML::Parser::Expat, 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4686
which is a lower level interface to James Clark's expat library.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4687
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4688
XML::DOM::Parser is derived from XML::Parser. It parses XML strings or files
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4689
and builds a data structure that conforms to the API of the Document Object 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4690
Model as described at http://www.w3.org/TR/REC-DOM-Level-1.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4691
See the XML::Parser manpage for other available features of the 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4692
XML::DOM::Parser class. 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4693
Note that the 'Style' property should not be used (it is set internally.)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4694
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4695
The XML::Parser I<NoExpand> option is more or less supported, in that it will
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4696
generate EntityReference objects whenever an entity reference is encountered
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4697
in character data. I'm not sure how useful this is. Any comments are welcome.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4698
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4699
As described in the synopsis, when you create an XML::DOM::Parser object, 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4700
the parse and parsefile methods create an I<XML::DOM::Document> object
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4701
from the specified input. This Document object can then be examined, modified and
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4702
written back out to a file or converted to a string.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4703
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4704
When using XML::DOM with XML::Parser version 2.19 and up, setting the 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4705
XML::DOM::Parser option I<KeepCDATA> to 1 will store CDATASections in
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4706
CDATASection nodes, instead of converting them to Text nodes.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4707
Subsequent CDATASection nodes will be merged into one. Let me know if this
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4708
is a problem.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4709
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4710
When using XML::Parser 2.27 and above, you can suppress expansion of
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4711
parameter entity references (e.g. %pent;) in the DTD, by setting I<ParseParamEnt>
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4712
to 1 and I<ExpandParamEnt> to 0. See L<Hidden Nodes|/_Hidden_Nodes_> for details.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4713
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4714
A Document has a tree structure consisting of I<Node> objects. A Node may contain
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4715
other nodes, depending on its type.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4716
A Document may have Element, Text, Comment, and CDATASection nodes. 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4717
Element nodes may have Attr, Element, Text, Comment, and CDATASection nodes. 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4718
The other nodes may not have any child nodes. 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4719
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4720
This module adds several node types that are not part of the DOM spec (yet.)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4721
These are: ElementDecl (for <!ELEMENT ...> declarations), AttlistDecl (for
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4722
<!ATTLIST ...> declarations), XMLDecl (for <?xml ...?> declarations) and AttDef
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4723
(for attribute definitions in an AttlistDecl.)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4724
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4725
=head1 XML::DOM Classes
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4726
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4727
The XML::DOM module stores XML documents in a tree structure with a root node
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4728
of type XML::DOM::Document. Different nodes in tree represent different
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4729
parts of the XML file. The DOM Level 1 Specification defines the following
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4730
node types:
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4731
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4732
=over 4
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4733
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4734
=item * L<XML::DOM::Node> - Super class of all node types
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4735
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4736
=item * L<XML::DOM::Document> - The root of the XML document
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4737
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4738
=item * L<XML::DOM::DocumentType> - Describes the document structure: <!DOCTYPE root [ ... ]>
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4739
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4740
=item * L<XML::DOM::Element> - An XML element: <elem attr="val"> ... </elem>
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4741
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4742
=item * L<XML::DOM::Attr> - An XML element attribute: name="value"
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4743
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4744
=item * L<XML::DOM::CharacterData> - Super class of Text, Comment and CDATASection
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4745
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4746
=item * L<XML::DOM::Text> - Text in an XML element
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4747
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4748
=item * L<XML::DOM::CDATASection> - Escaped block of text: <![CDATA[ text ]]>
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4749
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4750
=item * L<XML::DOM::Comment> - An XML comment: <!-- comment -->
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4751
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4752
=item * L<XML::DOM::EntityReference> - Refers to an ENTITY: &ent; or %ent;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4753
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4754
=item * L<XML::DOM::Entity> - An ENTITY definition: <!ENTITY ...>
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4755
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4756
=item * L<XML::DOM::ProcessingInstruction> - <?PI target>
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4757
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4758
=item * L<XML::DOM::DocumentFragment> - Lightweight node for cut & paste
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4759
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4760
=item * L<XML::DOM::Notation> - An NOTATION definition: <!NOTATION ...>
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4761
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4762
=back
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4763
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4764
In addition, the XML::DOM module contains the following nodes that are not part 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4765
of the DOM Level 1 Specification:
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4766
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4767
=over 4
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4768
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4769
=item * L<XML::DOM::ElementDecl> - Defines an element: <!ELEMENT ...>
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4770
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4771
=item * L<XML::DOM::AttlistDecl> - Defines one or more attributes in an <!ATTLIST ...>
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4772
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4773
=item * L<XML::DOM::AttDef> - Defines one attribute in an <!ATTLIST ...>
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4774
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4775
=item * L<XML::DOM::XMLDecl> - An XML declaration: <?xml version="1.0" ...>
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4776
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4777
=back
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4778
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4779
Other classes that are part of the DOM Level 1 Spec:
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4780
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4781
=over 4
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4782
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4783
=item * L<XML::DOM::Implementation> - Provides information about this implementation. Currently it doesn't do much.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4784
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4785
=item * L<XML::DOM::NodeList> - Used internally to store a node's child nodes. Also returned by getElementsByTagName.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4786
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4787
=item * L<XML::DOM::NamedNodeMap> - Used internally to store an element's attributes.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4788
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4789
=back
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4790
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4791
Other classes that are not part of the DOM Level 1 Spec:
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4792
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4793
=over 4
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4794
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4795
=item * L<XML::DOM::Parser> - An non-validating XML parser that creates XML::DOM::Documents
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4796
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4797
=item * L<XML::DOM::ValParser> - A validating XML parser that creates XML::DOM::Documents. It uses L<XML::Checker> to check against the DocumentType (DTD)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4798
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4799
=item * L<XML::Handler::BuildDOM> - A PerlSAX handler that creates XML::DOM::Documents.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4800
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4801
=back
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4802
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4803
=head1 XML::DOM package
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4804
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4805
=over 4
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4806
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4807
=item Constant definitions
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4808
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4809
The following predefined constants indicate which type of node it is.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4810
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4811
=back
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4812
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4813
 UNKNOWN_NODE (0)                The node type is unknown (not part of DOM)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4814
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4815
 ELEMENT_NODE (1)                The node is an Element.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4816
 ATTRIBUTE_NODE (2)              The node is an Attr.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4817
 TEXT_NODE (3)                   The node is a Text node.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4818
 CDATA_SECTION_NODE (4)          The node is a CDATASection.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4819
 ENTITY_REFERENCE_NODE (5)       The node is an EntityReference.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4820
 ENTITY_NODE (6)                 The node is an Entity.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4821
 PROCESSING_INSTRUCTION_NODE (7) The node is a ProcessingInstruction.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4822
 COMMENT_NODE (8)                The node is a Comment.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4823
 DOCUMENT_NODE (9)               The node is a Document.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4824
 DOCUMENT_TYPE_NODE (10)         The node is a DocumentType.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4825
 DOCUMENT_FRAGMENT_NODE (11)     The node is a DocumentFragment.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4826
 NOTATION_NODE (12)              The node is a Notation.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4827
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4828
 ELEMENT_DECL_NODE (13)		 The node is an ElementDecl (not part of DOM)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4829
 ATT_DEF_NODE (14)		 The node is an AttDef (not part of DOM)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4830
 XML_DECL_NODE (15)		 The node is an XMLDecl (not part of DOM)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4831
 ATTLIST_DECL_NODE (16)		 The node is an AttlistDecl (not part of DOM)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4832
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4833
 Usage:
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4834
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4835
   if ($node->getNodeType == ELEMENT_NODE)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4836
   {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4837
       print "It's an Element";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4838
   }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4839
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4840
B<Not In DOM Spec>: The DOM Spec does not mention UNKNOWN_NODE and, 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4841
quite frankly, you should never encounter it. The last 4 node types were added
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4842
to support the 4 added node classes.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4843
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4844
=head2 Global Variables
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4845
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4846
=over 4
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4847
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4848
=item $VERSION
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4849
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4850
The variable $XML::DOM::VERSION contains the version number of this 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4851
implementation, e.g. "1.07".
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4852
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4853
=back
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4854
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4855
=head2 METHODS
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4856
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4857
These methods are not part of the DOM Level 1 Specification.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4858
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4859
=over 4
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4860
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4861
=item getIgnoreReadOnly and ignoreReadOnly (readOnly)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4862
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4863
The DOM Level 1 Spec does not allow you to edit certain sections of the document,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4864
e.g. the DocumentType, so by default this implementation throws DOMExceptions
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4865
(i.e. NO_MODIFICATION_ALLOWED_ERR) when you try to edit a readonly node. 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4866
These readonly checks can be disabled by (temporarily) setting the global 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4867
IgnoreReadOnly flag.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4868
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4869
The ignoreReadOnly method sets the global IgnoreReadOnly flag and returns its
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4870
previous value. The getIgnoreReadOnly method simply returns its current value.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4871
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4872
 my $oldIgnore = XML::DOM::ignoreReadOnly (1);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4873
 eval {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4874
 ... do whatever you want, catching any other exceptions ...
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4875
 };
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4876
 XML::DOM::ignoreReadOnly ($oldIgnore);     # restore previous value
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4877
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4878
Another way to do it, using a local variable:
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4879
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4880
 { # start new scope
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4881
    local $XML::DOM::IgnoreReadOnly = 1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4882
    ... do whatever you want, don't worry about exceptions ...
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4883
 } # end of scope ($IgnoreReadOnly is set back to its previous value)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4884
    
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4885
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4886
=item isValidName (name)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4887
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4888
Whether the specified name is a valid "Name" as specified in the XML spec.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4889
Characters with Unicode values > 127 are now also supported.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4890
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4891
=item getAllowReservedNames and allowReservedNames (boolean)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4892
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4893
The first method returns whether reserved names are allowed. 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4894
The second takes a boolean argument and sets whether reserved names are allowed.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4895
The initial value is 1 (i.e. allow reserved names.)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4896
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4897
The XML spec states that "Names" starting with (X|x)(M|m)(L|l)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4898
are reserved for future use. (Amusingly enough, the XML version of the XML spec
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4899
(REC-xml-19980210.xml) breaks that very rule by defining an ENTITY with the name 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4900
'xmlpio'.)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4901
A "Name" in this context means the Name token as found in the BNF rules in the
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4902
XML spec.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4903
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4904
XML::DOM only checks for errors when you modify the DOM tree, not when the
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4905
DOM tree is built by the XML::DOM::Parser.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4906
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4907
=item setTagCompression (funcref)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4908
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4909
There are 3 possible styles for printing empty Element tags:
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4910
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4911
=over 4
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4912
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4913
=item Style 0
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4914
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4915
 <empty/> or <empty attr="val"/>
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4916
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4917
XML::DOM uses this style by default for all Elements.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4918
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4919
=item Style 1
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4920
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4921
  <empty></empty> or <empty attr="val"></empty>
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4922
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4923
=item Style 2
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4924
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4925
  <empty /> or <empty attr="val" />
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4926
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4927
This style is sometimes desired when using XHTML. 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4928
(Note the extra space before the slash "/")
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4929
See L<http://www.w3.org/TR/xhtml1> Appendix C for more details.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4930
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4931
=back
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4932
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4933
By default XML::DOM compresses all empty Element tags (style 0.)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4934
You can control which style is used for a particular Element by calling
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4935
XML::DOM::setTagCompression with a reference to a function that takes
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4936
2 arguments. The first is the tag name of the Element, the second is the
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4937
XML::DOM::Element that is being printed. 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4938
The function should return 0, 1 or 2 to indicate which style should be used to
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4939
print the empty tag. E.g.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4940
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4941
 XML::DOM::setTagCompression (\&my_tag_compression);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4942
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4943
 sub my_tag_compression
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4944
 {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4945
    my ($tag, $elem) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4946
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4947
    # Print empty br, hr and img tags like this: <br />
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4948
    return 2 if $tag =~ /^(br|hr|img)$/;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4949
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4950
    # Print other empty tags like this: <empty></empty>
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4951
    return 1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4952
 }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4953
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4954
=back
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4955
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4956
=head1 IMPLEMENTATION DETAILS
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4957
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4958
=over 4
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4959
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4960
=item * Perl Mappings
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4961
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4962
The value undef was used when the DOM Spec said null.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4963
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4964
The DOM Spec says: Applications must encode DOMString using UTF-16 (defined in 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4965
Appendix C.3 of [UNICODE] and Amendment 1 of [ISO-10646]).
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4966
In this implementation we use plain old Perl strings encoded in UTF-8 instead of
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4967
UTF-16.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4968
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4969
=item * Text and CDATASection nodes
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4970
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4971
The Expat parser expands EntityReferences and CDataSection sections to 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4972
raw strings and does not indicate where it was found. 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4973
This implementation does therefore convert both to Text nodes at parse time.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4974
CDATASection and EntityReference nodes that are added to an existing Document 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4975
(by the user) will be preserved.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4976
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4977
Also, subsequent Text nodes are always merged at parse time. Text nodes that are 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4978
added later can be merged with the normalize method. Consider using the addText
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4979
method when adding Text nodes.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4980
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4981
=item * Printing and toString
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4982
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4983
When printing (and converting an XML Document to a string) the strings have to 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4984
encoded differently depending on where they occur. E.g. in a CDATASection all 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4985
substrings are allowed except for "]]>". In regular text, certain characters are
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4986
not allowed, e.g. ">" has to be converted to "&gt;". 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4987
These routines should be verified by someone who knows the details.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4988
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4989
=item * Quotes
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4990
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4991
Certain sections in XML are quoted, like attribute values in an Element.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4992
XML::Parser strips these quotes and the print methods in this implementation 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4993
always uses double quotes, so when parsing and printing a document, single quotes
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4994
may be converted to double quotes. The default value of an attribute definition
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4995
(AttDef) in an AttlistDecl, however, will maintain its quotes.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4996
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4997
=item * AttlistDecl
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4998
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  4999
Attribute declarations for a certain Element are always merged into a single
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  5000
AttlistDecl object.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  5001
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  5002
=item * Comments
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  5003
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  5004
Comments in the DOCTYPE section are not kept in the right place. They will become
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  5005
child nodes of the Document.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  5006
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  5007
=item * Hidden Nodes
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  5008
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  5009
Previous versions of XML::DOM would expand parameter entity references
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  5010
(like B<%pent;>), so when printing the DTD, it would print the contents
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  5011
of the external entity, instead of the parameter entity reference.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  5012
With this release (1.27), you can prevent this by setting the XML::DOM::Parser
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  5013
options ParseParamEnt => 1 and ExpandParamEnt => 0.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  5014
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  5015
When it is parsing the contents of the external entities, it *DOES* still add
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  5016
the nodes to the DocumentType, but it marks these nodes by setting
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  5017
the 'Hidden' property. In addition, it adds an EntityReference node to the
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  5018
DocumentType node.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  5019
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  5020
When printing the DocumentType node (or when using to_expat() or to_sax()), 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  5021
the 'Hidden' nodes are suppressed, so you will see the parameter entity
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  5022
reference instead of the contents of the external entities. See test case
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  5023
t/dom_extent.t for an example.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  5024
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  5025
The reason for adding the 'Hidden' nodes to the DocumentType node, is that
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  5026
the nodes may contain <!ENTITY> definitions that are referenced further
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  5027
in the document. (Simply not adding the nodes to the DocumentType could
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  5028
cause such entity references to be expanded incorrectly.)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  5029
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  5030
Note that you need XML::Parser 2.27 or higher for this to work correctly.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  5031
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  5032
=back
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  5033
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  5034
=head1 SEE ALSO
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  5035
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  5036
The Japanese version of this document by Takanori Kawai (Hippo2000)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  5037
at L<http://member.nifty.ne.jp/hippo2000/perltips/xml/dom.htm>
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  5038
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  5039
The DOM Level 1 specification at L<http://www.w3.org/TR/REC-DOM-Level-1>
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  5040
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  5041
The XML spec (Extensible Markup Language 1.0) at L<http://www.w3.org/TR/REC-xml>
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  5042
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  5043
The L<XML::Parser> and L<XML::Parser::Expat> manual pages.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  5044
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  5045
=head1 CAVEATS
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  5046
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  5047
The method getElementsByTagName() does not return a "live" NodeList.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  5048
Whether this is an actual caveat is debatable, but a few people on the 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  5049
www-dom mailing list seemed to think so. I haven't decided yet. It's a pain
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  5050
to implement, it slows things down and the benefits seem marginal.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  5051
Let me know what you think. 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  5052
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  5053
(To subscribe to the www-dom mailing list send an email with the subject 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  5054
"subscribe" to www-dom-request@w3.org. I only look here occasionally, so don't
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  5055
send bug reports or suggestions about XML::DOM to this list, send them
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  5056
to enno@att.com instead.)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  5057
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  5058
=head1 AUTHOR
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  5059
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  5060
Send bug reports, hints, tips, suggestions to Enno Derksen at
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  5061
<F<enno@att.com>>. 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  5062
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  5063
Thanks to Clark Cooper for his help with the initial version.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  5064
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
  5065
=cut