.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.40) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Dumper 3pm" .TH Dumper 3pm "2020-12-28" "perl v5.32.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" XML::Dumper \- Perl module for dumping Perl objects from/to XML .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 3 \& # ===== Using an object \& use XML::Dumper; \& $dump = new XML::Dumper; \& \& $xml = $dump\->pl2xml( $perl ); \& $perl = $dump\->xml2pl( $xml ); \& $dump\->pl2xml( $perl, "my_perl_data.xml.gz" ); \& \& # ===== Using function calls \& use XML::Dumper; \& \& $xml = pl2xml( $perl ); \& $perl = xml2pl( $xml ); .Ve .SH "EXTENDED SYNOPSIS" .IX Header "EXTENDED SYNOPSIS" .Vb 2 \& use XML::Dumper; \& my $dump = new XML::Dumper; \& \& my $perl = \*(Aq\*(Aq; \& my $xml = \*(Aq\*(Aq; \& \& # ===== Convert Perl code to XML \& $perl = [ \& { \& fname => \*(AqFred\*(Aq, \& lname => \*(AqFlintstone\*(Aq, \& residence => \*(AqBedrock\*(Aq \& }, \& { \& fname => \*(AqBarney\*(Aq, \& lname => \*(AqRubble\*(Aq, \& residence => \*(AqBedrock\*(Aq \& } \& ]; \& $xml = $dump\->pl2xml( $perl ); \& \& # ===== Dump to a file \& my $file = "dump.xml"; \& $dump\->pl2xml( $perl, $file ); \& \& # ===== Convert XML to Perl code \& $xml = q| \& \& \& \& \& Fred \& Flintstone \& Bedrock \& \& \& \& \& Barney \& Rubble \& Bedrock \& \& \& \& \& |; \& \& my $perl = $dump\->xml2pl( $xml ); \& \& # ===== Convert an XML file to Perl code \& my $perl = $dump\->xml2pl( $file ); \& \& # ===== And serialize Perl code to an XML file \& $dump\->pl2xml( $perl, $file ); \& \& # ===== USE COMPRESSION \& $dump\->pl2xml( $perl, $file.".gz" ); \& \& # ===== INCLUDE AN IN\-DOCUMENT DTD \& $dump\->dtd; \& my $xml_with_dtd = $dump\->pl2xml( $perl ); \& \& # ===== USE EXTERNAL DTD \& $dump\->dtd( $file, $url ); \& my $xml_with_link_to_dtd = $dump\->pl2xml( $perl ); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" XML::Dumper dumps Perl data to \s-1XML\s0 format. XML::Dumper can also read \s-1XML\s0 data that was previously dumped by the module and convert it back to Perl. You can use the module read the \s-1XML\s0 from a file and write the \s-1XML\s0 to a file. Perl objects are blessed back to their original packaging; if the modules are installed on the system where the perl objects are reconstituted from xml, they will behave as expected. Intuitively, if the perl objects are converted and reconstituted in the same environment, all should be well. And it is. .PP Additionally, because \s-1XML\s0 benefits so nicely from compression, XML::Dumper understands gzipped \s-1XML\s0 files. It does so with an optional dependency on Compress::Zlib. So, if you dump a Perl variable with a file that has an extension of '.xml.gz', it will store and compress the file in gzipped format. Likewise, if you read a file with the extension '.xml.gz', it will uncompress the file in memory before parsing the \s-1XML\s0 back into a Perl variable. .PP Another fine challenge that this module rises to meet is that it understands circular definitions and multiple references to a single object. This includes doubly-linked lists, circular references, and the so-called 'Flyweight' pattern of Object Oriented programming. So it can take the gnarliest of your perl data, and should do just fine. .PP One caveat; XML::Dumper does not handle binary data. There have been discussions in the expat mailing list archives discussing the challenges associated with encoding binary data with \s-1XML. I\s0 chose the cowardly path of making the problem a non-issue by not addressing it. To store binary data, one could encode the data into \s-1ASCII\s0 before encapsulating the data as \s-1XML,\s0 and then reverse the process to restore the data. There are several Perl modules that one can use for this, Convert::UU, for example. .SS "\s-1FUNCTIONS AND METHODS\s0" .IX Subsection "FUNCTIONS AND METHODS" .IP "\(bu" 4 \&\fBnew()\fR \- XML::Dumper constructor. .Sp Creates a lean, mean, \s-1XML\s0 dumping machine. It's also completely at your disposal. .IP "\(bu" 4 dtd \- .Sp Generates a Document Type Dictionary for the 'perldata' data type. The default behaviour is to embed the \s-1DTD\s0 in the \s-1XML,\s0 thereby creating valid \s-1XML.\s0 Given a filename, the \s-1DTD\s0 will be written out to that file and the \s-1XML\s0 document for your Perl data will link to the file. Given a filename and an \s-1URL,\s0 the \s-1DTD\s0 will be written out the file and the \s-1XML\s0 document will link to the \s-1URL.\s0 XML::Dumper doesn't try really hard to determine where your \s-1DTD\s0's ought to go or relative paths or anything, so be careful with what arguments you supply this method, or just go with the default with the embedded \s-1DTD.\s0 Between \s-1DTD\s0's and Schemas, the potential for more free-form data to be imported and exported becomes feasible. .Sp Usage: .Sp .Vb 4 \& dtd(); # Causes XML to include embedded DTD \& dtd( $file ); # DTD saved to $file; XML will link to $file \& dtd( $file, $url ); # DTD saved to $file; XML will link to $url \& dtd( 0 ); # Prevents XML from including embedded DTD .Ve .IP "\(bu" 4 pl2xml( \f(CW$xml\fR, [ \f(CW$file\fR ] ) \- .Sp (Also \fBperl2xml()\fR, for those who enjoy readability over brevity). .Sp Converts Perl data to \s-1XML.\s0 If a second argument is given, then the Perl data will be stored to disk as \s-1XML,\s0 using the second argument as a filename. .Sp Usage: See Synopsis .IP "\(bu" 4 xml2pl( \f(CW$xml_or_filename\fR, [ \f(CW$callback\fR ] ) \- .Sp (Also \fBxml2perl()\fR, for those who enjoy readability over brevity.) .Sp Converts \s-1XML\s0 to a Perl datatype. If this method is given a second argument, XML::Dumper will use the second argument as a callback (if possible). If the first argument isn't \s-1XML\s0 and exists as a file, that file will be read and its contents will be used as the input \s-1XML.\s0 .Sp Currently, the only supported invocation of callbacks is through soft references. That is to say, the callback argument ought to be a string that matches the name of a callable method for your classes. If you have a congruent interface, this should work like a peach. If your class interface doesn't have such a named method, it won't be called. .IP "\(bu" 4 xml_compare( \f(CW$xml1\fR, \f(CW$xml2\fR ) \- Compares xml for content .Sp Compares two dumped Perl data structures (that is, compares the xml) for identity in content. Use this function rather than perl's built-in string comparison. This function will return true for any two perl data that are either deep clones of each other, or identical. This method is exported by default. .IP "\(bu" 4 xml_identity( \f(CW$xml1\fR, \f(CW$xml2\fR ) \- Compares xml for identity .Sp Compares two dumped Perl data structures (that is, compares the xml) for identity in instantiation. This function will return true for any two perl data that are identical, but not for deep clones of each other. This method is also exported by default. .SH "EXPORTS" .IX Header "EXPORTS" By default, the following methods are exported: .PP .Vb 1 \& xml2pl, pl2xml, xml_compare, xml_identity .Ve .SH "BUGS AND DEPENDENCIES" .IX Header "BUGS AND DEPENDENCIES" XML::Dumper has changed \s-1API\s0 since 0.4, as a response to a bug report from PerlMonks. I felt it was necessary, as the functions simply didn't work as advertised. That is, xml2pl really didnt accept xml as an argument; what it wanted was an \s-1XML\s0 Parse tree. To correct for the \&\s-1API\s0 change, simply don't parse the \s-1XML\s0 before feeding it to XML::Dumper. .PP XML::Dumper also has no understanding of typeglobs (references or not), references to regular expressions, or references to Perl subroutines. Turns out that Data::Dumper doesn't do references to Perl subroutines, either, so at least I'm in somewhat good company. .PP XML::Dumper requires one perl module, available from \s-1CPAN\s0 .PP .Vb 1 \& XML::Parser .Ve .PP XML::Parser itself relies on Clark Cooper's Expat implementation in Perl, which in turn requires James Clark's expat package itself. See the documentation for XML::Parser for more information. .SH "REVISIONS AND CREDITS" .IX Header "REVISIONS AND CREDITS" The list of credits got so long that I had to move it to the Changes file. Thanks to all those who've contributed with bug reports and suggested features! Keep 'em coming! .PP I've had ownership of the module since June of 2002, and very much appreciate requests on how to make the module better. It has served me well, both as a learning tool on how I can repay my debt to the Perl Community, and as a practical module that is useful. I'm thrilled to be able to offer this bit of code. So, if you have suggestions, bug reports, or feature requests, please let me know and I'll do my best to make this a better module. .SH "CURRENT MAINTAINER" .IX Header "CURRENT MAINTAINER" Mike Wong .PP XML::Dumper is free software. You can redistribute it and/or modify it under the same terms as Perl itself. .SH "ORIGINAL AUTHOR" .IX Header "ORIGINAL AUTHOR" Jonathan Eisenzopf .SH "SEE ALSO" .IX Header "SEE ALSO" \&\fBperl\fR\|(1) \&\fBCompress::Zlib\fR\|(3) \&\fBXML::Parser\fR\|(3) \&\fBData::DumpXML\fR\|(3)