You can subscribe to this list here.
2002 |
Jan
(8) |
Feb
(22) |
Mar
(3) |
Apr
(13) |
May
(1) |
Jun
(4) |
Jul
|
Aug
(5) |
Sep
(9) |
Oct
(36) |
Nov
(7) |
Dec
(15) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2003 |
Jan
(4) |
Feb
(1) |
Mar
(55) |
Apr
(25) |
May
(25) |
Jun
(4) |
Jul
(2) |
Aug
|
Sep
(12) |
Oct
(6) |
Nov
(14) |
Dec
(1) |
2004 |
Jan
(1) |
Feb
(8) |
Mar
(6) |
Apr
(5) |
May
|
Jun
|
Jul
|
Aug
(1) |
Sep
(1) |
Oct
(3) |
Nov
(11) |
Dec
|
2005 |
Jan
(14) |
Feb
(3) |
Mar
(4) |
Apr
(14) |
May
(1) |
Jun
|
Jul
(1) |
Aug
|
Sep
(1) |
Oct
(2) |
Nov
(2) |
Dec
(1) |
2006 |
Jan
|
Feb
|
Mar
|
Apr
(3) |
May
|
Jun
|
Jul
|
Aug
(1) |
Sep
(8) |
Oct
(19) |
Nov
(5) |
Dec
|
2007 |
Jan
(5) |
Feb
(1) |
Mar
|
Apr
(4) |
May
|
Jun
|
Jul
|
Aug
(8) |
Sep
|
Oct
|
Nov
|
Dec
|
2008 |
Jan
|
Feb
|
Mar
(2) |
Apr
|
May
|
Jun
|
Jul
(1) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Grant M. <gr...@us...> - 2002-10-13 01:13:23
|
Update of /cvsroot/perl-xml/xml-simple In directory usw-pr-cvs1:/tmp/cvs-serv1344 Modified Files: Simple.pm Log Message: - removed 5005threads locking code for ithreads compatibility Index: Simple.pm =================================================================== RCS file: /cvsroot/perl-xml/xml-simple/Simple.pm,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- Simple.pm 13 Oct 2002 01:11:04 -0000 1.5 +++ Simple.pm 13 Oct 2002 01:13:19 -0000 1.6 @@ -55,7 +55,6 @@ memcopy => [ \&MemCopySave, \&MemCopyRestore ] ); -my $DefaultValues = 1; # Used for locking only my @KnownOptIn = qw(keyattr keeproot forcecontent contentkey noattr searchpath forcearray cache suppressempty parseropts nsexpand datahandler DataHandler); @@ -72,7 +71,7 @@ ############################################################################## -# Globals for use by caching routines (access protected by locks) +# Globals for use by caching routines # my %MemShareCache = (); @@ -80,17 +79,6 @@ ############################################################################## -# Dummy 'lock' routine for non-threaded versions of Perl -# - -BEGIN { - if($] < 5.005) { - eval "sub lock {}"; - } -} - - -############################################################################## # Constructor for optional object interface. # @@ -170,7 +158,6 @@ $filename = $self->find_xml_file($string, @{$self->{opt}->{searchpath}}); if($self->{opt}->{cache}) { - lock(%CacheScheme); foreach $scheme (@{$self->{opt}->{cache}}) { croak "Unsupported caching scheme: $scheme" unless($CacheScheme{$scheme}); @@ -374,7 +361,6 @@ sub MemShareSave { my($data, $filename) = @_; - lock(%MemShareCache); $MemShareCache{$filename} = [time(), $data]; } @@ -388,7 +374,6 @@ sub MemShareRestore { my($filename) = @_; - lock(%MemShareCache); return unless($MemShareCache{$filename}); return unless($MemShareCache{$filename}->[0] > (stat($filename))[9]); @@ -407,7 +392,6 @@ sub MemCopySave { my($data, $filename) = @_; - lock(%MemCopyCache); unless($INC{'Storable.pm'}) { require Storable; # We didn't need it until now } @@ -426,7 +410,6 @@ sub MemCopyRestore { my($filename) = @_; - lock(%MemCopyCache); return unless($MemCopyCache{$filename}); return unless($MemCopyCache{$filename}->[0] > (stat($filename))[9]); @@ -558,8 +541,6 @@ my $self = shift; my $dirn = shift; - - lock($DefaultValues); # Determine valid options based on context |
From: Grant M. <gr...@us...> - 2002-10-13 01:11:08
|
Update of /cvsroot/perl-xml/xml-simple In directory usw-pr-cvs1:/tmp/cvs-serv894 Modified Files: Simple.pm Log Message: - POD update: alphabetised options Index: Simple.pm =================================================================== RCS file: /cvsroot/perl-xml/xml-simple/Simple.pm,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- Simple.pm 14 Feb 2002 21:32:44 -0000 1.4 +++ Simple.pm 13 Oct 2002 01:11:04 -0000 1.5 @@ -4,7 +4,7 @@ =head1 NAME -XML::Simple - Easy API to read/write XML (esp config files) +XML::Simple - Easy API to maintain XML (esp config files) =head1 SYNOPSIS @@ -964,7 +964,7 @@ # Arguments expected are: # - the data structure to be encoded (usually a reference) # - the XML tag name to use for this item -# - a hashref of references already encoded (to detect recursive structures) +# - a hashref of references already encoded (to detect circular structures) # - a string of spaces for use as the current indent level # @@ -984,7 +984,7 @@ # Convert to XML if(ref($ref)) { - croak "recursive data structures not supported" if($encoded->{$ref}); + croak "circular data structures not supported" if($encoded->{$ref}); $encoded->{$ref} = $ref; } else { @@ -1510,7 +1510,7 @@ approach). Note also that although you can nest hashes and arrays to arbitrary levels, -recursive data structures are not supported and will cause C<XMLout()> to die. +circular data structures are not supported and will cause C<XMLout()> to die. Refer to L<"WHERE TO FROM HERE?"> if C<XMLout()> is too simple for your needs. @@ -1534,8 +1534,9 @@ =item * -make sure you know what the 'keyattr' option does and what its default value -is because it may surprise you otherwise +make sure you know what the 'keyattr' option does and what its default value is +because it may surprise you otherwise (note in particular that 'keyattr' +affects both C<XMLin> and C<XMLout>) =back @@ -1544,134 +1545,100 @@ listed below are marked with 'B<in>' if they are recognised by C<XMLin()> and 'B<out>' if they are recognised by C<XMLout()>. -=over 4 +Each option is also flagged to indicate whether it is: -=item keyattr => [ list ] (B<in+out>) + 'important' - don't use the module until you understand this + 'handy' - you can skip this on the first time through + 'advanced' - you can skip this on the second time through + 'SAX only' - don't worry about this unless you're using SAX + 'seldom used' - you'll probably never use this unless you were the + person that requested the feature -This option controls the 'array folding' feature which translates nested -elements from an array to a hash. For example, this XML: +The options are listed alphabetically: - <opt> - <user login="grep" fullname="Gary R Epstein" /> - <user login="stty" fullname="Simon T Tyson" /> - </opt> +=over 4 -would, by default, parse to this: +=item cache => [ cache scheme(s) ] (B<in>) (B<advanced>) - { - 'user' => [ - { - 'login' => 'grep', - 'fullname' => 'Gary R Epstein' - }, - { - 'login' => 'stty', - 'fullname' => 'Simon T Tyson' - } - ] - } +Because loading the B<XML::Parser> module and parsing an XML file can consume a +significant number of CPU cycles, it is often desirable to cache the output of +C<XMLin()> for later reuse. -If the option 'keyattr => "login"' were used to specify that the 'login' -attribute is a key, the same XML would parse to: +When parsing from a named file, B<XML::Simple> supports a number of caching +schemes. The 'cache' option may be used to specify one or more schemes (using +an anonymous array). Each scheme will be tried in turn in the hope of finding +a cached pre-parsed representation of the XML file. If no cached copy is +found, the file will be parsed and the first cache scheme in the list will be +used to save a copy of the results. The following cache schemes have been +implemented: - { - 'user' => { - 'stty' => { - 'fullname' => 'Simon T Tyson' - }, - 'grep' => { - 'fullname' => 'Gary R Epstein' - } - } - } +=over 4 -The key attribute names should be supplied in an arrayref if there is more -than one. C<XMLin()> will attempt to match attribute names in the order -supplied. C<XMLout()> will use the first attribute name supplied when -'unfolding' a hash into an array. +=item storable -Note: the keyattr option controls the folding of arrays. By default a single -nested element will be rolled up into a scalar rather than an array and -therefore will not be folded. Use the 'forcearray' option (below) to force -nested elements to be parsed into arrays and therefore candidates for folding -into hashes. +Utilises B<Storable.pm> to read/write a cache file with the same name as the +XML file but with the extension .stor -The default value for 'keyattr' is ['name', 'key', 'id']. Setting this option -to an empty list will disable the array folding feature. +=item memshare -=item keyattr => { list } (B<in+out>) +When a file is first parsed, a copy of the resulting data structure is retained +in memory in the B<XML::Simple> module's namespace. Subsequent calls to parse +the same file will return a reference to this structure. This cached version +will persist only for the life of the Perl interpreter (which in the case of +mod_perl for example, may be some significant time). -This alternative method of specifiying the key attributes allows more fine -grained control over which elements are folded and on which attributes. For -example the option 'keyattr => { package => 'id' } will cause any package -elements to be folded on the 'id' attribute. No other elements which have an -'id' attribute will be folded at all. +Because each caller receives a reference to the same data structure, a change +made by one caller will be visible to all. For this reason, the reference +returned should be treated as read-only. -Note: C<XMLin()> will generate a warning if this syntax is used and an element -which does not have the specified key attribute is encountered (eg: a 'package' -element without an 'id' attribute, to use the example above). Warnings will -only be generated if B<-w> is in force. +=item memcopy -Two further variations are made possible by prefixing a '+' or a '-' character -to the attribute name: +This scheme works identically to 'memshare' (above) except that each caller +receives a reference to a new data structure which is a copy of the cached +version. Copying the data structure will add a little processing overhead, +therefore this scheme should only be used where the caller intends to modify +the data structure (or wishes to protect itself from others who might). This +scheme uses B<Storable.pm> to perform the copy. -The option 'keyattr => { user => "+login" }' will cause this XML: +=back - <opt> - <user login="grep" fullname="Gary R Epstein" /> - <user login="stty" fullname="Simon T Tyson" /> - </opt> +Warning! The memory-based caching schemes compare the timestamp on the file to +the time when it was last parsed. If the file is stored on an NFS filesystem +(or other network share) and the clock on the file server is not exactly +synchronised with the clock where your script is run, updates to the source XML +file may appear to be ignored. -to parse to this data structure: +=item contentkey => 'keyname' (B<in+out>) (B<seldom used>) - { - 'user' => { - 'stty' => { - 'fullname' => 'Simon T Tyson', - 'login' => 'stty' - }, - 'grep' => { - 'fullname' => 'Gary R Epstein', - 'login' => 'grep' - } - } - } +When text content is parsed to a hash value, this option let's you specify a +name for the hash key to override the default 'content'. So for example: -The '+' indicates that the value of the key attribute should be copied rather than -moved to the folded hash key. + XMLin('<opt one="1">Text</opt>', contentkey => 'text') -A '-' prefix would produce this result: +will parse to: - { - 'user' => { - 'stty' => { - 'fullname' => 'Simon T Tyson', - '-login' => 'stty' - }, - 'grep' => { - 'fullname' => 'Gary R Epstein', - '-login' => 'grep' - } - } - } + { 'one' => 1, 'text' => 'Text' } -As described earlier, C<XMLout> will ignore hash keys starting with a '-'. +instead of: -=item searchpath => [ list ] (B<in>) + { 'one' => 1, 'content' => 'Text' } -If you pass C<XMLin()> a filename, but the filename include no directory -component, you can use this option to specify which directories should be -searched to locate the file. You might use this option to search first in the -user's home directory, then in a global directory such as /etc. +C<XMLout()> will also honour the value of this option when converting a hashref +to XML. -If a filename is provided to C<XMLin()> but searchpath is not defined, the -file is assumed to be in the current directory. +=item datahandler => code_ref (B<in>) (B<SAX only>) -If the first parameter to C<XMLin()> is undefined, the default searchpath -will contain only the directory in which the script itself is located. -Otherwise the default searchpath will be empty. +When you use an B<XML::Simple> object as a SAX handler, it will return a +'simple tree' data structure in the same format as C<XMLin()> would return. If +this option is set (to a subroutine reference), then when the tree is built the +subroutine will be called and passed two arguments: a reference to the +B<XML::Simple> object and a reference to the data tree. The return value from +the subroutine will be returned to the SAX driver. (See L<"SAX SUPPORT"> for +more details). -=item forcearray => 1 (B<in>) +You can specify 'DataHandler' as a synonym for 'datahandler'. + +=item forcearray => 1 (B<in>) (B<IMPORTANT!>) This option should be set to '1' to force nested elements to be represented as arrays even when there is only one. Eg, with forcearray enabled, this @@ -1705,74 +1672,51 @@ the default value of 'keyattr' enables array folding, the default value of this option should probably also have been enabled too - sorry). -=item forcearray => [ name(s) ] (B<in>) - -This alternative form of the 'forcearray' option allows you to specify a list -of element names which should always be forced into an array representation, -rather than the 'all or nothing' approach above. - -=item noattr => 1 (B<in+out>) - -When used with C<XMLout()>, the generated XML will contain no attributes. -All hash key/values will be represented as nested elements instead. - -When used with C<XMLin()>, any attributes in the XML will be ignored. - -=item suppressempty => 1 | '' | undef (B<in>) - -This option controls what C<XMLin()> should do with empty elements (no -attributes and no content). The default behaviour is to represent them as -empty hashes. Setting this option to a true value (eg: 1) will cause empty -elements to be skipped altogether. Setting the option to 'undef' or the empty -string will cause empty elements to be represented as the undefined value or -the empty string respectively. The latter two alternatives are a little -easier to test for in your code than a hash with no keys. - -=item cache => [ cache scheme(s) ] (B<in>) +=item forcearray => [ name(s) ] (B<in>) (B<IMPORTANT!>) -Because loading the B<XML::Parser> module and parsing an XML file can consume a -significant number of CPU cycles, it is often desirable to cache the output of -C<XMLin()> for later reuse. +This alternative (and preferred) form of the 'forcearray' option allows you to +specify a list of element names which should always be forced into an array +representation, rather than the 'all or nothing' approach above. -When parsing from a named file, B<XML::Simple> supports a number of caching -schemes. The 'cache' option may be used to specify one or more schemes (using -an anonymous array). Each scheme will be tried in turn in the hope of finding -a cached pre-parsed representation of the XML file. If no cached copy is -found, the file will be parsed and the first cache scheme in the list will be -used to save a copy of the results. The following cache schemes have been -implemented: +=item forcecontent (B<in>) (B<seldom used>) -=over 4 +When C<XMLin()> parses elements which have text content as well as attributes, +the text content must be represented as a hash value rather than a simple +scalar. This option allows you to force text content to always parse to +a hash value even when there are no attributes. So for example: -=item storable + XMLin('<opt><x>text1</x><y a="2">text2</y></opt>', forcecontent => 1) -Utilises B<Storable.pm> to read/write a cache file with the same name as the -XML file but with the extension .stor +will parse to: -=item memshare + { + 'x' => { 'content' => 'text1' }, + 'y' => { 'a' => 2, 'content' => 'text2' } + } -When a file is first parsed, a copy of the resulting data structure is retained -in memory in the B<XML::Simple> module's namespace. Subsequent calls to parse -the same file will return a reference to this structure. This cached version -will persist only for the life of the Perl interpreter (which in the case of -mod_perl for example, may be some significant time). +instead of: -Because each caller receives a reference to the same data structure, a change -made by one caller will be visible to all. For this reason, the reference -returned should be treated as read-only. + { + 'x' => 'text1', + 'y' => { 'a' => 2, 'content' => 'text2' } + } -=item memcopy +=item handler => object_ref (B<out>) (B<SAX only>) -This scheme works identically to 'memshare' (above) except that each caller -receives a reference to a new data structure which is a copy of the cached -version. Copying the data structure will add a little processing overhead, -therefore this scheme should only be used where the caller intends to modify -the data structure (or wishes to protect itself from others who might). This -scheme uses B<Storable.pm> to perform the copy. +Use the 'handler' option to have C<XMLout()> generate SAX events rather than +returning a string of XML. For more details see L<"SAX SUPPORT"> below. +You can specify 'Handler' as a synonym for 'handler' for compatability with +the SAX specification. -=back +Note: the current implementation of this option generates a string of XML +and uses a SAX parser to translate it into SAX events. The normal encoding +rules apply here - your data must be UTF8 encoded unless you specify an +alternative encoding via the 'xmldecl' option; and by the time the data reaches +the handler object, it will be in UTF8 form regardless of the encoding you +supply. A future implementation of this option may generate the events +directly. -=item keeproot => 1 (B<in+out>) +=item keeproot => 1 (B<in+out>) (B<handy>) In its attempt to return a data structure free of superfluous detail and unnecessary levels of indirection, C<XMLin()> normally discards the root @@ -1789,82 +1733,145 @@ data structure already contains a root element name and it is not necessary to add another. -=item rootname => 'string' (B<out>) +=item keyattr => [ list ] (B<in+out>) (B<IMPORTANT!>) -By default, when C<XMLout()> generates XML, the root element will be named -'opt'. This option allows you to specify an alternative name. +This option controls the 'array folding' feature which translates nested +elements from an array to a hash. It also controls the 'unfolding' of hashes +to arrays. -Specifying either undef or the empty string for the rootname option will -produce XML with no root elements. In most cases the resulting XML fragment -will not be 'well formed' and therefore could not be read back in by C<XMLin()>. -Nevertheless, the option has been found to be useful in certain circumstances. +For example, this XML: -=item forcecontent (B<in>) + <opt> + <user login="grep" fullname="Gary R Epstein" /> + <user login="stty" fullname="Simon T Tyson" /> + </opt> -When C<XMLin()> parses elements which have text content as well as attributes, -the text content must be represented as a hash value rather than a simple -scalar. This option allows you to force text content to always parse to -a hash value even when there are no attributes. So for example: +would, by default, parse to this: - XMLin('<opt><x>text1</x><y a="2">text2</y></opt>', forcecontent => 1) + { + 'user' => [ + { + 'login' => 'grep', + 'fullname' => 'Gary R Epstein' + }, + { + 'login' => 'stty', + 'fullname' => 'Simon T Tyson' + } + ] + } -will parse to: +If the option 'keyattr => "login"' were used to specify that the 'login' +attribute is a key, the same XML would parse to: - { - 'x' => { 'content' => 'text1' }, - 'y' => { 'a' => 2, 'content' => 'text2' } - } + { + 'user' => { + 'stty' => { + 'fullname' => 'Simon T Tyson' + }, + 'grep' => { + 'fullname' => 'Gary R Epstein' + } + } + } -instead of: +The key attribute names should be supplied in an arrayref if there is more +than one. C<XMLin()> will attempt to match attribute names in the order +supplied. C<XMLout()> will use the first attribute name supplied when +'unfolding' a hash into an array. - { - 'x' => 'text1', - 'y' => { 'a' => 2, 'content' => 'text2' } - } +Note 1: The default value for 'keyattr' is ['name', 'key', 'id']. If you do +not want folding on input or unfolding on output you must setting this option +to an empty list to disable the feature. -=item contentkey => 'keyname' (B<in+out>) +Note 2: If you wish to use this option, you should also enable the 'forcearray' +option. Without 'forcearray', a single nested element will be rolled up into a +scalar rather than an array and therefore will not be folded (since only arrays +get folded). -When text content is parsed to a hash value, this option let's you specify a -name for the hash key to override the default 'content'. So for example: +=item keyattr => { list } (B<in+out>) (B<IMPORTANT!>) - XMLin('<opt one="1">Text</opt>', contentkey => 'text') +This alternative (and preferred) method of specifiying the key attributes +allows more fine grained control over which elements are folded and on which +attributes. For example the option 'keyattr => { package => 'id' } will cause +any package elements to be folded on the 'id' attribute. No other elements +which have an 'id' attribute will be folded at all. -will parse to: +Note: C<XMLin()> will generate a warning if this syntax is used and an element +which does not have the specified key attribute is encountered (eg: a 'package' +element without an 'id' attribute, to use the example above). Warnings will +only be generated if B<-w> is in force. - { 'one' => 1, 'text' => 'Text' } +Two further variations are made possible by prefixing a '+' or a '-' character +to the attribute name: -instead of: +The option 'keyattr => { user => "+login" }' will cause this XML: - { 'one' => 1, 'content' => 'Text' } + <opt> + <user login="grep" fullname="Gary R Epstein" /> + <user login="stty" fullname="Simon T Tyson" /> + </opt> -C<XMLout()> will also honour the value of this option when converting a hashref -to XML. +to parse to this data structure: -=item xmldecl => 1 or xmldecl => 'string' (B<out>) + { + 'user' => { + 'stty' => { + 'fullname' => 'Simon T Tyson', + 'login' => 'stty' + }, + 'grep' => { + 'fullname' => 'Gary R Epstein', + 'login' => 'grep' + } + } + } -If you want the output from C<XMLout()> to start with the optional XML -declaration, simply set the option to '1'. The default XML declaration is: +The '+' indicates that the value of the key attribute should be copied rather +than moved to the folded hash key. - <?xml version='1.0' standalone='yes'?> +A '-' prefix would produce this result: -If you want some other string (for example to declare an encoding value), set -the value of this option to the complete string you require. + { + 'user' => { + 'stty' => { + 'fullname' => 'Simon T Tyson', + '-login' => 'stty' + }, + 'grep' => { + 'fullname' => 'Gary R Epstein', + '-login' => 'grep' + } + } + } -=item outputfile => <file specifier> (B<out>) +As described earlier, C<XMLout> will ignore hash keys starting with a '-'. -The default behaviour of C<XMLout()> is to return the XML as a string. If you -wish to write the XML to a file, simply supply the filename using the -'outputfile' option. Alternatively, you can supply an IO handle object instead -of a filename. +=item noattr => 1 (B<in+out>) (B<handy>) -=item noescape => 1 (B<out>) +When used with C<XMLout()>, the generated XML will contain no attributes. +All hash key/values will be represented as nested elements instead. + +When used with C<XMLin()>, any attributes in the XML will be ignored. + +=item rootname => 'string' (B<out>) (B<handy>) + +By default, when C<XMLout()> generates XML, the root element will be named +'opt'. This option allows you to specify an alternative name. + +Specifying either undef or the empty string for the rootname option will +produce XML with no root elements. In most cases the resulting XML fragment +will not be 'well formed' and therefore could not be read back in by C<XMLin()>. +Nevertheless, the option has been found to be useful in certain circumstances. + +=item noescape => 1 (B<out>) (B<seldom used>) By default, C<XMLout()> will translate the characters 'E<lt>', 'E<gt>', '&' and '"' to '<', '>', '&' and '"' respectively. Use this option to suppress escaping (presumably because you've already escaped the data in some more sophisticated manner). -=item nsexpand => 1 (B<in+out>) +=item nsexpand => 1 (B<in+out>) (B<handy - SAX only>) This option controls namespace expansion - the translation of element and attribute names of the form 'prefix:name' to '{uri}name'. For example the @@ -1886,40 +1893,55 @@ I<Note: You must have the XML::NamespaceSupport module installed if you want C<XMLout()> to translate URIs back to prefixes>. -=item handler => object_ref (B<out>) +=item outputfile => <file specifier> (B<out>) (B<handy>) -Use the 'handler' option to have C<XMLout()> generate SAX events rather than -returning a string of XML. For more details see L<"SAX SUPPORT"> below. -You can specify 'Handler' as a synonym for 'handler' for compatability with -the SAX specification. +The default behaviour of C<XMLout()> is to return the XML as a string. If you +wish to write the XML to a file, simply supply the filename using the +'outputfile' option. Alternatively, you can supply an IO handle object instead +of a filename. -Note: the current implementation of this option generates a string of XML -and uses a SAX parser to translate it into SAX events. The normal encoding -rules apply here - your data must be UTF8 encoded unless you specify an -alternative encoding via the 'xmldecl' option; and by the time the data reaches -the handler object, it will be in UTF8 form regardless of the encoding you -supply. A future implementation of this option may generate the events -directly. +=item parseropts => [ XML::Parser Options ] (B<in>) (B<don't use this>) -=item datahandler => code_ref (B<in>) +I<Note: This option is now officially deprecated. If you find it useful, +email the author with an example of what you use it for>. -When you use an B<XML::Simple> object as a SAX handler, it will return a -'simple tree' data structure in the same format as C<XMLin()> would return. If -this option is set (to a subroutine reference), then when the tree is built the -subroutine will be called and passed two arguments: a reference to the -B<XML::Simple> object and a reference to the data tree. The return value from -the subroutine will be returned to the SAX driver. (See L<"SAX SUPPORT"> for -more details). +Use this option to specify parameters that should be passed to the constructor +of the underlying XML::Parser object (which of course assumes you're not using +SAX). -You can specify 'DataHandler' as a synonym for 'datahandler'. +=item searchpath => [ list ] (B<in>) (B<handy>) -=item parseropts => [ XML::Parser Options ] (B<in>) +If you pass C<XMLin()> a filename, but the filename include no directory +component, you can use this option to specify which directories should be +searched to locate the file. You might use this option to search first in the +user's home directory, then in a global directory such as /etc. -I<Note: This option is now officially deprecated. If you find it useful, -email the author with an example of what you use it for>. +If a filename is provided to C<XMLin()> but searchpath is not defined, the +file is assumed to be in the current directory. -Use this option to specify parameters that should be passed to the constructor -of the underlying XML::Parser object. +If the first parameter to C<XMLin()> is undefined, the default searchpath +will contain only the directory in which the script itself is located. +Otherwise the default searchpath will be empty. + +=item suppressempty => 1 | '' | undef (B<in>) (B<handy>) + +This option controls what C<XMLin()> should do with empty elements (no +attributes and no content). The default behaviour is to represent them as +empty hashes. Setting this option to a true value (eg: 1) will cause empty +elements to be skipped altogether. Setting the option to 'undef' or the empty +string will cause empty elements to be represented as the undefined value or +the empty string respectively. The latter two alternatives are a little +easier to test for in your code than a hash with no keys. + +=item xmldecl => 1 or xmldecl => 'string' (B<out>) (B<handy>) + +If you want the output from C<XMLout()> to start with the optional XML +declaration, simply set the option to '1'. The default XML declaration is: + + <?xml version='1.0' standalone='yes'?> + +If you want some other string (for example to declare an encoding value), set +the value of this option to the complete string you require. =back @@ -1970,7 +1992,7 @@ From version 1.08_01, B<XML::Simple> includes support for SAX (the Simple API for XML) - specifically SAX2. -In a typical SAX application, an XML Parser (or SAX 'driver') module generates +In a typical SAX application, an XML parser (or SAX 'driver') module generates SAX events (start of element, character data, end of element, etc) as it parses an XML document and a 'handler' module processes the events to extract the required data. This simple model allows for some interesting and powerful @@ -2113,6 +2135,11 @@ =back +Note: The B<XML::SAX> distribution includes an XML parser written entirely in +Perl. It is very portable but it is not very fast. You should consider +installing B<XML::LibXML> or B<XML::SAX::Expat> if they are available for your +platform. + =head1 ERROR HANDLING The XML standard is very clear on the issue of non-compliant documents. An @@ -2268,23 +2295,52 @@ =head1 WHERE TO FROM HERE? -This section is going to be re-written. It will offer advice on what to do do -when your parsing needs outgrow the capabilities of B<XML::Simple> (as they -surely will). This advice will boil down to a quick explanation of tree versus -event based parsers and then recommend: +B<XML::Simple> is able to present a simple API because it makes some +assumptions on your behalf. These include: + +=over 4 + +=item * + +You're not interested in text content consisting only of whitespace + +=item * + +You don't mind that when things get slurped into a hash the order is lost + +=item * + +You don't want fine-grained control of the formatting of generated XML + +=item * + +You would never use a hash key that was not a legal XML element name + +=item * + +You don't need help converting between different encodings + +=back + +In a serious XML project, you'll probably outgrow these assumptions fairly +quickly. This section of the document used to offer some advice on chosing a +more powerful option. That advice has now grown into the 'Perl-XML FAQ' +document which you can find at: L<http://www.perlxml.net/perl-xml-faq.dkb> + +The advice in the FAQ boils down to a quick explanation of tree versus +event based parsers and then recommends: For event based parsing, use SAX (do not set out to write any new code for -XML::Parser's handler API). +XML::Parser's handler API - it is obselete). For tree-based parsing, you could choose between the 'Perlish' approach of -XML::Twig and more standards based DOM implementations - preferably including +XML::Twig and more standards based DOM implementations - preferably one with XPath support. =head1 STATUS -This version (1.08_01) is a beta (development) release. The current stable -version is 1.08. +This version (1.09) is the current stable version. =head1 SEE ALSO |
From: Grant M. <gr...@us...> - 2002-10-11 02:03:21
|
Update of /cvsroot/perl-xml/xml-filter-nsnormalise In directory usw-pr-cvs1:/tmp/cvs-serv12339 Modified Files: Changes Log Message: - bumped version for modified test scripts Index: Changes =================================================================== RCS file: /cvsroot/perl-xml/xml-filter-nsnormalise/Changes,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- Changes 10 Oct 2002 21:38:33 -0000 1.3 +++ Changes 11 Oct 2002 02:03:19 -0000 1.4 @@ -1,5 +1,10 @@ Revision history for Perl extension XML::Filter::NSNormalise. +0.04 Fri Oct 11 + - added dependency on XML::SAX 0.11 + - added dependency on XML::SAX::Writer 0.44 + - changed tests to take advantage of Test::More's diagnostics + 0.03 Fri Oct 11 - added dependency on XML::NamespaceSupport 1.08 - skip tests which rely on XML::SAX if it doesn't work |
From: Grant M. <gr...@us...> - 2002-10-11 02:01:45
|
Update of /cvsroot/perl-xml/xml-filter-nsnormalise/lib/XML/Filter In directory usw-pr-cvs1:/tmp/cvs-serv11955/lib/XML/Filter Modified Files: NSNormalise.pm Log Message: - bumped version for modified test scripts Index: NSNormalise.pm =================================================================== RCS file: /cvsroot/perl-xml/xml-filter-nsnormalise/lib/XML/Filter/NSNormalise.pm,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- NSNormalise.pm 10 Oct 2002 21:36:56 -0000 1.4 +++ NSNormalise.pm 11 Oct 2002 02:01:43 -0000 1.5 @@ -10,7 +10,7 @@ use vars qw($VERSION @ISA); -$VERSION = '0.03'; +$VERSION = '0.04'; @ISA = qw(XML::SAX::Base); |
From: Grant M. <gr...@us...> - 2002-10-11 02:00:48
|
Update of /cvsroot/perl-xml/xml-filter-nsnormalise/t In directory usw-pr-cvs1:/tmp/cvs-serv11705/t Modified Files: 1_basic.t 2_more.t Log Message: - added better diagnostics to trap test failures Index: 1_basic.t =================================================================== RCS file: /cvsroot/perl-xml/xml-filter-nsnormalise/t/1_basic.t,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- 1_basic.t 10 Oct 2002 21:36:13 -0000 1.2 +++ 1_basic.t 11 Oct 2002 02:00:46 -0000 1.3 @@ -10,9 +10,62 @@ ############################################################################## -# Confirm that the module compiles +# Print out a list of installed modules and their version numbers # +eval { + + my @mod_list = qw( + XML::SAX XML::SAX::Writer XML::NamespaceSupport + ); + + + # If XML::SAX is installed, add a list of installed SAX parsers + + eval { require XML::SAX; }; + my $default_parser = ''; + unless($@) { + push @mod_list, map { $_->{Name} } @{XML::SAX->parsers()}; + $default_parser = ref(XML::SAX::ParserFactory->parser()); + } + + + # Extract the version number from each module + + my(%version); + foreach my $module (@mod_list) { + eval " require $module; "; + unless($@) { + no strict 'refs'; + $version{$module} = ${$module . '::VERSION'} || "Unknown"; + } + } + + + # Add version number of the Perl binary + + eval ' use Config; $version{perl} = $Config{version} '; # Should never fail + if($@) { + $version{perl} = $]; + } + unshift @mod_list, 'perl'; + + + # Print details of installed modules on STDERR + + diag(sprintf("\r%-30s %s", 'Package', 'Version')); + foreach my $module (@mod_list) { + $version{$module} = 'Not Installed' unless(defined($version{$module})); + $version{$module} .= " (default parser)" if($module eq $default_parser); + printf STDERR " %-30s %s\n", $module, $version{$module}; + } + +}; + + +############################################################################## +# Confirm that the module compiles + use XML::Filter::NSNormalise ok(1, 'XML::Filter::NSNormalise compiled OK'); @@ -47,7 +100,7 @@ ); }; -ok($@ =~ /Multiple URIs mapped to prefix 'dc'/, "Caught many to one mapping"); +like($@, qr/Multiple URIs mapped to prefix 'dc'/, "Caught many to one mapping"); ############################################################################## @@ -58,6 +111,6 @@ XML::Filter::NSNormalise->new(); }; -ok($@ =~ /No 'Map' option in call to XML::Filter::NSNormalise->new/, +like($@, qr/No 'Map' option in call to XML::Filter::NSNormalise->new/, "Caught missing 'Map' option"); Index: 2_more.t =================================================================== RCS file: /cvsroot/perl-xml/xml-filter-nsnormalise/t/2_more.t,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- 2_more.t 10 Oct 2002 21:36:13 -0000 1.3 +++ 2_more.t 11 Oct 2002 02:00:46 -0000 1.4 @@ -63,6 +63,7 @@ my $p = XML::SAX::ParserFactory->parser(Handler => $filter); ok(ref($p), 'Created a parser object'); +$@ = ''; eval {$p->parse_string(q{ <rdf:RDF xmlns="http://purl.org/rss/1.0/" @@ -72,7 +73,7 @@ </rdf:RDF> }); }; -ok(!$@, 'Parsed with no errors'); +is($@, '', 'Parsed with no errors'); ok($xml =~ s{xmlns=('|")http://purl\.org/rss/1\.0/\1}{ATTR}, "Default namespace declaration untouched"); @@ -83,7 +84,7 @@ ok($xml =~ s{xmlns:dc=('|")http://purl.org/dc/elements/1.1/\1}{ATTR}, "DC namespace declaration mapped successfully"); -ok($xml =~ m{ +like($xml, qr{ ^\s* # optional leading whitespace <rdf:RDF\s+ATTR\s+ATTR\s+ATTR # root element with three ns attrs \s*> # end the tag @@ -110,6 +111,7 @@ my $p = XML::SAX::ParserFactory->parser(Handler => $filter); +$@ = ''; eval {$p->parse_string(q{ <doc xmlns:alpha="companya.com" xmlns:beta="companyb.com"> <ignore>Does nothing</ignore> @@ -118,7 +120,7 @@ </doc> }); }; -ok(!$@, 'Parsed namespaced attributes with no errors'); +is($@, '', 'Parsed namespaced attributes with no errors'); ok($xml =~ s{xmlns:a=('|")companya.com\1}{ATTR}, "Company A namespace declaration mapped successfully"); @@ -136,7 +138,7 @@ ok($xml =~ s{\s+b:align=('|")right\1}{ ATTR_B}, "Company B namespaced attribute mapped successfully"); -ok($xml =~ m{ +like($xml, qr{ ^\s* # optional leading whitespace <doc\s+ATTR\s+ATTR\s*> # root element with two ns attrs \s+<ignore>Does\snothing</ignore> # innocent bystander @@ -164,6 +166,7 @@ my $p = XML::SAX::ParserFactory->parser(Handler => $filter); +$@ = ''; eval {$p->parse_string(q{ <doc xmlns:alpha="companya.com" xmlns:a="aardvark.com"> <alpha:para>paragraph one</alpha:para> @@ -172,7 +175,7 @@ }); }; -ok($@ =~ /Cannot map 'companya\.com' to 'a' - prefix already occurs in document/, +like($@, qr/Cannot map 'companya\.com' to 'a' - prefix already occurs in document/, 'Caught attempt to map to a used prefix'); @@ -193,6 +196,7 @@ my $p = XML::SAX::ParserFactory->parser(Handler => $filter); +$@ = ''; eval {$p->parse_string(q{ <doc xmlns:a="companya.com" xmlns:aa="aardvark.com"> <a:para>paragraph one</a:para> @@ -201,7 +205,7 @@ }); }; -ok(!$@, 'Mapping to same prefix succeeded'); +is($@, '', 'Mapping to same prefix succeeded'); ok($xml =~ s{xmlns:a=('|")companya.com\1}{ATTR}, "Original 'a' prefix declaration mapped successfully to itself"); @@ -209,7 +213,7 @@ ok($xml =~ s{xmlns:aa=('|")aardvark.com\1}{ATTR}, "Original 'aa' prefix declaration survived unscathed"); -ok($xml =~ m{ +like($xml, qr{ ^\s* # optional leading whitespace <doc\s+ATTR\s+ATTR\s*> # root element with two ns attrs \s+<a:para\s*>paragraph\sone</a:para> @@ -236,13 +240,14 @@ my $p = XML::SAX::ParserFactory->parser(Handler => $filter); +$@ = ''; eval {$p->parse_string(q{ <doc xmlns="companya.com"> <para>paragraph one</para> </doc> }); }; -ok(!$@, 'Parsed mapped default namespace with no errors'); +is($@, '', 'Parsed mapped default namespace with no errors'); ok($xml =~ s{xmlns=('|")companya.com\1}{ATTR}, "Default namespace declaration mapped successfully"); @@ -250,7 +255,7 @@ ok($xml =~ s{xmlns:a=('|")companya.com\1}{ATTR}, "Explicit namespace prefix declaration added"); -ok($xml =~ m{ +like($xml, qr{ ^\s* # optional leading whitespace <a:doc\s+ATTR\s+ATTR\s*> # root element with two ns attrs \s+<a:para\s*>paragraph\sone</a:para> @@ -276,6 +281,7 @@ my $p = XML::SAX::ParserFactory->parser(Handler => $filter); +$@ = ''; eval {$p->parse_string(q{ <doc xmlns="companya.com"> <para>paragraph one</para> @@ -288,7 +294,7 @@ </doc> }); }; -ok(!$@, 'Parsed nested default namespaces with no errors'); +is($@, '', 'Parsed nested default namespaces with no errors'); ok($xml =~ s{xmlns=('|")companya.com\1}{ATTR_A}, "Default namespace declaration mapped successfully"); @@ -304,9 +310,8 @@ ok($xml =~ s{xmlns=('|")companyc.com\1}{ATTR_C}, "Default namespace declaration mapped successfully"); -#print "$xml\n"; -ok($xml =~ m{ +like($xml, qr{ ^\s* # optional leading whitespace <a:doc\s+ATTR_A\s+ATTR_A\s*> # root element with two ns attrs \s+<a:para\s*>paragraph\sone</a:para> |
From: Grant M. <gr...@us...> - 2002-10-11 01:59:40
|
Update of /cvsroot/perl-xml/xml-filter-nsnormalise In directory usw-pr-cvs1:/tmp/cvs-serv11343 Modified Files: Makefile.PL Log Message: - added dependency on XML::SAX::Writer 0.44 and XML::SAX 0.11 Index: Makefile.PL =================================================================== RCS file: /cvsroot/perl-xml/xml-filter-nsnormalise/Makefile.PL,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- Makefile.PL 10 Oct 2002 21:35:06 -0000 1.3 +++ Makefile.PL 11 Oct 2002 01:59:37 -0000 1.4 @@ -7,7 +7,8 @@ 'VERSION_FROM' => 'lib/XML/Filter/NSNormalise.pm', 'PREREQ_PM' => { Test::Simple => 0.41, - XML::SAX => undef, + XML::SAX => 0.11, + XML::SAX::Writer => 0.44, XML::NamespaceSupport => 1.08, }, 'EXE_FILES' => [ qw(bin/xmlnsnorm) ], |
From: Grant M. <gr...@us...> - 2002-10-10 21:38:36
|
Update of /cvsroot/perl-xml/xml-filter-nsnormalise In directory usw-pr-cvs1:/tmp/cvs-serv15055 Modified Files: Changes Log Message: - Release 0.03 Index: Changes =================================================================== RCS file: /cvsroot/perl-xml/xml-filter-nsnormalise/Changes,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- Changes 9 Oct 2002 23:06:07 -0000 1.2 +++ Changes 10 Oct 2002 21:38:33 -0000 1.3 @@ -1,5 +1,9 @@ Revision history for Perl extension XML::Filter::NSNormalise. +0.03 Fri Oct 11 + - added dependency on XML::NamespaceSupport 1.08 + - skip tests which rely on XML::SAX if it doesn't work + 0.02 Thu Oct 10 - added xmlnsnorm command-line utility - fixed fatal error on mapping to the same prefix the document already uses |
From: Grant M. <gr...@us...> - 2002-10-10 21:36:59
|
Update of /cvsroot/perl-xml/xml-filter-nsnormalise/lib/XML/Filter In directory usw-pr-cvs1:/tmp/cvs-serv14488/lib/XML/Filter Modified Files: NSNormalise.pm Log Message: - bumped version for release of new test scripts Index: NSNormalise.pm =================================================================== RCS file: /cvsroot/perl-xml/xml-filter-nsnormalise/lib/XML/Filter/NSNormalise.pm,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- NSNormalise.pm 9 Oct 2002 23:06:08 -0000 1.3 +++ NSNormalise.pm 10 Oct 2002 21:36:56 -0000 1.4 @@ -10,7 +10,7 @@ use vars qw($VERSION @ISA); -$VERSION = '0.02'; +$VERSION = '0.03'; @ISA = qw(XML::SAX::Base); |
From: Grant M. <gr...@us...> - 2002-10-10 21:36:16
|
Update of /cvsroot/perl-xml/xml-filter-nsnormalise/t In directory usw-pr-cvs1:/tmp/cvs-serv14219/t Modified Files: 1_basic.t 2_more.t Log Message: - skip tests if SAX installation broken Index: 1_basic.t =================================================================== RCS file: /cvsroot/perl-xml/xml-filter-nsnormalise/t/1_basic.t,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- 1_basic.t 9 Oct 2002 02:25:33 -0000 1.1.1.1 +++ 1_basic.t 10 Oct 2002 21:36:13 -0000 1.2 @@ -1,4 +1,7 @@ # $Id$ +############################################################################## +# Very basic tests that do not rely on XML::SAX being installed correctly. +# use strict; use Test::More tests => 6; Index: 2_more.t =================================================================== RCS file: /cvsroot/perl-xml/xml-filter-nsnormalise/t/2_more.t,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- 2_more.t 9 Oct 2002 23:06:08 -0000 1.2 +++ 2_more.t 10 Oct 2002 21:36:13 -0000 1.3 @@ -1,4 +1,7 @@ # $Id$ +############################################################################## +# These tests require a functional XML::SAX installation +# use strict; use Test::More; @@ -11,6 +14,18 @@ unless(eval { require XML::SAX::ParserFactory }) { plan skip_all => 'XML::SAX::ParserFactory not installed'; + } + + # Test SAX installation + + eval { + my $xml = ''; + my $writer = XML::SAX::Writer->new(Output => \$xml); + my $parser = XML::SAX::ParserFactory->parser(Handler => $writer); + $parser->parse_string('<doc>text</doc>'); + }; + if($@) { + plan skip_all => "XML::SAX is not installed correctly: $@"; } } |
From: Grant M. <gr...@us...> - 2002-10-10 21:35:10
|
Update of /cvsroot/perl-xml/xml-filter-nsnormalise In directory usw-pr-cvs1:/tmp/cvs-serv13401 Modified Files: Makefile.PL Log Message: - added dependency on XML::NamespaceSupport 1.08 Index: Makefile.PL =================================================================== RCS file: /cvsroot/perl-xml/xml-filter-nsnormalise/Makefile.PL,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- Makefile.PL 9 Oct 2002 23:06:07 -0000 1.2 +++ Makefile.PL 10 Oct 2002 21:35:06 -0000 1.3 @@ -6,8 +6,9 @@ 'NAME' => 'XML::Filter::NSNormalise', 'VERSION_FROM' => 'lib/XML/Filter/NSNormalise.pm', 'PREREQ_PM' => { - Test::Simple => 0.41, - XML::SAX => undef, + Test::Simple => 0.41, + XML::SAX => undef, + XML::NamespaceSupport => 1.08, }, 'EXE_FILES' => [ qw(bin/xmlnsnorm) ], ($] >= 5.005 ? ( |
From: Grant M. <gr...@us...> - 2002-10-09 23:06:10
|
Update of /cvsroot/perl-xml/xml-filter-nsnormalise/t In directory usw-pr-cvs1:/tmp/cvs-serv17032/t Modified Files: 2_more.t Log Message: - fixed fatal error on mapping to the same prefix the document already uses - added xmlnsnorm command-line utility - fixed typo in sample code Index: 2_more.t =================================================================== RCS file: /cvsroot/perl-xml/xml-filter-nsnormalise/t/2_more.t,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- 2_more.t 9 Oct 2002 02:25:33 -0000 1.1.1.1 +++ 2_more.t 9 Oct 2002 23:06:08 -0000 1.2 @@ -15,7 +15,7 @@ } -plan tests => 28; +plan tests => 32; $^W = 1; @@ -159,6 +159,50 @@ ok($@ =~ /Cannot map 'companya\.com' to 'a' - prefix already occurs in document/, 'Caught attempt to map to a used prefix'); + + +############################################################################## +# Try mapping a URI to the same prefix which is already used and ensure that it +# all still works. +# + +$xml = ''; +$writer = XML::SAX::Writer->new(Output => \$xml); + +$filter = XML::Filter::NSNormalise->new( + Map => { + 'companya.com' => 'a', + }, + Handler => $writer, +); + +my $p = XML::SAX::ParserFactory->parser(Handler => $filter); + +eval {$p->parse_string(q{ + <doc xmlns:a="companya.com" xmlns:aa="aardvark.com"> + <a:para>paragraph one</a:para> + <aa:para>paragraph two</aa:para> + </doc> + }); +}; + +ok(!$@, 'Mapping to same prefix succeeded'); + +ok($xml =~ s{xmlns:a=('|")companya.com\1}{ATTR}, + "Original 'a' prefix declaration mapped successfully to itself"); + +ok($xml =~ s{xmlns:aa=('|")aardvark.com\1}{ATTR}, + "Original 'aa' prefix declaration survived unscathed"); + +ok($xml =~ m{ + ^\s* # optional leading whitespace + <doc\s+ATTR\s+ATTR\s*> # root element with two ns attrs + \s+<a:para\s*>paragraph\sone</a:para> + \s+<aa:para\s*>paragraph\stwo</aa:para> + \s+</doc\s*> + \s*$ +}xs, "Resulting document unchanged"); + ############################################################################## |
From: Grant M. <gr...@us...> - 2002-10-09 23:06:10
|
Update of /cvsroot/perl-xml/xml-filter-nsnormalise/bin In directory usw-pr-cvs1:/tmp/cvs-serv17032/bin Added Files: xmlnsnorm Log Message: - fixed fatal error on mapping to the same prefix the document already uses - added xmlnsnorm command-line utility - fixed typo in sample code --- NEW FILE: xmlnsnorm --- #!/usr/bin/perl -w ############################################################################## # $Id: xmlnsnorm,v 1.1 2002/10/09 23:06:08 grantm Exp $ # # Title: xmlnsnorm # # Author: Grant McLean <gr...@cp...> # # Script for normalising namespace prefixes in XML files. Use -h option for # help. # use strict; use Getopt::Long; use Pod::Usage; use IO::File; use XML::SAX::ParserFactory; use XML::SAX::Writer; use XML::Filter::NSNormalise; ############################################################################## # Handle command line parameters # my %opt = (m => []); GetOptions(\%opt, 'm=s', 'h') || pod2usage(0); pod2usage({-verbose => 2, -exitval => 0}) if($opt{h}); pod2usage(0) unless(@{$opt{m}}); my $filename = shift || '-'; ############################################################################## # Build up the hash of URI to Prefix mappings. # my %mapping = map { split /\s+/, $_, 2 } @{$opt{m}}; ############################################################################## # Create a filter pipeline and 'run' it # my $writer = XML::SAX::Writer->new( Output => \*STDOUT ); my $filter = XML::Filter::NSNormalise->new( Map => \%mapping, Handler => $writer ); my $parser = XML::SAX::ParserFactory->parser(Handler => $filter); my $fd = IO::File->new("<$filename") || die "$!"; $parser->parse_file($fd); print "\n"; exit; __END__ =head1 NAME xmlnsnorm - normalises namespace prefixes in XML files =head1 SYNOPSIS xmlnsnorm -m 'URI prefix' [ -m 'URI prefix' ... ] [ <filename> ] Options: -m <mapping> specify URI to prefix mapping (space separated) -h help - display the full documentation Example: xmlnsnorm -m 'http://purl.org/dc/elements/1.1/ dc' in.xml >out.xml =head1 DESCRIPTION This script takes an XML document either on STDIN or from a named file and writes a 'normalised' version of the file to STDOUT. Any prefixed names (elements or attributes) associated with a mapped namespace URI will have their prefix changed to the prefix you specify. Any namespace prefixes which occur in the document but for which you have not specified a mapping, will be passed through unchanged. =head1 SEE ALSO This script uses the following modules: XML::SAX::ParserFactory XML::Filter::NSNormalise XML::SAX::Writer =head1 AUTHOR Grant McLean <gr...@cp...> =head1 COPYRIGHT Copyright (c) 2002 Grant McLean. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut |
From: Grant M. <gr...@us...> - 2002-10-09 23:06:10
|
Update of /cvsroot/perl-xml/xml-filter-nsnormalise In directory usw-pr-cvs1:/tmp/cvs-serv17032 Modified Files: Changes MANIFEST Makefile.PL Log Message: - fixed fatal error on mapping to the same prefix the document already uses - added xmlnsnorm command-line utility - fixed typo in sample code Index: Changes =================================================================== RCS file: /cvsroot/perl-xml/xml-filter-nsnormalise/Changes,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- Changes 9 Oct 2002 02:25:33 -0000 1.1.1.1 +++ Changes 9 Oct 2002 23:06:07 -0000 1.2 @@ -1,6 +1,12 @@ Revision history for Perl extension XML::Filter::NSNormalise. -0.01 Wed Oct 9 10:00:44 2002 +0.02 Thu Oct 10 + - added xmlnsnorm command-line utility + - fixed fatal error on mapping to the same prefix the document already uses + - fixed typo in sample code + - added extra examples/clarifcations in POD + +0.01 Wed Oct 9 - first release to CPAN - added tests - added POD Index: MANIFEST =================================================================== RCS file: /cvsroot/perl-xml/xml-filter-nsnormalise/MANIFEST,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- MANIFEST 9 Oct 2002 02:25:33 -0000 1.1.1.1 +++ MANIFEST 9 Oct 2002 23:06:07 -0000 1.2 @@ -2,6 +2,7 @@ Makefile.PL MANIFEST lib/XML/Filter/NSNormalise.pm +bin/xmlnsnorm README t/1_basic.t t/2_more.t Index: Makefile.PL =================================================================== RCS file: /cvsroot/perl-xml/xml-filter-nsnormalise/Makefile.PL,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- Makefile.PL 9 Oct 2002 02:25:33 -0000 1.1.1.1 +++ Makefile.PL 9 Oct 2002 23:06:07 -0000 1.2 @@ -9,6 +9,7 @@ Test::Simple => 0.41, XML::SAX => undef, }, + 'EXE_FILES' => [ qw(bin/xmlnsnorm) ], ($] >= 5.005 ? ( AUTHOR => 'Grant McLean <gr...@cp...>', ABSTRACT_FROM => 'lib/XML/Filter/NSNormalise.pm', |
From: Grant M. <gr...@us...> - 2002-10-09 23:06:10
|
Update of /cvsroot/perl-xml/xml-filter-nsnormalise/lib/XML/Filter In directory usw-pr-cvs1:/tmp/cvs-serv17032/lib/XML/Filter Modified Files: NSNormalise.pm Log Message: - fixed fatal error on mapping to the same prefix the document already uses - added xmlnsnorm command-line utility - fixed typo in sample code Index: NSNormalise.pm =================================================================== RCS file: /cvsroot/perl-xml/xml-filter-nsnormalise/lib/XML/Filter/NSNormalise.pm,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- NSNormalise.pm 9 Oct 2002 02:31:58 -0000 1.2 +++ NSNormalise.pm 9 Oct 2002 23:06:08 -0000 1.3 @@ -10,7 +10,7 @@ use vars qw($VERSION @ISA); -$VERSION = '0.01'; +$VERSION = '0.02'; @ISA = qw(XML::SAX::Base); @@ -96,8 +96,10 @@ if($attr->{Prefix} eq 'xmlns') { if($self->{ReverseMap}->{$attr->{LocalName}}) { - die "Cannot map '$self->{ReverseMap}->{$attr->{LocalName}}' to " . - "'$attr->{LocalName}' - prefix already occurs in document"; + if($attr->{Value} ne $self->{ReverseMap}->{$attr->{LocalName}}) { + die "Cannot map '$self->{ReverseMap}->{$attr->{LocalName}}' to " . + "'$attr->{LocalName}' - prefix already occurs in document"; + } } if($self->{Map}->{$attr->{Value}}) { $attr = { %$attr }; @@ -182,7 +184,7 @@ ... through this filter ... XML::Filter::NSNormalise->new( - Map => {=20 + Map => { 'http://purl.org/dc/elements/1.1/' => 'dc' } ) @@ -196,7 +198,15 @@ <dc:date>2002-10-08</dc:date> </rdf:RDF> -You can specify more than one namespace URI to prefix mapping. +You can specify more than one namespace URI to prefix mapping, eg: + + XML::Filter::NSNormalise->new( + Map => { + 'http://purl.org/dc/elements/1.1/' => 'dc', + 'http://www.w3.org/1999/02/22-rdf-syntax-ns#' => 'rdf', + 'http://purl.org/rss/1.0/modules/syndication/' => 'syn' + } + ) =head1 METHODS @@ -214,10 +224,18 @@ =head1 ERROR HANDLING Attempting to map more than one URI to the same prefix will cause a fatal -exception. +exception, eg: + + XML::Filter::NSNormalise->new( + Map => { + 'http://x.com/ => 'z', + 'http://y.com/ => 'z' + } + ) Attempting to map a URI to a prefix that is already mapped to a different URI -will cause a fatal exception. +will cause a fatal exception (eg: you map a URI to the prefix 'foo' but the +document your are filtering already uses 'foo' for a different URI). =head1 SEE ALSO |
From: Grant M. <gr...@us...> - 2002-10-09 22:59:55
|
Update of /cvsroot/perl-xml/xml-filter-nsnormalise/bin In directory usw-pr-cvs1:/tmp/cvs-serv14683/bin Log Message: Directory /cvsroot/perl-xml/xml-filter-nsnormalise/bin added to the repository |
From: Grant M. <gr...@us...> - 2002-10-09 02:32:01
|
Update of /cvsroot/perl-xml/xml-filter-nsnormalise/lib/XML/Filter In directory usw-pr-cvs1:/tmp/cvs-serv22165/lib/XML/Filter Modified Files: NSNormalise.pm Log Message: - fixed version number before release Index: NSNormalise.pm =================================================================== RCS file: /cvsroot/perl-xml/xml-filter-nsnormalise/lib/XML/Filter/NSNormalise.pm,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- NSNormalise.pm 9 Oct 2002 02:25:34 -0000 1.1.1.1 +++ NSNormalise.pm 9 Oct 2002 02:31:58 -0000 1.2 @@ -10,7 +10,7 @@ use vars qw($VERSION @ISA); -$VERSION = '0.91'; +$VERSION = '0.01'; @ISA = qw(XML::SAX::Base); |
From: Grant M. <gr...@us...> - 2002-10-09 02:25:37
|
Update of /cvsroot/perl-xml/xml-filter-nsnormalise In directory usw-pr-cvs1:/tmp/cvs-serv20085 Log Message: XML::Filter::NSNormalise Version 0.01 Status: Vendor Tag: grantm Release Tags: start N xml-filter-nsnormalise/Makefile.PL N xml-filter-nsnormalise/README N xml-filter-nsnormalise/Changes N xml-filter-nsnormalise/MANIFEST N xml-filter-nsnormalise/t/1_basic.t N xml-filter-nsnormalise/t/2_more.t N xml-filter-nsnormalise/lib/XML/Filter/NSNormalise.pm No conflicts created by this import ***** Bogus filespec: - Imported sources |
From: Edwin P. <edp...@us...> - 2002-09-18 07:53:55
|
Update of /cvsroot/perl-xml/xalan-p In directory usw-pr-cvs1:/tmp/cvs-serv27743 Modified Files: Xalan.xs Log Message: Fixed for win32 build Index: Xalan.xs =================================================================== RCS file: /cvsroot/perl-xml/xalan-p/Xalan.xs,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- Xalan.xs 30 Apr 2002 05:33:02 -0000 1.3 +++ Xalan.xs 18 Sep 2002 07:53:46 -0000 1.4 @@ -399,7 +399,8 @@ const XalanDOMString getError() const { - return XALAN_STATIC_UCODE_STRING(m_func_name); + return PointerToDOMString(m_func_name); +//XALAN_STATIC_UCODE_STRING } private: |
From: Edwin P. <edp...@us...> - 2002-09-18 07:53:55
|
Update of /cvsroot/perl-xml/xalan-p/t In directory usw-pr-cvs1:/tmp/cvs-serv27743/t Modified Files: 15ext_ctx.t 16nodeset.t Log Message: Fixed for win32 build Index: 15ext_ctx.t =================================================================== RCS file: /cvsroot/perl-xml/xalan-p/t/15ext_ctx.t,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- 15ext_ctx.t 18 Apr 2002 03:37:42 -0000 1.1.1.1 +++ 15ext_ctx.t 18 Sep 2002 07:53:46 -0000 1.2 @@ -27,8 +27,8 @@ my %functions = ( 'asctime' => sub { my ($context, $context_node) = @_; - #print STDERR Dumper($context); - #print STDERR Dumper($context_node); + debug($context); + debug($context_node); # call DOM method on context node #print STDERR "Name of context node: ", $context_node->getNodeName() . "\n"; @@ -39,7 +39,7 @@ }, 'square-root' => sub { my ($context, $context_node, $xobj) = @_; - #print STDERR Dumper($xobj); + debug($xobj); my $num = $xobj->number; #print STDERR "Post converted xobj type: ". Dumper($num); @@ -90,3 +90,6 @@ my $res = $tr->transform_to_file($parsed, @files[1,2]); ok($res) or print STDERR $tr->errstr; +sub debug { + print STDERR Dumper(@_) if $ENV{DEBUG_XALAN}; +} Index: 16nodeset.t =================================================================== RCS file: /cvsroot/perl-xml/xalan-p/t/16nodeset.t,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- 16nodeset.t 18 Apr 2002 03:37:42 -0000 1.1.1.1 +++ 16nodeset.t 18 Sep 2002 07:53:46 -0000 1.2 @@ -85,13 +85,14 @@ my $obj_factory = $context->get_xobject_factory; if (ref $xobj eq "XML::Xalan::NodeSet") { - my @nodes = $xobj->get_nodelist; - #print STDERR Dumper(@nodes); + #my @nodes = $xobj->get_nodelist; + my @nodes = $xobj->my_nodeset; + debug(@nodes); my $ret = $obj_factory->create_nodeset(@nodes); return $ret; } else { - #print STDERR Dumper $xobj; + debug($xobj); my $ret = $obj_factory->create_boolean($xobj); return $ret; } @@ -109,3 +110,6 @@ my $res = $tr->transform_to_file($parsed, $xsl, $file); ok($res) or print STDERR $tr->errstr; +sub debug { + print STDERR Dumper(@_) if $ENV{DEBUG_XALAN}; +} |
From: Christian G. <phi...@us...> - 2002-09-14 20:20:33
|
Update of /cvsroot/perl-xml/XML-LibXML-Common In directory usw-pr-cvs1:/tmp/cvs-serv14154 Modified Files: Changes Makefile.PL README Log Message: Modified Files: Changes README + whitespces, email and version notes Common.pm - typos Makefile.PL + HPUX fix (?) Index: Changes =================================================================== RCS file: /cvsroot/perl-xml/XML-LibXML-Common/Changes,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- Changes 2 Sep 2002 09:15:16 -0000 1.1.1.1 +++ Changes 14 Sep 2002 20:20:30 -0000 1.2 @@ -5,4 +5,4 @@ 0.10 Sat Aug 31 20:00:00 2002 - implemented encoding functions - - libxml/ libgdome conform implementation + - libxml/ libgdome conform implementation Index: Makefile.PL =================================================================== RCS file: /cvsroot/perl-xml/XML-LibXML-Common/Makefile.PL,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- Makefile.PL 2 Sep 2002 09:15:16 -0000 1.1.1.1 +++ Makefile.PL 14 Sep 2002 20:20:30 -0000 1.2 @@ -294,14 +294,14 @@ my $libs = $is_Win32 ? " $lib.lib " : "-l$lib"; # my $libs = "-l$lib"; if ($is_Win32) { - $result = try_link(<<"SRC", $libs); + $result = try_link(<<"SRC",undef ); #include <windows.h> #include <winsock.h> blank() { return 0; } int t() { ${func}(); return 0; } SRC unless ($result) { - $result = try_link(<<"SRC", $libs); + $result = try_link(<<"SRC", undef); #include <windows.h> #include <winsock.h> blank() { return 0; } @@ -310,7 +310,7 @@ } } else { - $result = try_link(<<"SRC", $libs); + $result = try_link(<<"SRC", undef); blank() { return 0; } int t() { ${func}(); return 0; } SRC Index: README =================================================================== RCS file: /cvsroot/perl-xml/XML-LibXML-Common/README,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- README 2 Sep 2002 09:15:16 -0000 1.1.1.1 +++ README 14 Sep 2002 20:20:30 -0000 1.2 @@ -1,10 +1,10 @@ XML::LibXML::Common version 0.10 -============================== +================================ XML::LibXML::Common contains several constants and functions that are shared by XML::LibXML, XML::GDOME and XML::LibXSLT (not all done, yet) -This package is required at least for XML::LibXML 1.54 or later to +This package is required at least for XML::LibXML 1.53 or later to work properly. the latest cvs can be found at sourceforge: @@ -15,4 +15,4 @@ on a regular basis. but since i am offline from time to time it may take up to a week before i will be able to answer. -christian glahn +christian glahn ( christian.glahn at uibk.ac.at ) |
From: Christian G. <phi...@us...> - 2002-09-02 09:38:18
|
Update of /cvsroot/perl-xml/XML-LibXML-Common/blib/lib/XML/LibXML In directory usw-pr-cvs1:/tmp/cvs-serv18919/blib/lib/XML/LibXML Removed Files: .exists Common.pm Log Message: Removed Files: Common.bs Common.c Makefile pm_to_blib blib/arch/auto/XML/LibXML/Common/.exists blib/arch/auto/XML/LibXML/Common/Common.bs blib/lib/XML/LibXML/.exists blib/lib/XML/LibXML/Common.pm blib/lib/auto/XML/LibXML/Common/.exists blib/man3/.exists blib/man3/XML::LibXML::Common.3pm stupid me forgot to run make distclean before import ... --- .exists DELETED --- --- Common.pm DELETED --- |
From: Christian G. <phi...@us...> - 2002-09-02 09:38:18
|
Update of /cvsroot/perl-xml/XML-LibXML-Common/blib/lib/auto/XML/LibXML/Common In directory usw-pr-cvs1:/tmp/cvs-serv18919/blib/lib/auto/XML/LibXML/Common Removed Files: .exists Log Message: Removed Files: Common.bs Common.c Makefile pm_to_blib blib/arch/auto/XML/LibXML/Common/.exists blib/arch/auto/XML/LibXML/Common/Common.bs blib/lib/XML/LibXML/.exists blib/lib/XML/LibXML/Common.pm blib/lib/auto/XML/LibXML/Common/.exists blib/man3/.exists blib/man3/XML::LibXML::Common.3pm stupid me forgot to run make distclean before import ... --- .exists DELETED --- |
From: Christian G. <phi...@us...> - 2002-09-02 09:38:18
|
Update of /cvsroot/perl-xml/XML-LibXML-Common/blib/arch/auto/XML/LibXML/Common In directory usw-pr-cvs1:/tmp/cvs-serv18919/blib/arch/auto/XML/LibXML/Common Removed Files: .exists Common.bs Log Message: Removed Files: Common.bs Common.c Makefile pm_to_blib blib/arch/auto/XML/LibXML/Common/.exists blib/arch/auto/XML/LibXML/Common/Common.bs blib/lib/XML/LibXML/.exists blib/lib/XML/LibXML/Common.pm blib/lib/auto/XML/LibXML/Common/.exists blib/man3/.exists blib/man3/XML::LibXML::Common.3pm stupid me forgot to run make distclean before import ... --- .exists DELETED --- --- Common.bs DELETED --- |
From: Christian G. <phi...@us...> - 2002-09-02 09:38:17
|
Update of /cvsroot/perl-xml/XML-LibXML-Common In directory usw-pr-cvs1:/tmp/cvs-serv18919 Removed Files: Common.bs Common.c Makefile pm_to_blib Log Message: Removed Files: Common.bs Common.c Makefile pm_to_blib blib/arch/auto/XML/LibXML/Common/.exists blib/arch/auto/XML/LibXML/Common/Common.bs blib/lib/XML/LibXML/.exists blib/lib/XML/LibXML/Common.pm blib/lib/auto/XML/LibXML/Common/.exists blib/man3/.exists blib/man3/XML::LibXML::Common.3pm stupid me forgot to run make distclean before import ... --- Common.bs DELETED --- --- Common.c DELETED --- --- Makefile DELETED --- --- pm_to_blib DELETED --- |
From: Christian G. <phi...@us...> - 2002-09-02 09:38:17
|
Update of /cvsroot/perl-xml/XML-LibXML-Common/blib/man3 In directory usw-pr-cvs1:/tmp/cvs-serv18919/blib/man3 Removed Files: .exists XML::LibXML::Common.3pm Log Message: Removed Files: Common.bs Common.c Makefile pm_to_blib blib/arch/auto/XML/LibXML/Common/.exists blib/arch/auto/XML/LibXML/Common/Common.bs blib/lib/XML/LibXML/.exists blib/lib/XML/LibXML/Common.pm blib/lib/auto/XML/LibXML/Common/.exists blib/man3/.exists blib/man3/XML::LibXML::Common.3pm stupid me forgot to run make distclean before import ... --- .exists DELETED --- --- XML::LibXML::Common.3pm DELETED --- |