test debugging
[irspy-moved-to-github.git] / lib / ZOOM / XML / Simple.pm
1 # $Id: Simple.pm,v 1.2 2006-07-21 11:29:17 mike Exp $
2
3 package ZOOM::XML::Simple;
4
5 use 5.008;
6 use strict;
7 use warnings;
8
9 use XML::LibXML;
10
11
12 =head1 NAME
13
14 ZOOM::XML::Simple - read XML files into memory and play them out again
15
16 =head1 SYNOPSIS
17
18  $doc = ZOOM::XML::Simple::XMLin("foo.xml");
19  $doc->[0]->{beenRead} = 1;
20  print ZOOM::XML::Simple::XMLout($doc);
21
22 =head1 DESCRIPTION
23
24 Ever used the C<XML::Simple> module?  That's what I wanted.  Read its
25 manual for details, but basically it lets you read a document into a
26 nice, simple in-memory format, fiddle with it to your heart's content,
27 then render it back out again.  This is nice because the in-memory
28 format is so very much simpler than a DOM tree.
29
30 Unfortunately, it turns out that C<XML::Simple> messes with your data
31 too much to be used if your XML needs to conform to a fixed pattern,
32 such as a DTD or XML Schema.  Some of its damage can be prevented by
33 passing a hatful of attributes to its C<XMLin()> and C<XMLout()>
34 methods, but I've not found any way to prevent it from reordering the
35 subelements of each element into alphabetical order, which is of
36 course completely unacceptable in many cases.
37
38 For the IRSpy project's C<ZOOM::IRSpy::Record> module, I need
39 something like C<XML::Simple> to handle the ZeeRex records -- but it
40 has to keep elements in their original order.  Hence this module.
41 Because of its ordering requirement, it has to make a different
42 data-structure from the original.  It also implements only a tiny
43 subset of the full C<XML::Simple> functionality - the parts that I
44 need, natch.
45
46 =cut
47
48 # But will what I make actually be all that much simpler than DOM?
49 #
50 # For now, this effort is abandoned, and I am using DOM directly.
51
52 #use XML::Simple qw(:strict);
53 #my %attr = (KeyAttr => [], KeepRoot => 1);
54 #my $config = XMLin("foo.xml", %attr, ForceArray => 1, ForceContent => 1);
55 #print XMLout($config, %attr);
56
57
58 =head1 SEE ALSO
59
60 XML::Simple - the module that I hoped I'd be able to use, but wasn't
61 able to, hence my having had to write this one.
62
63 ZOOM::IRSpy::Record - the module I was writing that I wanted to use
64 XML::Simple for, and found that it wouldn't do.
65
66 The ZeeRex XML format is described at
67 http://explain.z3950.org/
68
69 =head1 AUTHOR
70
71 Mike Taylor, E<lt>mike@indexdata.comE<gt>
72
73 =head1 COPYRIGHT AND LICENSE
74
75 Copyright (C) 2006 by Index Data ApS.
76
77 This library is free software; you can redistribute it and/or modify
78 it under the same terms as Perl itself, either Perl version 5.8.7 or,
79 at your option, any later version of Perl 5 you may have available.
80
81 =cut
82
83 1;