home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / tsw / TSW_3.4.0.exe / Apache2 / perl / Common.pm < prev    next >
Encoding:
Perl POD Document  |  2003-02-27  |  11.7 KB  |  307 lines

  1. #-------------------------------------------------------------------------#
  2. # $Id: Common.pm,v 1.5 2003/02/27 18:32:59 phish108 Exp $
  3. #-------------------------------------------------------------------------#
  4. package XML::LibXML::Common;
  5.  
  6. #-------------------------------------------------------------------------#
  7. # global blur                                                             #
  8. #-------------------------------------------------------------------------#
  9. use strict;
  10.  
  11. require Exporter;
  12. require DynaLoader;
  13. use vars qw( @ISA $VERSION @EXPORT @EXPORT_OK %EXPORT_TAGS);
  14.  
  15. @ISA = qw(DynaLoader Exporter);
  16.  
  17. $VERSION = '0.13';
  18.  
  19. bootstrap XML::LibXML::Common $VERSION;
  20.  
  21. #-------------------------------------------------------------------------#
  22. # export information                                                      #
  23. #-------------------------------------------------------------------------#
  24. %EXPORT_TAGS = (
  25.                 all => [qw(
  26.                            ELEMENT_NODE
  27.                            ATTRIBUTE_NODE
  28.                            TEXT_NODE
  29.                            CDATA_SECTION_NODE
  30.                            ENTITY_REFERENCE_NODE
  31.                            ENTITY_NODE
  32.                            PI_NODE
  33.                            PROCESSING_INSTRUCTION_NODE
  34.                            COMMENT_NODE
  35.                            DOCUMENT_NODE
  36.                            DOCUMENT_TYPE_NODE
  37.                            DOCUMENT_FRAG_NODE
  38.                            DOCUMENT_FRAGMENT_NODE
  39.                            NOTATION_NODE
  40.                            HTML_DOCUMENT_NODE
  41.                            DTD_NODE
  42.                            ELEMENT_DECLARATION
  43.                            ATTRIBUTE_DECLARATION
  44.                            ENTITY_DECLARATION
  45.                            NAMESPACE_DECLARATION
  46.                            XINCLUDE_END
  47.                            XINCLUDE_START
  48.                            encodeToUTF8
  49.                            decodeFromUTF8
  50.                           )],
  51.                 w3c => [qw(
  52.                            ELEMENT_NODE
  53.                            ATTRIBUTE_NODE
  54.                            TEXT_NODE
  55.                            CDATA_SECTION_NODE
  56.                            ENTITY_REFERENCE_NODE
  57.                            ENTITY_NODE
  58.                            PI_NODE
  59.                            PROCESSING_INSTRUCTION_NODE
  60.                            COMMENT_NODE
  61.                            DOCUMENT_NODE
  62.                            DOCUMENT_TYPE_NODE
  63.                            DOCUMENT_FRAG_NODE
  64.                            DOCUMENT_FRAGMENT_NODE
  65.                            NOTATION_NODE
  66.                            HTML_DOCUMENT_NODE
  67.                            DTD_NODE
  68.                            ELEMENT_DECLARATION
  69.                            ATTRIBUTE_DECLARATION
  70.                            ENTITY_DECLARATION
  71.                            NAMESPACE_DECLARATION
  72.                            XINCLUDE_END
  73.                            XINCLUDE_START
  74.                           )],
  75.                 libxml => [qw(
  76.                            XML_ELEMENT_NODE
  77.                            XML_ATTRIBUTE_NODE
  78.                            XML_TEXT_NODE
  79.                            XML_CDATA_SECTION_NODE
  80.                            XML_ENTITY_REF_NODE
  81.                            XML_ENTITY_NODE
  82.                            XML_PI_NODE
  83.                            XML_COMMENT_NODE
  84.                            XML_DOCUMENT_NODE
  85.                            XML_DOCUMENT_TYPE_NODE
  86.                            XML_DOCUMENT_FRAG_NODE
  87.                            XML_NOTATION_NODE
  88.                            XML_HTML_DOCUMENT_NODE
  89.                            XML_DTD_NODE
  90.                            XML_ELEMENT_DECL
  91.                            XML_ATTRIBUTE_DECL
  92.                            XML_ENTITY_DECL
  93.                            XML_NAMESPACE_DECL
  94.                            XML_XINCLUDE_END
  95.                            XML_XINCLUDE_START
  96.                           )],
  97.                 gdome => [qw(
  98.                            GDOME_ELEMENT_NODE
  99.                            GDOME_ATTRIBUTE_NODE
  100.                            GDOME_TEXT_NODE
  101.                            GDOME_CDATA_SECTION_NODE
  102.                            GDOME_ENTITY_REF_NODE
  103.                            GDOME_ENTITY_NODE
  104.                            GDOME_PI_NODE
  105.                            GDOME_COMMENT_NODE
  106.                            GDOME_DOCUMENT_NODE
  107.                            GDOME_DOCUMENT_TYPE_NODE
  108.                            GDOME_DOCUMENT_FRAG_NODE
  109.                            GDOME_NOTATION_NODE
  110.                            GDOME_HTML_DOCUMENT_NODE
  111.                            GDOME_DTD_NODE
  112.                            GDOME_ELEMENT_DECL
  113.                            GDOME_ATTRIBUTE_DECL
  114.                            GDOME_ENTITY_DECL
  115.                            GDOME_NAMESPACE_DECL
  116.                            GDOME_XINCLUDE_END
  117.                            GDOME_XINCLUDE_START
  118.                           )],
  119.                 encoding => [qw(
  120.                                 encodeToUTF8
  121.                                 decodeFromUTF8
  122.                                )],
  123.                );
  124.  
  125. @EXPORT_OK = (
  126.               @{$EXPORT_TAGS{encoding}},
  127.               @{$EXPORT_TAGS{w3c}},
  128.               @{$EXPORT_TAGS{libxml}},
  129.               @{$EXPORT_TAGS{gdome}},
  130.              );
  131.  
  132. @EXPORT = (
  133.            @{$EXPORT_TAGS{encoding}},
  134.            @{$EXPORT_TAGS{w3c}},
  135.           );
  136.  
  137. #-------------------------------------------------------------------------#
  138. # W3 conform node types                                                   #
  139. #-------------------------------------------------------------------------#
  140. use constant ELEMENT_NODE                => 1;
  141. use constant ATTRIBUTE_NODE              => 2;
  142. use constant TEXT_NODE                   => 3;
  143. use constant CDATA_SECTION_NODE          => 4;
  144. use constant ENTITY_REFERENCE_NODE       => 5;
  145. use constant ENTITY_NODE                 => 6;
  146. use constant PROCESSING_INSTRUCTION_NODE => 7;
  147. use constant COMMENT_NODE                => 8;
  148. use constant DOCUMENT_NODE               => 9;
  149. use constant DOCUMENT_TYPE_NODE          => 10;
  150. use constant DOCUMENT_FRAGMENT_NODE      => 11;
  151. use constant NOTATION_NODE               => 12;
  152. use constant HTML_DOCUMENT_NODE          => 13;
  153. use constant DTD_NODE                    => 14;
  154. use constant ELEMENT_DECLARATION         => 15;
  155. use constant ATTRIBUTE_DECLARATION       => 16;
  156. use constant ENTITY_DECLARATION          => 17;
  157. use constant NAMESPACE_DECLARATION       => 18;
  158.  
  159. #-------------------------------------------------------------------------#
  160. # some extras for the W3 spec
  161. #-------------------------------------------------------------------------#
  162. use constant PI_NODE                     => 7;
  163. use constant DOCUMENT_FRAG_NODE          => 11;
  164. use constant XINCLUDE_END                => 19;
  165. use constant XINCLUDE_START              => 20;
  166.  
  167. #-------------------------------------------------------------------------#
  168. # libxml2 compat names                                                    #
  169. #-------------------------------------------------------------------------#
  170. use constant XML_ELEMENT_NODE            => 1;
  171. use constant XML_ATTRIBUTE_NODE          => 2;
  172. use constant XML_TEXT_NODE               => 3;
  173. use constant XML_CDATA_SECTION_NODE      => 4;
  174. use constant XML_ENTITY_REF_NODE         => 5;
  175. use constant XML_ENTITY_NODE             => 6;
  176. use constant XML_PI_NODE                 => 7;
  177. use constant XML_COMMENT_NODE            => 8;
  178. use constant XML_DOCUMENT_NODE           => 9;
  179. use constant XML_DOCUMENT_TYPE_NODE      => 10;
  180. use constant XML_DOCUMENT_FRAG_NODE      => 11;
  181. use constant XML_NOTATION_NODE           => 12;
  182. use constant XML_HTML_DOCUMENT_NODE      => 13;
  183. use constant XML_DTD_NODE                => 14;
  184. use constant XML_ELEMENT_DECL            => 15;
  185. use constant XML_ATTRIBUTE_DECL          => 16;
  186. use constant XML_ENTITY_DECL             => 17;
  187. use constant XML_NAMESPACE_DECL          => 18;
  188. use constant XML_XINCLUDE_START          => 19;
  189. use constant XML_XINCLUDE_END            => 20;
  190.  
  191. #-------------------------------------------------------------------------#
  192. # libgdome compat names                                                   #
  193. #-------------------------------------------------------------------------#
  194. use constant GDOME_ELEMENT_NODE          => 1;
  195. use constant GDOME_ATTRIBUTE_NODE        => 2;
  196. use constant GDOME_TEXT_NODE             => 3;
  197. use constant GDOME_CDATA_SECTION_NODE    => 4;
  198. use constant GDOME_ENTITY_REF_NODE       => 5;
  199. use constant GDOME_ENTITY_NODE           => 6;
  200. use constant GDOME_PI_NODE               => 7;
  201. use constant GDOME_COMMENT_NODE          => 8;
  202. use constant GDOME_DOCUMENT_NODE         => 9;
  203. use constant GDOME_DOCUMENT_TYPE_NODE    => 10;
  204. use constant GDOME_DOCUMENT_FRAG_NODE    => 11;
  205. use constant GDOME_NOTATION_NODE         => 12;
  206. use constant GDOME_HTML_DOCUMENT_NODE    => 13;
  207. use constant GDOME_DTD_NODE              => 14;
  208. use constant GDOME_ELEMENT_DECL          => 15;
  209. use constant GDOME_ATTRIBUTE_DECL        => 16;
  210. use constant GDOME_ENTITY_DECL           => 17;
  211. use constant GDOME_NAMESPACE_DECL        => 18;
  212. use constant GDOME_XINCLUDE_START        => 19;
  213. use constant GDOME_XINCLUDE_END          => 20;
  214.  
  215. 1;
  216. #-------------------------------------------------------------------------#
  217. __END__
  218.  
  219. =head1 NAME
  220.  
  221. XML::LibXML::Common - Routines and Constants common for XML::LibXML and XML::GDOME
  222.  
  223. =head1 SYNOPSIS
  224.  
  225.   use XML::LibXML::Common;
  226.  
  227. =head1 DESCRIPTION
  228.  
  229. XML::LibXML and XML::GDOME share some of the same functionality. This
  230. package should bundle some shared constansts and functions, so both
  231. modules may coexist within the same scripts.
  232.  
  233. XML::LibXML::Common defines all node types as constants. While
  234. XML::LibXML and XML::GDOME originally declared their own node type
  235. definitions, one may want to use XML::LibXML::Common in its
  236. compatibility mode:
  237.  
  238. =over 4
  239.  
  240. =item * use XML::LibXML::Common qw(:libxml);
  241.  
  242. :libxml will use the XML::LibXML Compatibility mode, which defines the
  243. old 'XML_' node-type definitions
  244.  
  245. =item * use XML::LibXML::Common qw(:gdome);
  246.  
  247. This allows one to use the XML::LibXML Compatibility mode, which
  248. defines the old 'GDOME_' node-type definitions
  249.  
  250. =item * use XML::LibXML::Common qw(:w3c);
  251.  
  252. This uses the nodetype definition names as specified for DOM.
  253.  
  254. =item * use XML::LibXML::Common qw(:encoding);
  255.  
  256. This is ment if only the encoding functions of XML::LibXML::Common
  257. should be used.
  258.  
  259. =back
  260.  
  261. By default the W3 definitions as defined in the DOM specifications and
  262. the encoding functions are exported by XML::LibXML::Common.
  263.  
  264. =head2 encoding functions
  265.  
  266. To encode or decode a string to or from UTF-8 XML::LibXML::Common exports
  267. two functions, which use the encoding mechanism of the underlaying
  268. implementation. These functions should be used, if external encoding
  269. is required (e.g. for queryfunctions).
  270.  
  271. =head2 encodeToUTF8
  272.  
  273.     $encodedstring = encodeToUTF8( $name_of_encoding, $sting_to_encode );
  274.  
  275. The function will encode a string from the specified encoding to UTF-8.
  276.  
  277. =head2 decodeFromUTF8
  278.  
  279.     $decodedstring = decodeFromUTF8($name_of_encoding, $string_to_decode );
  280.  
  281. This Function transforms an UTF-8 encoded string the specified
  282. encoding.  While transforms to ISO encodings may cause errors if the
  283. given stirng contains unsupported characters, both functions can
  284. transform to UTF-16 encodings as well.
  285.  
  286. Note that both encoding functions report their errors on the standard
  287. error. If an error occours the function will croak(). To catch the
  288. error information it is required to call the encoding function from
  289. within an eval block to avoid a script to stop.
  290.  
  291. =head1 AUTHOR
  292.  
  293. Christian Glahn, (christian.glahn@uibk.ac.at) Innsbruck University
  294.  
  295. =head1 COPYRIGHT
  296.  
  297. (c) 2002 Christian Glahn. All rights reserved. 
  298.  
  299. This program is free software; you can redistribute it and/or modify
  300. it under the same terms as Perl itself.
  301.  
  302. =head1 SEE ALSO
  303.  
  304. L<perl>, L<XML::LibXML>, L<XML::GDOME>
  305.  
  306. =cut
  307.