r2553 - in packages: . libxml-mini-perl libxml-mini-perl/branches
libxml-mini-perl/branches/upstream
libxml-mini-perl/branches/upstream/current
libxml-mini-perl/branches/upstream/current/lib
libxml-mini-perl/branches/upstream/current/lib/XML
libxml-mini-perl/branches/upstream/current/lib/XML/Mini
libxml-mini-perl/branches/upstream/current/lib/XML/Mini/Element
libxml-mini-perl/branches/upstream/current/t
libxml-mini-perl/branches/upstream/current/t/sample
Raphaël Hertzog
hertzog at costa.debian.org
Thu Apr 13 21:19:07 UTC 2006
Author: hertzog
Date: 2006-04-13 21:19:04 +0000 (Thu, 13 Apr 2006)
New Revision: 2553
Added:
packages/libxml-mini-perl/
packages/libxml-mini-perl/branches/
packages/libxml-mini-perl/branches/upstream/
packages/libxml-mini-perl/branches/upstream/current/
packages/libxml-mini-perl/branches/upstream/current/Changes
packages/libxml-mini-perl/branches/upstream/current/INSTALL
packages/libxml-mini-perl/branches/upstream/current/LICENSE
packages/libxml-mini-perl/branches/upstream/current/MANIFEST
packages/libxml-mini-perl/branches/upstream/current/Makefile.PL
packages/libxml-mini-perl/branches/upstream/current/README
packages/libxml-mini-perl/branches/upstream/current/lib/
packages/libxml-mini-perl/branches/upstream/current/lib/XML/
packages/libxml-mini-perl/branches/upstream/current/lib/XML/Mini.pm
packages/libxml-mini-perl/branches/upstream/current/lib/XML/Mini/
packages/libxml-mini-perl/branches/upstream/current/lib/XML/Mini/Document.pm
packages/libxml-mini-perl/branches/upstream/current/lib/XML/Mini/Element.pm
packages/libxml-mini-perl/branches/upstream/current/lib/XML/Mini/Element/
packages/libxml-mini-perl/branches/upstream/current/lib/XML/Mini/Element/CData.pm
packages/libxml-mini-perl/branches/upstream/current/lib/XML/Mini/Element/Comment.pm
packages/libxml-mini-perl/branches/upstream/current/lib/XML/Mini/Element/DocType.pm
packages/libxml-mini-perl/branches/upstream/current/lib/XML/Mini/Element/Entity.pm
packages/libxml-mini-perl/branches/upstream/current/lib/XML/Mini/Element/Header.pm
packages/libxml-mini-perl/branches/upstream/current/lib/XML/Mini/Node.pm
packages/libxml-mini-perl/branches/upstream/current/lib/XML/Mini/TreeComponent.pm
packages/libxml-mini-perl/branches/upstream/current/t/
packages/libxml-mini-perl/branches/upstream/current/t/01parseable.t
packages/libxml-mini-perl/branches/upstream/current/t/02parsexml.t
packages/libxml-mini-perl/branches/upstream/current/t/03genxml.t
packages/libxml-mini-perl/branches/upstream/current/t/04crossnested.t
packages/libxml-mini-perl/branches/upstream/current/t/05parsefunc.t
packages/libxml-mini-perl/branches/upstream/current/t/06getelem.t
packages/libxml-mini-perl/branches/upstream/current/t/07ToFromHash.t
packages/libxml-mini-perl/branches/upstream/current/t/sample/
packages/libxml-mini-perl/branches/upstream/current/t/sample/vocpboxes.xml
packages/libxml-mini-perl/branches/upstream/current/t/sample/xnested.xml
packages/libxml-mini-perl/tags/
Log:
[svn-inject] Installing original source of libxml-mini-perl
Added: packages/libxml-mini-perl/branches/upstream/current/Changes
===================================================================
--- packages/libxml-mini-perl/branches/upstream/current/Changes 2006-04-13 21:15:52 UTC (rev 2552)
+++ packages/libxml-mini-perl/branches/upstream/current/Changes 2006-04-13 21:19:04 UTC (rev 2553)
@@ -0,0 +1,57 @@
+Revision history for Perl extension XML::Mini
+
+XML-Mini-1.28, 2003.03.31
+-------------------------
+- New XML::Mini::Document methods, toHash() and fromHash(), allow for wickedly easy XML generation and manipulation.
+See the XML::Mini::Document::fromHash() and XML::Mini::Document::toHash() pod for details.
+
+- Bug in the parsing algorithm when dealing with multiple elements of the same name, some of which have sub-elements, eg
+
+ <a />
+ <a />
+ <a> <b>...</b> </a>
+ <a />
+
+ Now fixed.
+
+XML-Mini-1.27, 2003.02.01
+-------------------------
+- Problem for users of Perl < 5.8.0 - The module was coded as if Text::Balanced was optional but was 'use'ing it and failing the make test.
+- Made some changes to the parameters for getElement() and getElementByPath(), adding optional positions in order to allow extraction of the nth matching element instead of only the 1st.
+
+
+XML-Mini-1.26, 2003.01.27
+-------------------------
+- Big bug found when using Text::Balanced (problem in parsing <tag>...</tag> whenever ... contains
+something like <unary /> tags or anything but <tag>..</tag> and text). Fixed and tests adjusted.
+
+XML-Mini-1.25, 2003.01.26
+-------------------------
+- Major changes to the parsing algorithm which, if Text::Balanced is available, allow "cross-nested" tags
+ (such as <a><b><a>..</a></b></a>) to be parsed successfully.
+- <? tags ?> are now represented as XML::Mini::Element::Header elements
+- Added the XML::Mini::Document::header() method to create the new XML::Mini::Element::Header elements
+ which represent <? tags ?>.
+- Added the XML::Mini::Document::parse() method which accepts strings, filenames, open file handles and
+ opened FileHandle objects
+- Currently beta-testing an XML::Mini replacement parser for the RPC::XML package
+
+XML-Mini-1.24, 2002.12.16
+-------------------------
+- Included Nigel Wetters (rivalsdm.com) changes/bug fixes to XML::Mini
+ in order to make it more compatible with older Perl installs
+- Fixes to getElement (inability to fetch nested tags of same name)
+- Added the ability to removeChild() and removeAllChildren() for Element objects
+- Added the ability to prependChild() and insertChild(CHILD, INDEX)
+
+XML-Mini-1.24, 2002.11.25
+-------------------------
+- Made compatible with early Perls.
+- test added to check whether modules parse correctly
+- some rearrangement of PODs
+
+
+XML-Mini-1.2, 2002.09.15
+-------------------------
+- Perl implementation of MiniXML API finalised and Makefile.PL created
+
Added: packages/libxml-mini-perl/branches/upstream/current/INSTALL
===================================================================
--- packages/libxml-mini-perl/branches/upstream/current/INSTALL 2006-04-13 21:15:52 UTC (rev 2552)
+++ packages/libxml-mini-perl/branches/upstream/current/INSTALL 2006-04-13 21:19:04 UTC (rev 2553)
@@ -0,0 +1,43 @@
+#!/bin/sh
+
+# XML::Mini
+#
+# XML::Mini perl extension, XML parser/generator package.
+# Copyright (C) 2002-2003 Patrick Deegan, Psychogenic INC
+# All rights reserved
+# http://minixml.psychogenic.com
+#
+# See the LICENSE file for details on terms/conditions of use.
+#
+
+# Installation. The usual procedure will function nicely :
+
+perl Makefile.PL
+make
+make test
+make install
+
+#
+# but note that, since XML::Mini is 100% perl, you could probably just:
+#
+# - Select a location and create an XML directory:
+#
+# $ mkdir /path/to/install/XML
+#
+# - Move the modules to the install location
+#
+# $ mv Mini Mini.pm /path/to/install/XML
+#
+# - Then specify the location of the library in your code
+#
+# #!/usr/bin/perl
+#
+# use lib '/path/to/install';
+# use XML::Mini;
+#
+# # ...
+#
+#
+# Regards,
+# Pat Deegan
+#
Property changes on: packages/libxml-mini-perl/branches/upstream/current/INSTALL
___________________________________________________________________
Name: svn:executable
+
Added: packages/libxml-mini-perl/branches/upstream/current/LICENSE
===================================================================
--- packages/libxml-mini-perl/branches/upstream/current/LICENSE 2006-04-13 21:15:52 UTC (rev 2552)
+++ packages/libxml-mini-perl/branches/upstream/current/LICENSE 2006-04-13 21:19:04 UTC (rev 2553)
@@ -0,0 +1,350 @@
+This license is included in, and applies to, the MiniXML package, including all
+elements of both the PHP version and the XML::Mini perl extension, which are
+Copyright (C) 2002-2003 Patrick Deegan, Psychogenic Inc.
+All rights reserved.
+
+Programs that use this code are bound to these terms and conditions - if you wish
+to include these modules in non-GPL code, you need prior written authorisation from
+the authors.
+
+
+ GNU GENERAL PUBLIC LICENSE
+ Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
+ 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users. This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it. (Some other Free Software Foundation software is covered by
+the GNU Library General Public License instead.) You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+ To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have. You must make sure that they, too, receive or can get the
+source code. And you must show them these terms so they know their
+rights.
+
+ We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+ Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software. If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+ Finally, any free program is threatened constantly by software
+patents. We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary. To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ GNU GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License. The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language. (Hereinafter, translation is included without limitation in
+the term "modification".) Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+ 1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+ 2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) You must cause the modified files to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ b) You must cause any work that you distribute or publish, that in
+ whole or in part contains or is derived from the Program or any
+ part thereof, to be licensed as a whole at no charge to all third
+ parties under the terms of this License.
+
+ c) If the modified program normally reads commands interactively
+ when run, you must cause it, when started running for such
+ interactive use in the most ordinary way, to print or display an
+ announcement including an appropriate copyright notice and a
+ notice that there is no warranty (or else, saying that you provide
+ a warranty) and that users may redistribute the program under
+ these conditions, and telling the user how to view a copy of this
+ License. (Exception: if the Program itself is interactive but
+ does not normally print such an announcement, your work based on
+ the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+ a) Accompany it with the complete corresponding machine-readable
+ source code, which must be distributed under the terms of Sections
+ 1 and 2 above on a medium customarily used for software interchange; or,
+
+ b) Accompany it with a written offer, valid for at least three
+ years, to give any third party, for a charge no more than your
+ cost of physically performing source distribution, a complete
+ machine-readable copy of the corresponding source code, to be
+ distributed under the terms of Sections 1 and 2 above on a medium
+ customarily used for software interchange; or,
+
+ c) Accompany it with the information you received as to the offer
+ to distribute corresponding source code. (This alternative is
+ allowed only for noncommercial distribution and only if you
+ received the program in object code or executable form with such
+ an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it. For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable. However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License. Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+ 5. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Program or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+ 6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+ 7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all. For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded. In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+ 9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation. If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+ 10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission. For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this. Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+ NO WARRANTY
+
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) 19yy <name of author>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+ Gnomovision version 69, Copyright (C) 19yy name of author
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+ <signature of Ty Coon>, 1 April 1989
+ Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs. If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library. If this is what you want to do, use the GNU Library General
+Public License instead of this License.
Added: packages/libxml-mini-perl/branches/upstream/current/MANIFEST
===================================================================
--- packages/libxml-mini-perl/branches/upstream/current/MANIFEST 2006-04-13 21:15:52 UTC (rev 2552)
+++ packages/libxml-mini-perl/branches/upstream/current/MANIFEST 2006-04-13 21:19:04 UTC (rev 2553)
@@ -0,0 +1,25 @@
+Changes
+INSTALL
+lib/XML/Mini/Document.pm
+lib/XML/Mini/TreeComponent.pm
+lib/XML/Mini/Node.pm
+lib/XML/Mini/Element.pm
+lib/XML/Mini/Element/Comment.pm
+lib/XML/Mini/Element/Entity.pm
+lib/XML/Mini/Element/CData.pm
+lib/XML/Mini/Element/DocType.pm
+lib/XML/Mini/Element/Header.pm
+lib/XML/Mini.pm
+Makefile.PL
+MANIFEST
+README
+t/01parseable.t
+t/sample/vocpboxes.xml
+t/sample/xnested.xml
+t/02parsexml.t
+t/03genxml.t
+t/04crossnested.t
+t/05parsefunc.t
+t/06getelem.t
+t/07ToFromHash.t
+LICENSE
Added: packages/libxml-mini-perl/branches/upstream/current/Makefile.PL
===================================================================
--- packages/libxml-mini-perl/branches/upstream/current/Makefile.PL 2006-04-13 21:15:52 UTC (rev 2552)
+++ packages/libxml-mini-perl/branches/upstream/current/Makefile.PL 2006-04-13 21:19:04 UTC (rev 2553)
@@ -0,0 +1,15 @@
+use ExtUtils::MakeMaker;
+use strict;
+$^W = 1;
+
+my $PACKAGE = 'XML::Mini';
+(my $PACKAGE_FILE = $PACKAGE) =~ s|::|/|g;
+
+WriteMakefile(
+ NAME => $PACKAGE,
+ VERSION_FROM => "lib/$PACKAGE_FILE.pm", # finds $VERSION
+ PREREQ_PM => {
+ 'FileHandle' => 2.0,
+ 'Data::Dumper' => 2.1
+ }
+ );
Added: packages/libxml-mini-perl/branches/upstream/current/README
===================================================================
--- packages/libxml-mini-perl/branches/upstream/current/README 2006-04-13 21:15:52 UTC (rev 2552)
+++ packages/libxml-mini-perl/branches/upstream/current/README 2006-04-13 21:19:04 UTC (rev 2553)
@@ -0,0 +1,187 @@
+
+XML::Mini Perl Module - Homepage and latest version:
+
+ http://minixml.psychogenic.com
+
+INSTALLATION:
+
+3 Methods are available:
+
+- CPAN
+ # perl -MCPAN -e 'install XML::Mini'
+
+- Local
+ perl Makefile.PL
+ make
+ make test
+ su ; make install
+
+- Simple (no need for root priv)
+
+ Since XML::Mini is a pure Perl implementation, you can simply
+ tar zxvf XML-Mini-XXX.tar.gz
+ mv lib/XML /path/to/destination
+
+ and then, in your code, use:
+
+ #!/usr/bin/perl
+ use lib '/path/to/destination';
+ use XML::Mini::Document;
+
+ # ... create and parse XML!
+
+
+
+NAME
+ XML::Mini - Stand-alone, pure Perl implementation of the MiniXML
+ XML generator and parser interface (http://minixml.psychogenic.com).
+
+SYNOPSIS
+ use XML::Mini::Document;
+
+ ############# Generate XML ###############
+
+ # Create a new XML::Mini::Document
+
+ my $newDoc = XML::Mini::Document->new();
+
+ # Creating XML can be done easily by using a hash ref:
+ my $h = {
+ 'spy' => {
+ 'id' => '007',
+ 'type' => 'SuperSpy',
+ 'name' => 'James Bond',
+ 'email' => 'mi5 at london.uk',
+ 'address' => 'Wherever he is needed most',
+ },
+ };
+
+ $newDoc->fromHash($h);
+
+ # output the XML
+ print $newDoc->toString();
+
+
+ # Or new XML can also be created by manipulating
+ # elements directly:
+
+ my $newDocRoot = $newDoc->getRoot();
+
+ # create the <? xml ?> header
+ my $xmlHeader = $newDocRoot->header('xml');
+ # add the version
+ $xmlHeader->attribute('version', '1.0');
+
+ my $person = $newDocRoot->createChild('person');
+
+ my $name = $person->createChild('name');
+ $name->createChild('first')->text('John');
+ $name->createChild('last')->text('Doe');
+
+ my $eyes = $person->createChild('eyes');
+ $eyes->attribute('color', 'blue');
+ $eyes->attribute('number', 2);
+
+ # output the document
+ print $newDoc->toString();
+ # ...
+
+ ############# Parse XML ###############
+ # Parse existing XML string
+ my $xmlDoc = XML::Mini::Document->new();
+
+ $xmlDoc->parse($XMLString);
+ # or
+ $xmlDoc->parse('/path/to/file.xml');
+ # or
+ $xmlDoc->parse(*INPUTFILEHANDLE);
+
+ # Now we can fetch elements:
+
+ my $part = $xmlDoc->getElementByPath('partsRateReply/part');
+
+ my $partId = $part->attribute('id');
+
+ my $price = $partList->getElement('price');
+
+ print "Part $partId costs: " . $price->getValue() . "\n";
+
+DESCRIPTION
+ XML::Mini is a set of Perl (and PHP) classes that allow you to access
+ XML data and create valid XML output with a tree-based hierarchy of
+ elements.
+
+ It provides an easy, object-oriented interface for manipulating XML
+ documents and their elements. It is currently being used to send
+ requests and understand responses from remote servers in Perl or PHP
+ applications.
+
+ XML::Mini does not require any external libraries or modules.
+
+ The XML::Mini.pm module includes a number of variable you may use to
+ tweak XML::Mini's behavior. These include:
+
+ $XML::Mini::AutoEscapeEntities - when greater than 0, the values set for
+ nodes are automatically escaped, thus $element->text('4 is > 3') will
+ set the contents of the appended node to '4 is > 3'. Default setting
+ is 1.
+
+ $XML::Mini::IgnoreWhitespaces - when greater than 0, extraneous
+ whitespaces will be ignored (maily useful when parsing). Thus <mytag>
+ Hello There </mytag> will be parsed as containing a text node with
+ contents 'Hello There' instead of ' Hello There '. Default setting is 1.
+
+ $XML::Mini::CaseSensitive - when greater than 0, element names are
+ treated as case sensitive. Thus, $element->getElement('subelement') and
+ $element->getElement('SubElement') will be equivalent. Defaults to 0.
+
+Class methods
+ escapeEntites TOENCODE
+
+ This method returns ToENCODE with HTML sensitive values (eg '<', '>',
+ '"', etc) HTML encoded.
+
+ Log MESSAGE
+
+ Logs the message to STDERR
+
+ Error MESSAGE
+
+ Logs MESSAGE and exits the program, calling exit()
+
+AUTHOR
+
+Programs that use this code are bound to the terms and conditions of the GNU GPL (see the LICENSE file).
+If you wish to include these modules in non-GPL code, you need prior written authorisation
+from the authors.
+
+ LICENSE
+
+ XML::Mini module, part of the XML::Mini XML parser/generator package.
+ Copyright (C) 2002, 2003 Patrick Deegan, Psychogenic.com
+ All rights reserved
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+ Official XML::Mini site: http://minixml.psychogenic.com
+
+ Contact page for author available at
+ http://www.psychogenic.com/
+
+SEE ALSO
+ XML::Mini::Document, XML::Mini::Element
+
+ http://minixml.psychogenic.com
+
Added: packages/libxml-mini-perl/branches/upstream/current/lib/XML/Mini/Document.pm
===================================================================
--- packages/libxml-mini-perl/branches/upstream/current/lib/XML/Mini/Document.pm 2006-04-13 21:15:52 UTC (rev 2552)
+++ packages/libxml-mini-perl/branches/upstream/current/lib/XML/Mini/Document.pm 2006-04-13 21:19:04 UTC (rev 2553)
@@ -0,0 +1,1341 @@
+package XML::Mini::Document;
+use strict;
+$^W = 1;
+
+use FileHandle;
+
+use XML::Mini;
+use XML::Mini::Element;
+use XML::Mini::Element::Comment;
+use XML::Mini::Element::Header;
+use XML::Mini::Element::CData;
+use XML::Mini::Element::DocType;
+use XML::Mini::Element::Entity;
+use XML::Mini::Node;
+
+use vars qw ( $VERSION
+ $TextBalancedAvailable
+ );
+
+eval "use Text::Balanced qw(extract_tagged)";
+if ($@)
+{
+ $TextBalancedAvailable = 0;
+} else {
+ $TextBalancedAvailable = 1;
+}
+
+
+$VERSION = '1.28';
+
+sub new
+{
+ my $class = shift;
+ my $string = shift;
+
+ my $self = {};
+ bless $self, ref $class || $class;
+
+ $self->init();
+
+ if (defined $string)
+ {
+ $self->fromString($string);
+ }
+
+ return $self;
+}
+
+sub init {
+ my $self = shift;
+ delete $self->{'_xmlDoc'};
+
+ $self->{'_xmlDoc'} = XML::Mini::Element->new("PSYCHOGENIC_ROOT_ELEMENT");
+}
+
+
+sub getRoot
+{
+ my $self = shift;
+ return $self->{'_xmlDoc'};
+}
+
+sub setRoot
+{
+ my $self = shift;
+ my $root = shift;
+
+ return XML::Mini->Error("XML::Mini::Document::setRoot(): Trying to set non-XML::Mini::Element as root")
+ unless ($self->isElement($root));
+
+ $self->{'_xmlDoc'} = $root;
+}
+
+sub isElement
+{
+ my $self = shift;
+ my $element = shift || return undef;
+
+ my $type = ref $element;
+
+ return undef unless $type;
+
+ return 0 unless ($type =~ /^XML::Mini::Element/);
+
+ return 1;
+}
+
+sub isNode
+{
+ my $self = shift;
+ my $element = shift || return undef;
+
+ my $type = ref $element;
+
+ return undef unless $type;
+
+ return 0 unless ($type =~ /^XML::Mini::Node/);
+
+ return 1;
+}
+
+sub createElement
+{
+ my $self = shift;
+ my $name = shift;
+ my $value = shift; # optional
+
+ my $newElement = XML::Mini::Element->new($name);
+
+ return XML::Mini->Error("Could not create new element named '$name'")
+ unless ($newElement);
+
+ if (defined $value)
+ {
+ $newElement->text($value);
+ }
+
+ return $newElement;
+}
+
+sub getElementByPath
+{
+ my $self = shift;
+ my $path = shift;
+ my @elementNumbers = @_;
+
+ my $element = $self->{'_xmlDoc'}->getElementByPath($path, @elementNumbers);
+ if ($XML::Mini::Debug)
+ {
+ if ($element)
+ {
+ XML::Mini->Log("XML::Mini::Document::getElementByPath(): element at $path found.");
+ } else {
+ XML::Mini->Log("XML::Mini::Document::getElement(): element at $path NOT found.");
+ }
+ }
+
+ return $element;
+}
+
+sub getElement
+{
+ my $self = shift;
+ my $name = shift;
+ my $elementNumber = shift; # optionally get only the ith element
+
+ my $element = $self->{'_xmlDoc'}->getElement($name, $elementNumber);
+
+ if ($XML::Mini::Debug)
+ {
+ if ($element)
+ {
+ XML::Mini->Log("XML::Mini::Document::getElement(): element named $name found.");
+ } else {
+ XML::Mini->Log("XML::Mini::Document::getElement(): element named $name NOT found.");
+ }
+ }
+
+ return $element;
+}
+
+sub fromString
+{
+ my $self = shift;
+ my $string = shift;
+
+ $self->fromSubString($self->{'_xmlDoc'}, $string);
+
+ return $self->{'_xmlDoc'}->numChildren();
+}
+
+sub fromFile
+{
+ my $self = shift;
+ my $filename = shift;
+
+ my $fRef = \$filename;
+ my $contents;
+ if (ref($filename) && UNIVERSAL::isa($filename, 'IO::Handle'))
+ {
+ $contents = join("", $filename->getlines());
+ $filename->close();
+
+ } elsif (ref $fRef eq 'GLOB') {
+
+ $contents = join('', $fRef->getlines());
+ $fRef->close();
+
+ } elsif (ref $fRef eq 'SCALAR') {
+
+ return XML::Mini->Error("XML::Mini::Document::fromFile() Can't find file $filename")
+ unless (-e $filename);
+
+
+ return XML::Mini->Error("XML::Mini::Document::fromFile() Can't read file $filename")
+ unless (-r $filename);
+
+ my $infile = FileHandle->new();
+ $infile->open( "<$filename")
+ || return XML::Mini->Error("XML::Mini::Document::fromFile() Could not open $filename for read: $!");
+ $contents = join("", $infile->getlines());
+ $infile->close();
+ }
+
+ return $self->fromString($contents);
+}
+
+sub parse
+{
+ my $self = shift;
+ my $input = shift;
+
+ my $inRef = \$input;
+ my $type = ref($inRef);
+
+ if ($type eq 'SCALAR' && $input =~ m|<[^>]+>|sm)
+ {
+ # we have some XML
+ return $self->fromString($input);
+
+ } else {
+ # hope it's a file name or handle
+ return $self->fromFile($input);
+ }
+
+}
+
+
+sub fromHash {
+ my $self = shift;
+ my $href = shift || return XML::Mini->Error("XML::Mini::Document::fromHash - must pass a hash reference");
+ my $params = shift || {};
+
+ $self->init();
+
+ if ($params->{'attributes'})
+ {
+ my %attribs;
+ while (my ($attribName, $value) = each %{$params->{'attributes'}})
+ {
+ my $vType = ref $value || "";
+ if ($vType)
+ {
+ if ($vType eq 'ARRAY')
+ {
+ foreach my $v (@{$value})
+ {
+ $attribs{$attribName}->{$v}++;
+ }
+
+ }
+ } else {
+ $attribs{$attribName}->{$value}++;
+ }
+ }
+
+ $params->{'attributes'} = \%attribs;
+ }
+
+
+
+ while (my ($keyname, $value) = each %{$href})
+ {
+
+ my $sub = $self->_fromHash_getExtractSub(ref $value);
+
+ $self->$sub($keyname, $value, $self->{'_xmlDoc'}, $params);
+
+ }
+
+ return $self->{'_xmlDoc'}->numChildren();
+
+}
+
+sub _fromHash_getExtractSub {
+ my $self = shift;
+ my $valType = shift || 'STRING';
+
+ my $sub = "_fromHash_extract$valType";
+
+ return XML::Mini->Error("XML::Mini::Document::fromHash Don't know how to interpret '$valType' values")
+ unless ($self->can($sub));
+
+ return $sub;
+
+}
+
+
+sub _fromHash_extractHASH {
+ my $self = shift;
+ my $name = shift;
+ my $value = shift || return XML::Mini->Error("XML::Mini::Document::extractHASHref No value passed!");
+ my $parent = shift || return XML::Mini->Error("XML::Mini::Document::extractHASHref No parent element passed!");
+ my $params = shift || {};
+
+ return XML::Mini->Error("XML::Mini::Document::extractHASHref No element name passed!")
+ unless (defined $name);
+
+
+ my $thisElement = $parent->createChild($name);
+
+ while (my ($key, $val) = each %{$value})
+ {
+
+
+ my $sub = $self->_fromHash_getExtractSub(ref $val);
+
+ $self->$sub($key, $val, $thisElement, $params);
+
+ }
+
+ return ;
+}
+
+sub _fromHash_extractARRAY {
+ my $self = shift;
+ my $name = shift;
+ my $values = shift || return XML::Mini->Error("XML::Mini::Document::extractARRAYref No value passed!");
+ my $parent = shift || return XML::Mini->Error("XML::Mini::Document::extractARRAYref No parent element passed!");
+ my $params = shift || {};
+
+ return XML::Mini->Error("XML::Mini::Document::extractARRAYref No element name passed!")
+ unless (defined $name);
+
+ # every element in an array ref is a child element of the parent
+ foreach my $val (@{$values})
+ {
+ my $valRef = ref $val;
+
+ if ($valRef)
+ {
+ # this is a complex element
+ #my $childElement = $parent->createChild($name);
+
+ # process sub elements
+ my $sub = $self->_fromHash_getExtractSub($valRef);
+
+ $self->$sub($name, $val, $parent, $params);
+
+ } else {
+ # simple string
+ $self->_fromHash_extractSTRING($name, $val, $parent, $params);
+
+
+ }
+
+ }
+
+ return;
+
+}
+
+sub _fromHash_extractSTRING {
+ my $self = shift;
+ my $name = shift;
+ my $val = shift ;
+ my $parent = shift || return XML::Mini->Error("XML::Mini::Document::extractSTRING No parent element passed!");
+ my $params = shift || {};
+
+ return XML::Mini->Error("XML::Mini::Document::extractSTRING No element name passed!")
+ unless (defined $name);
+
+
+ return XML::Mini->Error("XML::Mini::Document::extractSTRING No value passed!")
+ unless (defined $val);
+
+ my $pname = $parent->name();
+
+ if ($params->{'attributes'}->{$pname}->{$name} || $params->{'attributes'}->{'-all'}->{$name})
+ {
+ $parent->attribute($name, $val);
+ } elsif ($name eq '-content') {
+
+ $parent->text($val);
+
+ } else {
+ $parent->createChild($name, $val);
+ }
+
+ return ;
+
+
+}
+
+
+
+sub toHash {
+ my $self = shift;
+
+ my $retVal = $self->{'_xmlDoc'}->toStructure();
+
+ my $type = ref $retVal;
+
+ if ($type && $type eq 'HASH')
+ {
+ return $retVal;
+ }
+
+ my $retHash = {
+ '-content' => $retVal,
+ };
+
+ return $retHash;
+
+}
+
+
+
+sub toString
+{
+ my $self = shift;
+ my $depth = shift || 0;
+
+ my $retString = $self->{'_xmlDoc'}->toString($depth);
+
+ $retString =~ s/<\/PSYCHOGENIC_ROOT_ELEMENT>//smi;
+ $retString =~ s/<PSYCHOGENIC_ROOT_ELEMENT([^>]*)?>\s*//smi;
+
+
+ return $retString;
+}
+
+sub fromSubStringBT {
+ my $self = shift;
+ my $parentElement = shift;
+ my $XMLString = shift;
+ my $useIgnore = shift;
+
+ if ($XML::Mini::Debug)
+ {
+ XML::Mini->Log("Called fromSubStringBT() with parent '" . $parentElement->name() . "'\n");
+ }
+
+ my @res;
+ if ($useIgnore)
+ {
+ my $ignore = [ '<\s*[^\s>]+[^>]*\/\s*>', # <unary \/>
+ '<\?\s*[^\s>]+\s*[^>]*\?>', # <? headers ?>
+ '<!--.+?-->', # <!-- comments -->
+ '<!\[CDATA\s*\[.*?\]\]\s*>\s*', # CDATA
+ '<!DOCTYPE\s*([^\[]*)\[(.*?)\]\s*>', # DOCTYPE
+ '<!ENTITY\s*[^>]+>'
+ ];
+
+ @res = Text::Balanced::extract_tagged($XMLString, undef, undef, undef, { 'ignore' => $ignore });
+ } else {
+ @res = Text::Balanced::extract_tagged($XMLString);
+ }
+
+ if ($#res == 5)
+ {
+ # We've extracted a balanced <tag>..</tag>
+
+ my $extracted = $res[0]; # the entire <t>..</t>
+ my $remainder = $res[1]; # stuff after the <t>..</t>HERE - 3
+ my $prefix = $res[3]; # the <t ...> itself - 1
+ my $contents = $res[4]; # the '..' between <t>..</t> - 2
+ my $suffix = $res[5]; # the </t>
+
+ #XML::Mini->Log("Grabbed prefix '$prefix'...");
+ my $newElement;
+
+ if ($prefix =~ m|<\s*([^\s>]+)\s*([^>]*)>|)
+ {
+ my $name = $1;
+ my $attribs = $2;
+ $newElement = $parentElement->createChild($name);
+ $self->_extractAttributesFromString($newElement, $attribs) if ($attribs);
+
+ $self->fromSubStringBT($newElement, $contents) if ($contents =~ m|\S|);
+
+ $self->fromSubStringBT($parentElement, $remainder) if ($remainder =~ m|\S|);
+ } else {
+
+ XML::Mini->Log("XML::Mini::Document::fromSubStringBT extracted balanced text from invalid tag '$prefix' - ignoring");
+ }
+ } else {
+
+ $XMLString =~ s/>\s*\n/>/gsm;
+ if ($XMLString =~ m/^\s*<\s*([^\s>]+)([^>]*>).*<\s*\/\1\s*>/osm)
+ {
+ # starts with a normal <tag> ... </tag> but has some ?? in it
+
+ my $startTag = $2;
+ return $self->fromSubStringBT($parentElement, $XMLString, 'USEIGNORE')
+ unless ($startTag =~ m|/\s*>$|);
+ }
+
+ # not a <tag>...</tag>
+ #it's either a
+ if ($XMLString =~ m/^\s*(<\s*([^\s>]+)([^>]+)\/\s*>| # <unary \/>
+ <\?\s*([^\s>]+)\s*([^>]*)\?>| # <? headers ?>
+ <!--(.+?)-->| # <!-- comments -->
+ <!\[CDATA\s*\[(.*?)\]\]\s*>\s*| # CDATA
+ <!DOCTYPE\s*([^\[]*)\[(.*?)\]\s*>\s*| # DOCTYPE
+ <!ENTITY\s*([^"'>]+)\s*(["'])([^\11]+)\11\s*>\s*| # ENTITY
+ ([^<]+))(.*)/xogsmi) # plain text
+ {
+ my $firstPart = $1;
+ my $unaryName = $2;
+ my $unaryAttribs = $3;
+ my $headerName = $4;
+ my $headerAttribs= $5;
+ my $comment = $6;
+ my $cdata = $7;
+ my $doctype = $8;
+ my $doctypeCont = $9;
+ my $entityName = $10;
+ my $entityCont = $12;
+ my $plainText = $13;
+ my $remainder = $14;
+
+ # There is some duplication here that should be merged with that in fromSubString()
+ if ($unaryName)
+ {
+ my $newElement = $parentElement->createChild($unaryName);
+ $self->_extractAttributesFromString($newElement, $unaryAttribs) if ($unaryAttribs);
+ } elsif ($headerName)
+ {
+ my $newElement = XML::Mini::Element::Header->new($headerName);
+ $self->_extractAttributesFromString($newElement, $headerAttribs) if ($headerAttribs);
+ $parentElement->appendChild($newElement);
+ } elsif (defined $comment) {
+ $parentElement->comment($comment);
+ } elsif (defined $cdata) {
+ my $newElement = XML::Mini::Element::CData->new($cdata);
+ $parentElement->appendChild($newElement);
+ } elsif (defined $doctypeCont) {
+ my $newElement = XML::Mini::Element::DocType->new($doctype);
+ $parentElement->appendChild($newElement);
+ $self->fromSubStringBT($newElement, $doctypeCont);
+ } elsif (defined $entityName) {
+ my $newElement = XML::Mini::Element::Entity->new($entityName, $entityCont);
+ $parentElement->appendChild($newElement);
+ } elsif (defined $plainText && $plainText =~ m|\S|sm)
+ {
+ $parentElement->createNode($plainText);
+ } else {
+ XML::Mini->Log("NO MATCH???") if ($XML::Mini::Debug);
+ }
+
+
+ if (defined $remainder && $remainder =~ m|\S|sm)
+ {
+ $self->fromSubStringBT($parentElement, $remainder);
+ }
+
+ } else {
+ # No match here either...
+ XML::Mini->Log("No match in fromSubStringBT() for '$XMLString'") if ($XML::Mini::Debug);
+
+ } # end if it matches one of our other tags or plain text
+
+ } # end if Text::Balanced returned a match
+
+
+} # end fromSubStringBT()
+
+
+
+
+sub fromSubString
+{
+ my $self = shift;
+ my $parentElement = shift;
+ my $XMLString = shift;
+
+ if ($XML::Mini::Debug)
+ {
+ XML::Mini->Log("Called fromSubString() with parent '" . $parentElement->name() . "'\n");
+ }
+
+
+ # The heart of the parsing is here, in our mega regex
+ # The sections are for:
+ # <tag>...</tag>
+ # <!-- comments -->
+ # <singletag />
+ # <![CDATA [ STUFF ]]>
+ # <!DOCTYPE ... [ ... ]>
+ # <!ENTITY bla "bla">
+ # plain text
+ #=~/<\s*([^\s>]+)([^>]+)?>(.*?)<\s*\/\\1\s*>\s*([^<]+)?(.*)
+
+
+ if ($TextBalancedAvailable)
+ {
+ return $self->fromSubStringBT($parentElement, $XMLString);
+ }
+
+ while ($XMLString =~/\s*<\s*([^\s>]+)([^>]+)?>(.*?)<\s*\/\1\s*>\s*([^<]+)?(.*)|
+ \s*<!--(.+?)-->\s*|
+ \s*<\s*([^\s>]+)\s*([^>]*)\/\s*>\s*([^<>]+)?|
+ \s*<!\[CDATA\s*\[(.*?)\]\]\s*>\s*|
+ \s*<!DOCTYPE\s*([^\[]*)\[(.*?)\]\s*>\s*|
+ \s*<!ENTITY\s*([^"'>]+)\s*(["'])([^\14]+)\14\s*>\s*|
+ \s*<\?\s*([^\s>]+)\s*([^>]*)\?>|
+ ^([^<]+)(.*)/xogsmi)
+
+
+ {
+ # Check which string matched.'
+ my $uname = $7;
+ my $comment = $6;
+ my $cdata = $10;
+ my $doctypedef = $12;
+ my $entityname = $13;
+ my $headername = $16;
+ my $headerAttribs = $17;
+ my $plaintext = $18;
+
+ if (defined $uname)
+ {
+ my $ufinaltxt = $9;
+ my $newElement = $parentElement->createChild($uname);
+ $self->_extractAttributesFromString($newElement, $8);
+ if (defined $ufinaltxt && $ufinaltxt =~ m|\S+|)
+ {
+ $parentElement->createNode($ufinaltxt);
+ }
+ } elsif (defined $headername)
+ {
+ my $newElement = XML::Mini::Element::Header->new($headername);
+ $self->_extractAttributesFromString($newElement, $headerAttribs) if ($headerAttribs);
+ $parentElement->appendChild($newElement);
+
+ } elsif (defined $comment) {
+ #my $newElement = XML::Mini::Element::Comment->new('!--');
+ #$newElement->createNode($comment);
+ $parentElement->comment($comment);
+ } elsif (defined $cdata) {
+ my $newElement = XML::Mini::Element::CData->new($cdata);
+ $parentElement->appendChild($newElement);
+ } elsif (defined $doctypedef) {
+ my $newElement = XML::Mini::Element::DocType->new($11);
+ $parentElement->appendChild($newElement);
+ $self->fromSubString($newElement, $doctypedef);
+
+ } elsif (defined $entityname) {
+
+ my $newElement = XML::Mini::Element::Entity->new($entityname, $15);
+ $parentElement->appendChild($newElement);
+
+ } elsif (defined $plaintext) {
+
+ my $afterTxt = $19;
+ if ($plaintext !~ /^\s+$/)
+ {
+ $parentElement->createNode($plaintext);
+ }
+
+ if (defined $afterTxt)
+ {
+ $self->fromSubString($parentElement, $afterTxt);
+ }
+ } elsif ($1) {
+
+ my $nencl = $3;
+ my $finaltxt = $4;
+ my $otherTags = $5;
+ my $newElement = $parentElement->createChild($1);
+ $self->_extractAttributesFromString($newElement, $2);
+
+
+ if ($nencl =~ /^\s*([^\s<][^<]*)/)
+ {
+ my $txt = $1;
+ $newElement->createNode($txt);
+ $nencl =~ s/^\s*[^<]+//;
+ }
+
+ $self->fromSubString($newElement, $nencl);
+
+ if (defined $finaltxt)
+ {
+ $parentElement->createNode($finaltxt);
+ }
+
+ if (defined $otherTags)
+ {
+ $self->fromSubString($parentElement, $otherTags);
+ }
+ }
+ } # end while matches
+} #* end method fromSubString */
+
+sub toFile
+{
+ my $self = shift;
+ my $filename = shift || return XML::Mini->Error("XML::Mini::Document::toFile - must pass a filename to save to");
+ my $safe = shift;
+
+ my $dir = $filename;
+
+ $dir =~ s|(.+/)?[^/]+$|$1|;
+
+ if ($dir)
+ {
+ return XML::Mini->Error("XML::Mini::Document::toFile - called with file '$filename' but cannot find director $dir")
+ unless (-e $dir && -d $dir);
+ return XML::Mini->Error("XML::Mini::Document::toFile - called with file '$filename' but no permission to write to dir $dir")
+ unless (-w $dir);
+ }
+
+ my $contents = $self->toString();
+
+ return XML::Mini->Error("XML::Mini::Document::toFile - got nothing back from call to toString()")
+ unless ($contents);
+
+ my $outfile = FileHandle->new();
+
+ if ($safe)
+ {
+ if ($filename =~ m|/\.\./| || $filename =~ m|#;`\*|)
+ {
+ return XML::Mini->Error("XML::Mini::Document::toFile() Filename '$filename' invalid with SAFE flag on");
+ }
+
+ if (-e $filename)
+ {
+ if ($safe =~ /NOOVERWRITE/i)
+ {
+ return XML::Mini->Error("XML::Mini::Document::toFile() file '$filename' exists and SAFE flag is '$safe'");
+ }
+
+ if (-l $filename)
+ {
+ return XML::Mini->Error("XML::Mini::Document::toFile() file '$filename' is a "
+ . "symbolic link and SAFE flag is on");
+ }
+ }
+ }
+
+ $outfile->open( ">$filename")
+ || return XML::Mini->Error("XML::Mini::Document::toFile() Could not open $filename for write: $!");
+ $outfile->print($contents);
+ $outfile->close();
+ return length($contents);
+}
+
+sub getValue
+{
+ my $self = shift;
+ return $self->{'_xmlDoc'}->getValue();
+}
+
+sub dump
+{
+ my $self = shift;
+ return Dumper($self);
+}
+
+#// _extractAttributesFromString
+#// private method for extracting and setting the attributs from a
+#// ' a="b" c = "d"' string
+sub _extractAttributesFromString
+{
+ my $self = shift;
+ my $element = shift;
+ my $attrString = shift;
+
+ return undef unless (defined $attrString);
+ my $count = 0;
+ while ($attrString =~ /([^\s]+)\s*=\s*(['"])([^\2]+?)\2/g)
+ {
+ my $attrname = $1;
+ my $attrval = $3;
+
+ if (defined $attrname)
+ {
+ $element->attribute($attrname, $attrval, '');
+ $count++;
+ }
+ }
+
+ return $count;
+}
+
+1;
+
+__END__
+
+=head1 NAME
+
+XML::Mini::Document - Perl implementation of the XML::Mini Document API.
+
+=head1 SYNOPSIS
+
+ use XML::Mini::Document;
+
+
+ use Data::Dumper;
+
+
+ ###### PARSING XML #######
+
+ # create a new object
+ my $xmlDoc = XML::Mini::Document->new();
+
+ # init the doc from an XML string
+ $xmlDoc->parse($XMLString);
+
+ # You may use the toHash() method to automatically
+ # convert the XML into a hash reference
+ my $xmlHash = $xmlDoc->toHash();
+
+ print Dumper($xmlHash);
+
+
+ # You can also manipulate the elements like directly, like this:
+
+ # Fetch the ROOT element for the document
+ # (an instance of XML::Mini::Element)
+ my $xmlRoot = $xmlDoc->getRoot();
+
+ # play with the element and its children
+ # ...
+ my $topLevelChildren = $xmlRoot->getAllChildren();
+
+ foreach my $childElement (@{$topLevelChildren})
+ {
+ # ...
+ }
+
+
+ ###### CREATING XML #######
+
+ # Create a new document from scratch
+
+ my $newDoc = XML::Mini::Document->new();
+
+ # This can be done easily by using a hash:
+ my $h = {
+ 'spy' => {
+ 'id' => '007',
+ 'type' => 'SuperSpy',
+ 'name' => 'James Bond',
+ 'email' => 'mi5 at london.uk',
+ 'address' => 'Wherever he is needed most',
+ },
+ };
+
+ $newDoc->fromHash($h);
+
+
+
+ # Or new XML can also be created by manipulating
+ #elements directly:
+
+ my $newDocRoot = $newDoc->getRoot();
+
+ # create the <? xml ?> header
+ my $xmlHeader = $newDocRoot->header('xml');
+ # add the version
+ $xmlHeader->attribute('version', '1.0');
+
+ my $person = $newDocRoot->createChild('person');
+
+ my $name = $person->createChild('name');
+ $name->createChild('first')->text('John');
+ $name->createChild('last')->text('Doe');
+
+ my $eyes = $person->createChild('eyes');
+ $eyes->attribute('color', 'blue');
+ $eyes->attribute('number', 2);
+
+ # output the document
+ print $newDoc->toString();
+
+
+This example would output :
+
+
+
+ <?xml version="1.0"?>
+ <person>
+ <name>
+ <first>
+ John
+ </first>
+ <last>
+ Doe
+ </last>
+ </name>
+ <eyes color="blue" number="2" />
+ </person>
+
+
+=head1 DESCRIPTION
+
+The XML::Mini::Document class is the programmer's handle to XML::Mini functionality.
+
+A XML::Mini::Document instance is created in every program that uses XML::Mini.
+With the XML::Mini::Document object, you can access the root XML::Mini::Element,
+find/fetch/create elements and read in or output XML strings.
+
+
+=head2 new [XMLSTRING]
+
+Creates a new instance of XML::Mini::Document, optionally calling
+fromString with the passed XMLSTRING
+
+=head2 getRoot
+
+Returns a reference the this document's root element
+(an instance of XML::Mini::Element)
+
+=head2 setRoot NEWROOT
+
+setRoot NEWROOT
+Set the document root to the NEWROOT XML::Mini::Element object.
+
+=head2 isElement ELEMENT
+
+Returns a true value if ELEMENT is an instance of XML::Mini::Element,
+false otherwise.
+
+=head2 isNode NODE
+
+Returns a true value if NODE is an instance of XML::MiniNode,
+false otherwise.
+
+=head2 createElement NAME [VALUE]
+
+Creates a new XML::Mini::Element with name NAME.
+
+This element is an orphan (has no assigned parent)
+and will be lost unless it is appended (XML::Mini::Element::appendChild())
+to an element at some point.
+
+If the optional VALUE (string or numeric) parameter is passed,
+the new element's text/numeric content will be set using VALUE.
+Returns a reference to the newly created element.
+
+=head2 getElement NAME [POSITON]
+
+Searches the document for an element with name NAME.
+
+Returns a reference to the first XML::Mini::Element with name NAME,
+if found, NULL otherwise.
+
+NOTE: The search is performed like this, returning the first
+element that matches:
+
+ - Check the Root Element's immediate children (in order) for a match.
+ - Ask each immediate child (in order) to XML::Mini::Element::getElement()
+ (each child will then proceed similarly, checking all it's immediate
+ children in order and then asking them to getElement())
+
+If a numeric POSITION parameter is passed, getElement() will return only
+the POSITIONth element of name NAME (starting at 1). Thus, on document
+
+
+ <?xml version="1.0"?>
+ <people>
+ <person>
+ bob
+ </person>
+ <person>
+ jane
+ </person>
+ <person>
+ ralph
+ </person>
+ </people>
+
+
+$people->getElement('person') will return the element containing the text node
+'bob', while $people->getElement('person', 3) will return the element containing the
+text 'ralph'.
+
+
+
+=head2 getElementByPath PATH [POSITIONARRAY]
+
+Attempts to return a reference to the (first) element at PATH
+where PATH is the path in the structure from the root element to
+the requested element.
+
+For example, in the document represented by:
+
+ <partRateRequest>
+ <vendor>
+ <accessid user="myusername" password="mypassword" />
+ </vendor>
+ <partList>
+ <partNum>
+ DA42
+ </partNum>
+ <partNum>
+ D99983FFF
+ </partNum>
+ <partNum>
+ ss-839uent
+ </partNum>
+ </partList>
+ </partRateRequest>
+
+ $accessid = $xmlDocument->getElementByPath('partRateRequest/vendor/accessid');
+
+Will return what you expect (the accessid element with attributes user = "myusername"
+and password = "mypassword").
+
+BUT be careful:
+
+ my $accessid = $xmlDocument->getElementByPath('partRateRequest/partList/partNum');
+
+will return the partNum element with the value "DA42". To access other partNum elements you
+must either use the POSITIONSARRAY or the getAllChildren() method on the partRateRequest element.
+
+POSITIONSARRAY functions like the POSITION parameter to getElement(), but instead of specifying the
+position of a single element, you must indicate the position of all elements in the path. Therefore, to
+get the third part number element, you would use
+
+ my $thirdPart = $xmlDocument->getElementByPath('partRateRequest/partList/partNum', 1, 1, 3);
+
+The additional 1,1,3 parameters indicate that you wish to retrieve the 1st partRateRequest element in
+the document, the 1st partList child of partRateRequest and the 3rd partNum child of the partList element
+(in this instance, the partNum element that contains 'ss-839uent').
+
+
+Returns the XML::Mini::Element reference if found, NULL otherwise.
+
+
+=head2 parse SOURCE
+
+Initialise the XML::Mini::Document (and its root XML::Mini::Element) using the
+XML from file SOURCE.
+
+SOURCE may be a string containing your XML document.
+
+In addition to parsing strings, possible SOURCEs are:
+
+
+ # a file location string
+ $miniXMLDoc->parse('/path/to/file.xml');
+
+ # an open file handle
+ open(INFILE, '/path/to/file.xml');
+ $miniXMLDoc->parse(*INFILE);
+
+ # an open FileHandle object
+ my $fhObj = FileHandle->new();
+ $fhObj->open('/path/to/file.xml');
+ $miniXML->parse($fhObj);
+
+In all cases where SOURCE is a file or file handle, XML::Mini takes care of slurping the
+contents and closing the handle.
+
+
+=head2 fromHash HASHREF [OPTIONS]
+
+Parses a "hash representation" of your XML structure. For each key => value pair within the
+hash ref, XML::Mini will create an element of name 'key' :
+
+
+ - with the text contents set to 'value' if 'value' is a string
+
+ - for each element of 'value' if value is an ARRAY REFERENCE
+
+ - with suitable children for each subkey => subvalue if 'value' is a HASH REFERENCE.
+
+
+For instance, if fromHash() is passed a simple hash ref like:
+
+
+ my $h = {
+
+ 'spy' => {
+ 'id' => '007',
+ 'type' => 'SuperSpy',
+ 'name' => 'James Bond',
+ 'email' => 'mi5 at london.uk',
+ 'address' => 'Wherever he is needed most',
+ },
+ };
+
+
+then :
+
+ $xmlDoc->fromHash($h);
+ print $xmlDoc->toString();
+
+will output
+
+ <spy>
+ <email> mi5 at london.uk </email>
+ <name> James Bond </name>
+ <address> Wherever he is needed most </address>
+ <type> SuperSpy </type>
+ <id> 007 </id>
+ </spy>
+
+
+
+The optional OPTIONS parameter may be used to specify which keys to use as attributes (instead of
+creating subelements). For example, calling
+
+
+ my $options = {
+ 'attributes' => {
+ 'spy' => 'id',
+ 'email' => 'type',
+ 'friend' => ['name', 'age'],
+ }
+ };
+
+
+ my $h = {
+
+ 'spy' => {
+ 'id' => '007',
+ 'type' => 'SuperSpy',
+ 'name' => 'James Bond',
+ 'email' => {
+ 'type' => 'private',
+ '-content' => 'mi5 at london.uk',
+
+ },
+ 'address' => {
+ 'type' => 'residential',
+ '-content' => 'Wherever he is needed most',
+ },
+
+ 'friend' => [
+ {
+ 'name' => 'claudia',
+ 'age' => 25,
+ 'type' => 'close',
+ },
+
+ {
+ 'name' => 'monneypenny',
+ 'age' => '40something',
+ 'type' => 'tease',
+ },
+
+ {
+ 'name' => 'Q',
+ 'age' => '10E4',
+ 'type' => 'pain',
+ }
+ ],
+
+ },
+ };
+
+
+ $xmlDoc->fromHash($h, $options);
+ print $xmlDoc->toString();
+
+will output something like:
+
+ <spy id="007">
+ <name> James Bond </name>
+ <email type="private"> mi5 at london.uk </email>
+ <address>
+ <type> residential </type>
+ Wherever he is needed most
+ </address>
+ <type> SuperSpy </type>
+ <friend age="25" name="claudia">
+ <type> close </type>
+ </friend>
+ <friend age="40something" name="monneypenny">
+ <type> tease </type>
+ </friend>
+ <friend age="10E4" name="Q">
+ <type> pain </type>
+ </friend>
+ </spy>
+
+As demonstrated above, you can use the optional href to specify tags for which attributes (instead of elements) should be
+created and you may nest hash and array refs to create complex structures.
+
+NOTE: Whenever a hash references is used you lose the sequence in which the elements are placed - only the array references (which create
+a list of identically named elements) can preserve their order.
+
+See ALSO: the documentation for the related toHash() method.
+
+Still TODO: Create some better docs for this! For the moment you can take a peek within the test suite of the source distribution.
+
+
+=head2 fromString XMLSTRING
+
+Initialise the XML::Mini::Document (and it's root XML::Mini::Element) using the
+XML string XMLSTRING.
+
+Returns the number of immediate children the root XML::Mini::Element now
+has.
+
+=head2 fromFile FILENAME
+
+Initialise the XML::Mini::Document (and it's root XML::Mini::Element) using the
+XML from file FILNAME.
+
+Returns the number of immediate children the root XML::Mini::Element now
+has.
+
+
+
+
+
+=head2 toString [DEPTH]
+
+Converts this XML::Mini::Document object to a string and returns it.
+
+The optional DEPTH may be passed to set the space offset for the
+first element.
+
+If the optional DEPTH is set to $XML::Mini::NoWhiteSpaces
+no \n or whitespaces will be inserted in the xml string
+(ie it will all be on a single line with no spaces between the tags.
+
+Returns a string of XML representing the document.
+
+=head2 toFile FILENAME [SAFE]
+
+Stringify and save the XML document to file FILENAME
+
+If SAFE flag is passed and is a true value, toFile will do some extra checking, refusing to open the file
+if the filename matches m|/\.\./| or m|#;`\*| or if FILENAME points to a softlink. In addition, if SAFE
+is 'NOOVERWRITE', toFile will fail if the FILENAME already exists.
+
+
+=head2 toHash
+
+Transform the XML structure internally represented within the object
+(created manually or parsed from a file or string) into a HASH reference and returns the href.
+
+For instance, if this XML is parse()d:
+
+<people>
+
+ <person id="007">
+ <email> mi5 at london.uk </email>
+ <name> James Bond </name>
+ <address> Wherever he is needed most </address>
+ <type> SuperSpy </type>
+ </person>
+
+ <person id="006" number="6">
+ <comment> I am not a man, I am a free number </comment>
+ <name> Number 6 </name>
+ <email type="private"> prisoner at aol.com </email>
+ <address> 6 Prison Island Road, Prison Island, Somewhere </address>
+ </person>
+
+</people>
+
+The hash reference returned will look like this (as output by Data::Dumper):
+
+
+ 'people' => {
+
+ 'person' => [
+ {
+ 'email' => 'mi5 at london.uk',
+ 'name' => 'James Bond',
+ 'type' => 'SuperSpy',
+ 'address' => 'Wherever he is needed most',
+ 'id' => '007'
+ },
+ {
+ 'email' => {
+ 'type' => 'private',
+ '-content' => 'prisoner at aol.com'
+ },
+ 'comment' => 'I am not a man, I am a free number',
+ 'number' => '6',
+ 'name' => 'Number 6',
+ 'address' => '6 Prison Island Road, Prison Island, Somewhere',
+ 'id' => '006'
+ }
+ ]
+ }
+
+
+
+=head2 getValue
+
+Utility function, call the root XML::Mini::Element's getValue()
+
+=head2 dump
+
+Debugging aid, dump returns a nicely formatted dump of the current structure of the
+XML::Mini::Document object.
+
+
+=head1 CAVEATS
+
+It is impossible to parse "cross-nested" tags using regular expressions (i.e. sequences of the form
+<a><b><a>...</a></b></a>). However, if you have the Text::Balanced module installed (it is installed
+by default with Perl 5.8), such sequences will be handled flawlessly.
+
+Even if you do not have the Text::Balanced module available, it is still possible to generate this type
+of XML - the problem only appears when parsing.
+
+=head1 AUTHOR
+
+
+Copyright (C) 2002-2003 Patrick Deegan, Psychogenic Inc.
+
+Programs that use this code are bound to the terms and conditions of the GNU GPL (see the LICENSE file).
+If you wish to include these modules in non-GPL code, you need prior written authorisation
+from the authors.
+
+
+LICENSE
+
+ XML::Mini::Document module, part of the XML::Mini XML parser/generator package.
+ Copyright (C) 2002-2003 Patrick Deegan
+ All rights reserved
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+
+Official XML::Mini site: http://minixml.psychogenic.com
+
+Contact page for author available at http://www.psychogenic.com/
+
+=head1 SEE ALSO
+
+
+XML::Mini, XML::Mini::Element
+
+http://minixml.psychogenic.com
+
+=cut
Added: packages/libxml-mini-perl/branches/upstream/current/lib/XML/Mini/Element/CData.pm
===================================================================
--- packages/libxml-mini-perl/branches/upstream/current/lib/XML/Mini/Element/CData.pm 2006-04-13 21:15:52 UTC (rev 2552)
+++ packages/libxml-mini-perl/branches/upstream/current/lib/XML/Mini/Element/CData.pm 2006-04-13 21:19:04 UTC (rev 2553)
@@ -0,0 +1,125 @@
+package XML::Mini::Element::CData;
+use strict;
+$^W = 1;
+
+use XML::Mini;
+use XML::Mini::Element;
+
+use vars qw ( $VERSION @ISA );
+$VERSION = '1.24';
+push @ISA, qw ( XML::Mini::Element );
+
+sub new
+{
+ my $class = shift;
+ my $contents = shift;
+
+ my $self = {};
+ bless $self, ref $class || $class;
+
+ $self->{'_attributes'} = {};
+ $self->{'_numChildren'} = 0;
+ $self->{'_numElementChildren'} = 0;
+ $self->{'_children'} = [];
+ $self->{'_avoidLoops'} = $XML::Mini::AvoidLoops;
+
+ $self->name('CDATA');
+
+ my $oldAutoEscape = $XML::Mini::AutoEscapeEntities;
+ $XML::Mini::AutoEscapeEntities = 0;
+ $self->createNode($contents) if (defined $contents);
+ $XML::Mini::AutoEscapeEntities = $oldAutoEscape;
+
+ return $self;
+}
+
+sub toString
+{
+ my $self = shift;
+ my $depth = shift;
+
+ my $spaces;
+ if ($depth == $XML::Mini::NoWhiteSpaces)
+ {
+ $spaces = '';
+ } else {
+ $spaces = $self->_spaceStr($depth);
+ }
+
+ my $retString = "$spaces<![CDATA[ ";
+
+ if (! $self->{'_numChildren'})
+ {
+ $retString .= "]]>\n";
+ return $retString;
+ }
+
+ my $nextDepth = ($depth == $XML::Mini::NoWhiteSpaces) ? $XML::Mini::NoWhiteSpaces
+ : $depth + 1;
+
+ for (my $i=0; $i < $self->{'_numChildren'}; $i++)
+ {
+ $retString .= $self->{'_children'}->[$i]->getValue();
+ }
+
+ $retString .= " ]]>\n";
+ return $retString;
+}
+
+
+sub toStringNoWhiteSpaces
+{
+ my $self = shift;
+ my $depth = shift;
+ return $self->toString($depth);
+}
+
+1;
+
+__END__
+
+=head1 NAME
+
+XML::Mini::Element::CData
+
+=head1 DESCRIPTION
+
+The XML::Mini::Element::CData is used internally to represent <![CDATA [ CONTENTS ]]>.
+
+You shouldn't need to use it directly, see XML::Mini::Element's cdata() method.
+
+=head1 AUTHOR
+
+LICENSE
+
+ XML::Mini::Element::CData module, part of the XML::Mini XML parser/generator package.
+ Copyright (C) 2002 Patrick Deegan
+ All rights reserved
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+
+Official XML::Mini site: http://minixml.psychogenic.com
+
+Contact page for author available at http://www.psychogenic.com/en/contact.shtml
+
+=head1 SEE ALSO
+
+
+XML::Mini, XML::Mini::Document, XML::Mini::Element
+
+http://minixml.psychogenic.com
+
+=cut
Added: packages/libxml-mini-perl/branches/upstream/current/lib/XML/Mini/Element/Comment.pm
===================================================================
--- packages/libxml-mini-perl/branches/upstream/current/lib/XML/Mini/Element/Comment.pm 2006-04-13 21:15:52 UTC (rev 2552)
+++ packages/libxml-mini-perl/branches/upstream/current/lib/XML/Mini/Element/Comment.pm 2006-04-13 21:19:04 UTC (rev 2553)
@@ -0,0 +1,128 @@
+package XML::Mini::Element::Comment;
+use strict;
+$^W = 1;
+
+use XML::Mini;
+use XML::Mini::Element;
+
+use vars qw ( $VERSION @ISA );
+$VERSION = '1.24';
+push @ISA, qw ( XML::Mini::Element );
+
+sub new
+{
+ my $class = shift;
+ my $self = {};
+ bless $self, ref $class || $class;
+ $self->{'_attributes'} = {};
+ $self->{'_numChildren'} = 0;
+ $self->{'_numElementChildren'} = 0;
+ $self->{'_children'} = [];
+ $self->{'_avoidLoops'} = $XML::Mini::AvoidLoops;
+ $self->name('!--');
+ return $self;
+}
+
+sub toString
+{
+ my $self = shift;
+ my $depth = shift;
+
+ if ($depth == $XML::Mini::NoWhiteSpaces)
+ {
+ return $self->toStringNoWhiteSpaces();
+ }
+
+ my $spaces = $self->_spaceStr($depth);
+
+ my $retString = "$spaces<!-- \n";
+
+ if (! $self->{'_numChildren'})
+ {
+ $retString .= " -->\n";
+ return $retString;
+ }
+
+ my $nextDepth = $depth + 1;
+
+ for (my $i=0; $i < $self->{'_numChildren'}; $i++)
+ {
+ $retString .= $self->{'_children'}->[$i]->toString($nextDepth);
+ }
+
+ $retString .= "\n" unless ($retString =~ m|\n$|sm);
+ $retString .= "$spaces -->\n";
+ return $retString;
+}
+
+
+sub toStringNoWhiteSpaces
+{
+ my $self = shift;
+
+ my $retString = '<!-- ';
+
+ if (! $self->{'_numChildren'})
+ {
+ $retString .= ' -->';
+ return $retString;
+ }
+
+ for (my $i=0; $i < $self->{'_numChildren'}; $i++)
+ {
+ $retString .= $self->{'_children'}->[$i]->toStringNoWhiteSpaces();
+ }
+
+ $retString .= " -->";
+ return $retString;
+}
+
+1;
+
+__END__
+
+=head1 NAME
+
+XML::Mini::Element::Comment
+
+=head1 DESCRIPTION
+
+The XML::Mini::Element::Comment is used internally to represent <!-- comments -->.
+
+You shouldn't need to use it directly, see XML::Mini::Element's comment() method.
+
+=head1 AUTHOR
+
+LICENSE
+
+ XML::Mini::Element::Comment module, part of the XML::Mini XML parser/generator package.
+ Copyright (C) 2002 Patrick Deegan
+ All rights reserved
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+
+Official XML::Mini site: http://minixml.psychogenic.com
+
+Contact page for author available at http://www.psychogenic.com/en/contact.shtml
+
+=head1 SEE ALSO
+
+
+XML::Mini, XML::Mini::Document, XML::Mini::Element
+
+http://minixml.psychogenic.com
+
+=cut
Added: packages/libxml-mini-perl/branches/upstream/current/lib/XML/Mini/Element/DocType.pm
===================================================================
--- packages/libxml-mini-perl/branches/upstream/current/lib/XML/Mini/Element/DocType.pm 2006-04-13 21:15:52 UTC (rev 2552)
+++ packages/libxml-mini-perl/branches/upstream/current/lib/XML/Mini/Element/DocType.pm 2006-04-13 21:19:04 UTC (rev 2553)
@@ -0,0 +1,117 @@
+package XML::Mini::Element::DocType;
+use strict;
+$^W = 1;
+
+use XML::Mini;
+use XML::Mini::Element;
+use vars qw ( $VERSION @ISA );
+
+$VERSION = '1.24';
+push @ISA, qw ( XML::Mini::Element );
+
+sub new
+{
+ my $class = shift;
+ my $attr = shift;
+ my $self = {};
+ bless $self, ref $class || $class;
+ $self->{'_attributes'} = {};
+ $self->{'_numChildren'} = 0;
+ $self->{'_numElementChildren'} = 0;
+ $self->{'_children'} = [];
+ $self->{'_avoidLoops'} = $XML::Mini::AvoidLoops;
+ $self->{'_attr'} = $attr;
+ $self->name('DOCTYPE');
+ return $self;
+}
+
+sub toString
+{
+ my $self = shift;
+ my $depth = shift;
+
+ my $spaces;
+ if ($depth == $XML::Mini::NoWhiteSpaces)
+ {
+ $spaces = '';
+ } else {
+ $spaces = $self->_spaceStr($depth);
+ }
+
+ my $retString = "$spaces<!DOCTYPE " . $self->{'_attr'} . " [\n";
+
+ if (! $self->{'_numChildren'})
+ {
+ $retString .= "]>\n";
+ return $retString;
+ }
+
+ my $nextDepth = ($depth == $XML::Mini::NoWhiteSpaces) ? $XML::Mini::NoWhiteSpaces
+ : $depth + 1;
+
+ for (my $i=0; $i < $self->{'_numChildren'}; $i++)
+ {
+ $retString .= $self->{'_children'}->[$i]->toString($nextDepth);
+ }
+
+ $retString .= "\n]>\n";
+ return $retString;
+}
+
+
+sub toStringNoWhiteSpaces
+{
+ my $self = shift;
+ my $depth = shift;
+ return $self->toString($depth);
+}
+
+1;
+
+__END__
+
+=head1 NAME
+
+XML::Mini::Element::DocType
+
+=head1 DESCRIPTION
+
+The XML::Mini::Element::DocType is used internally to represent <!DOCTYPE bla bla [ ... ]>.
+
+You shouldn't need to use it directly, see XML::Mini::Element's docType() method.
+
+=head1 AUTHOR
+
+LICENSE
+
+ XML::Mini::Element::DocType module, part of the XML::Mini XML parser/generator package.
+ Copyright (C) 2002 Patrick Deegan
+ All rights reserved
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+
+Official XML::Mini site: http://minixml.psychogenic.com
+
+Contact page for author available at http://www.psychogenic.com/en/contact.shtml
+
+=head1 SEE ALSO
+
+
+XML::Mini, XML::Mini::Document, XML::Mini::Element
+
+http://minixml.psychogenic.com
+
+=cut
Added: packages/libxml-mini-perl/branches/upstream/current/lib/XML/Mini/Element/Entity.pm
===================================================================
--- packages/libxml-mini-perl/branches/upstream/current/lib/XML/Mini/Element/Entity.pm 2006-04-13 21:15:52 UTC (rev 2552)
+++ packages/libxml-mini-perl/branches/upstream/current/lib/XML/Mini/Element/Entity.pm 2006-04-13 21:19:04 UTC (rev 2553)
@@ -0,0 +1,129 @@
+package XML::Mini::Element::Entity;
+use strict;
+$^W = 1;
+
+use XML::Mini;
+use XML::Mini::Element;
+
+use vars qw ( $VERSION @ISA );
+$VERSION = '1.24';
+push @ISA, qw ( XML::Mini::Element );
+
+sub new
+{
+ my $class = shift;
+ my $name = shift;
+ my $value = shift;
+
+ my $self = {};
+ bless $self, ref $class || $class;
+
+ $self->{'_attributes'} = {};
+ $self->{'_numChildren'} = 0;
+ $self->{'_numElementChildren'} = 0;
+ $self->{'_children'} = [];
+ $self->{'_avoidLoops'} = $XML::Mini::AvoidLoops;
+
+ $self->name($name);
+
+ my $oldAutoEscape = $XML::Mini::AutoEscapeEntities;
+ $XML::Mini::AutoEscapeEntities = 0;
+ $self->createNode($value) if (defined $value);
+ $XML::Mini::AutoEscapeEntities = $oldAutoEscape;
+
+ return $self;
+}
+
+sub toString
+{
+ my $self = shift;
+ my $depth = shift;
+
+ my $spaces;
+ if ($depth == $XML::Mini::NoWhiteSpaces)
+ {
+ $spaces = '';
+ } else {
+ $spaces = $self->_spaceStr($depth);
+ }
+
+ my $retString = "$spaces<!ENTITY " . $self->name();
+
+ if (! $self->{'_numChildren'})
+ {
+ $retString .= ">\n";
+ return $retString;
+ }
+
+ my $nextDepth = ($depth == $XML::Mini::NoWhiteSpaces) ? $XML::Mini::NoWhiteSpaces
+ : $depth + 1;
+ $retString .= '"';
+ for (my $i=0; $i < $self->{'_numChildren'}; $i++)
+ {
+ $retString .= $self->{'_children'}->[$i]->toString($XML::Mini::NoWhiteSpaces);
+ }
+ $retString .= '"';
+ #$retString =~ s/\n//g;
+
+ $retString .= " >\n";
+
+ return $retString;
+}
+
+
+sub toStringNoWhiteSpaces
+{
+ my $self = shift;
+ my $depth = shift;
+ return $self->toString($depth);
+}
+
+1;
+
+__END__
+
+=head1 NAME
+
+XML::Mini::Element::Entity
+
+=head1 DESCRIPTION
+
+The XML::Mini::Element::Entity is used internally to represent <!ENTITY name "stuff">.
+
+You shouldn't need to use it directly, see XML::Mini::Element's entity() method.
+
+=head1 AUTHOR
+
+LICENSE
+
+ XML::Mini::Element::Entity module, part of the XML::Mini XML parser/generator package.
+ Copyright (C) 2002 Patrick Deegan
+ All rights reserved
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+
+Official XML::Mini site: http://minixml.psychogenic.com
+
+Contact page for author available at http://www.psychogenic.com/en/contact.shtml
+
+=head1 SEE ALSO
+
+
+XML::Mini, XML::Mini::Document, XML::Mini::Element
+
+http://minixml.psychogenic.com
+
+=cut
Added: packages/libxml-mini-perl/branches/upstream/current/lib/XML/Mini/Element/Header.pm
===================================================================
--- packages/libxml-mini-perl/branches/upstream/current/lib/XML/Mini/Element/Header.pm 2006-04-13 21:15:52 UTC (rev 2552)
+++ packages/libxml-mini-perl/branches/upstream/current/lib/XML/Mini/Element/Header.pm 2006-04-13 21:19:04 UTC (rev 2553)
@@ -0,0 +1,128 @@
+package XML::Mini::Element::Header;
+use strict;
+$^W = 1;
+
+use XML::Mini;
+use XML::Mini::Element;
+
+use vars qw ( $VERSION @ISA );
+$VERSION = '1.00';
+push @ISA, qw ( XML::Mini::Element );
+
+sub new
+{
+ my $class = shift;
+ my $name = shift || XML::Mini->Error("Must pass a NAME to XML::Mini::Element::Header::new()");
+
+ my $self = {};
+ bless $self, ref $class || $class;
+ $self->{'_attributes'} = {};
+ $self->{'_numChildren'} = 0;
+ $self->{'_numElementChildren'} = 0;
+ $self->{'_children'} = [];
+ $self->{'_avoidLoops'} = $XML::Mini::AvoidLoops;
+ $self->name($name);
+ return $self;
+}
+
+sub toString
+{
+ my $self = shift;
+ my $depth = shift;
+
+ if ($depth == $XML::Mini::NoWhiteSpaces)
+ {
+ return $self->toStringNoWhiteSpaces();
+ }
+
+ my $spaces = $self->_spaceStr($depth);
+
+ my $retString = "$spaces<?". $self->name() . ' ';
+
+ my $attribString;
+ foreach my $atName (sort keys %{$self->{'_attributes'}})
+ {
+ $attribString .= qq|$atName="$self->{'_attributes'}->{$atName}" |;
+ }
+
+ if (defined $attribString && $attribString =~ m|\S|)
+ {
+ $retString .= $attribString;
+ }
+
+ $retString =~ s/\s+$//;
+
+ $retString .= "?>\n";
+ return $retString;
+
+}
+
+
+sub toStringNoWhiteSpaces
+{
+ my $self = shift;
+
+ my $retString = '<? ' . $self->name();
+ my $attribString;
+ foreach my $atName (sort keys %{$self->{'_attributes'}})
+ {
+ $attribString .= qq|$atName="$self->{'_attributes'}->{$atName}" |;
+ }
+ if (defined $attribString && $attribString =~ m|\S|)
+ {
+ $retString .= $attribString;
+ }
+ $retString =~ s/\s+$//;
+ $retString .= "?>";
+ return $retString;
+}
+
+1;
+
+__END__
+
+=head1 NAME
+
+XML::Mini::Element::Header
+
+=head1 DESCRIPTION
+
+The XML::Mini::Element::Header is used internally to represent <? xml blah="hohoho" ?> type headers.
+
+You shouldn't need to use it directly, see XML::Mini::Element's header() method.
+
+=head1 AUTHOR
+
+LICENSE
+
+ XML::Mini::Element::Header module, part of the XML::Mini XML parser/generator package.
+ Copyright (C) 2003 Patrick Deegan
+ All rights reserved
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+
+Official XML::Mini site: http://minixml.psychogenic.com
+
+Contact page for author available at http://www.psychogenic.com/en/contact.shtml
+
+=head1 SEE ALSO
+
+
+XML::Mini, XML::Mini::Document, XML::Mini::Element
+
+http://minixml.psychogenic.com
+
+=cut
Added: packages/libxml-mini-perl/branches/upstream/current/lib/XML/Mini/Element.pm
===================================================================
--- packages/libxml-mini-perl/branches/upstream/current/lib/XML/Mini/Element.pm 2006-04-13 21:15:52 UTC (rev 2552)
+++ packages/libxml-mini-perl/branches/upstream/current/lib/XML/Mini/Element.pm 2006-04-13 21:19:04 UTC (rev 2553)
@@ -0,0 +1,1357 @@
+package XML::Mini::Element;
+use strict;
+$^W = 1;
+
+use XML::Mini;
+use XML::Mini::TreeComponent;
+use XML::Mini::Element::Comment;
+use XML::Mini::Element::DocType;
+use XML::Mini::Element::Entity;
+use XML::Mini::Element::CData;
+
+use vars qw ( $VERSION @ISA );
+push @ISA, qw ( XML::Mini::TreeComponent );
+$VERSION = '1.28';
+
+sub new
+{
+ my $class = shift;
+ my $name = shift;
+
+ my $self = {};
+ bless $self, ref $class || $class;
+
+ $self->{'_attributes'} = {};
+ $self->{'_numChildren'} = 0;
+ $self->{'_numElementChildren'} = 0;
+ $self->{'_children'} = [];
+ $self->{'_avoidLoops'} = $XML::Mini::AvoidLoops;
+
+ if ($name)
+ {
+ $self->name($name);
+ } else {
+ return XML::Mini->Error("Must pass a name to create a new Element.");
+ }
+
+ return $self;
+}
+
+sub name
+{
+ my $self = shift;
+ my $name = shift;
+
+ if (defined $name)
+ {
+ $self->{'_name'} = $name;
+ }
+
+ return $self->{'_name'};
+}
+
+sub attribute
+{
+ my $self = shift;
+ my $name = shift || return undef;
+ my $primValue = shift;
+ my $altValue = shift;
+
+ my $value = (defined $primValue) ? $primValue : $altValue;
+
+ if (defined $value)
+ {
+ $self->{'_attributes'}->{$name} = $value;
+ }
+
+ if (defined $self->{'_attributes'}->{$name})
+ {
+ return $self->{'_attributes'}->{$name};
+ }
+
+ return undef;
+}
+
+sub text
+{
+ my $self = shift;
+ my $primValue = shift;
+ my $altValue = shift;
+
+ my $setTo = (defined $primValue) ? $primValue : $altValue;
+
+ if (defined $setTo)
+ {
+ $self->createNode($setTo);
+ }
+
+ my @contents;
+
+ foreach my $child (@{$self->{'_children'}})
+ {
+ my $value = $child->getValue();
+ if (defined $value)
+ {
+ push @contents, $value;
+ }
+ }
+
+ if (scalar @contents)
+ {
+ my $retStr = join(' ', @contents);
+ return $retStr;
+ }
+
+ return undef;
+}
+
+sub numeric
+{
+ my $self = shift;
+ my $primValue = shift;
+ my $altValue = shift;
+
+ my $setTo = (defined $primValue) ? $primValue : $altValue;
+
+ if (defined $setTo)
+ {
+ return XML::Mini->Error("Must pass a NUMERIC value to Element::numeric() to set ($setTo)")
+ unless ($setTo =~ m/^\s*[Ee\d\.\+-]+\s*$/);
+
+ $self->text($setTo);
+ }
+
+
+ my @contents;
+ foreach my $child (@{$self->{'_children'}})
+ {
+ my $value = $child->getValue();
+ if (defined $value)
+ {
+ push @contents, $value if ($value =~ /^\s*[Ee\d\.\+-]+\s*$/);
+ }
+ }
+
+ if (scalar @contents)
+ {
+ my $retStr = join(' ', @contents);
+ return $retStr;
+ }
+
+ return undef;
+}
+
+sub comment
+{
+ my $self = shift;
+ my $contents = shift;
+
+ my $newEl = XML::Mini::Element::Comment->new();
+ $newEl->text($contents);
+
+ $self->appendChild($newEl);
+
+ return $newEl;
+}
+
+sub header
+{
+ my $self = shift;
+ my $name = shift;
+ my $attribs = shift; # optional
+
+ unless (defined $name)
+ {
+ return XML::Mini->Error("XML::Mini::Element::header() must pass a NAME to create a new header");
+ }
+
+ my $newElement = XML::Mini::Element::Header->new($name);
+ $self->appendChild($newElement);
+
+ return $newElement;
+}
+
+
+sub docType
+{
+ my $self = shift;
+ my $definition = shift;
+
+ my $newElement = XML::Mini::Element::DocType->new($definition);
+ $self->appendChild($newElement);
+
+ return $newElement;
+}
+
+sub entity
+{
+ my $self = shift;
+ my $name = shift;
+ my $value = shift;
+
+ my $newElement = XML::Mini::Element::Entity->new($name, $value);
+ $self->appendChild($newElement);
+
+ return $newElement;
+}
+
+sub cdata
+{
+ my $self = shift;
+ my $contents = shift;
+ my $newElement = XML::Mini::Element::CData->new($contents);
+ $self->appendChild($newElement);
+
+ return $newElement;
+}
+
+# Note: the seperator parameter remains officially undocumented
+# since I'm not sure it will remain part of the API
+sub getValue {
+ my $self = shift;
+ my $seperator = shift || ' ';
+
+ my @valArray;
+ my $retStr = '';
+
+ foreach my $child ( @{$self->{'_children'}})
+ {
+ my $value = $child->getValue();
+ if (defined $value)
+ {
+ push @valArray , $value;
+ }
+ }
+
+ if (scalar @valArray)
+ {
+ $retStr = join($seperator, @valArray);
+ }
+
+ return $retStr;
+}
+
+sub getElement {
+ my $self = shift;
+ my $name = shift;
+ my $elementNumber = shift || 1;
+
+ return XML::Mini->Error("Element::getElement() Must Pass Element name.")
+ unless defined ($name);
+
+ if ($XML::Mini::Debug)
+ {
+ XML::Mini->Log("Element::getElement() called for $name on " . $self->{'_name'} );
+ }
+
+
+ ########## getElement needs to search the calling element's children ONLY
+ ########## or else it is impossible to retrieve the nested element of the same name:
+ ########## <nested>
+ ########## <nested>
+ ########## The second nested element is inaccessible if we return $self...
+ ########## </nested>
+ ########## <nested>
+ #if ($XML::Mini::CaseSensitive)
+ #{
+ #return $self if ($self->{'_name'} =~ m/^$name$/);
+ #} else {
+ #return $self if ($self->{'_name'} =~ m/^$name$/i);
+ #}
+
+ return undef unless $self->{'_numChildren'};
+
+ my $foundCount = 0;
+ #* Try each child (immediate children take priority) *
+ for (my $i = 0; $i < $self->{'_numChildren'}; $i++)
+ {
+ my $childname = $self->{'_children'}->[$i]->name();
+ if ($childname)
+ {
+ if ($XML::Mini::CaseSensitive)
+ {
+ if ($name =~ m/^$childname$/)
+ {
+ $foundCount++;
+ return $self->{'_children'}->[$i] if ($foundCount == $elementNumber);
+ }
+ } else {
+ if ($name =~ m/^$childname$/i)
+ {
+ $foundCount++;
+ return $self->{'_children'}->[$i] if ($foundCount == $elementNumber);
+ }
+
+ }
+
+ } #/* end if child has a name */
+
+ } #/* end loop over all my children */
+
+ #/* Now, Use beautiful recursion, daniel san */
+ for (my $i = 0; $i < $self->{'_numChildren'}; $i++)
+ {
+ my $theelement = $self->{'_children'}->[$i]->getElement($name, $elementNumber);
+ if ($theelement)
+ {
+
+ XML::Mini->Log("Element::getElement() returning element " . $theelement->name())
+ if ($XML::Mini::Debug);
+
+ return $theelement;
+ }
+ }
+
+ #/* Not found */
+ return undef;
+}
+
+sub getElementByPath
+{
+ my $self = shift;
+ my $path = shift || return undef;
+ my @elementNumbers = @_;
+
+ my @names = split ("/", $path);
+ my $element = $self;
+ my $position = 0;
+ foreach my $elementName (@names)
+ {
+ next unless ($elementName);
+ if ($element) #/* Make sure we didn't hit a dead end */
+ {
+ #/* Ask this element to get the next child in path */
+ $element = $element->getElement($elementName, $elementNumbers[$position++]);
+ }
+ }
+ return $element;
+} #/* end method getElementByPath */
+
+
+sub numChildren
+{
+ my $self = shift;
+ my $named = shift; # optionally only count elements named 'named'
+ unless (defined $named)
+ {
+ return $self->{'_numElementChildren'};
+ }
+ my $allkids = $self->getAllChildren($named);
+ return scalar @{$allkids};
+}
+
+sub getAllChildren
+{
+ my $self = shift;
+ my $name = shift; # optionally only children with this name
+
+
+ my @returnChildren;
+ for (my $i=0; $i < $self->{'_numChildren'}; $i++)
+ {
+ if ($self->isElement($self->{'_children'}->[$i]))
+ {
+ my $childName = $self->{'_children'}->[$i]->name();
+ # return only Element and derivatives children
+ if (defined $name)
+ {
+ if ($XML::Mini::CaseSensitive)
+ {
+ push @returnChildren, $self->{'_children'}->[$i]
+ if ($name =~ /^$childName$/);
+ } else {
+ # case insensitive
+ push @returnChildren, $self->{'_children'}->[$i]
+ if ($name =~ /^$childName$/i);
+ }
+ } else {
+ # no name set, all children returned
+ push @returnChildren, $self->{'_children'}->[$i];
+ } # end if name
+ } # end if element
+ } # end loop over all children
+ return \@returnChildren;
+}
+
+sub isElement
+{
+ my $self = shift;
+ my $element = shift || $self;
+ my $type = ref $element;
+ return undef unless $type;
+ return 0 unless ($type =~ /^XML::Mini::Element/);
+ return 1;
+}
+
+sub isNode
+{
+ my $self = shift;
+ my $element = shift || $self;
+ my $type = ref $element;
+ return undef unless $type;
+ return 0 unless ($type =~ /^XML::Mini::Node/);
+ return 1;
+}
+
+
+sub insertChild {
+ my $self = shift;
+ my $child = shift;
+ my $idx = shift || 0;
+
+
+
+ $self->_validateChild($child);
+
+
+ if ($self->{'_avoidLoops'} || $XML::Mini::AutoSetParent)
+ {
+ if ($self->{'_parent'} == $child)
+ {
+ my $childName = $child->name();
+ return XML::Mini->Error("Element::insertChild() Tryng to append parent $childName as child of "
+ . $self->name());
+ }
+ $child->parent($self);
+ }
+
+ my $nextIdx = $self->{'_numChildren'};
+ my $lastIdx = $nextIdx - 1;
+
+ if ($idx > $lastIdx)
+ {
+
+ if ($idx > $nextIdx)
+ {
+ $idx = $lastIdx + 1;
+ }
+ $self->{'_children'}->[$idx] = $child;
+ $self->{'_numChildren'}++;
+ $self->{'_numElementChildren'}++ if ($self->isElement($child));
+
+ } elsif ($idx >= 0)
+ {
+ my @removed = splice(@{$self->{'_children'}}, $idx);
+ push @{$self->{'_children'}}, ($child, @removed);
+
+ $self->{'_numChildren'}++;
+ $self->{'_numElementChildren'}++ if ($self->isElement($child));
+ } else {
+ my $revIdx = (-1 * $idx) % $self->{'_numChildren'};
+ my $newIdx = $self->{'_numChildren'} - $revIdx;
+
+ if ($newIdx < 0)
+ {
+ return XML::Mini->Error("Element::insertChild() Ended up with a negative index? ($newIdx)");
+ }
+
+ return $self->insertChild($child, $newIdx);
+ }
+
+ return $child;
+}
+
+
+sub appendChild
+{
+ my $self = shift;
+ my $child = shift;
+
+ $self->_validateChild($child);
+
+ if ($self->{'_avoidLoops'} || $XML::Mini::AutoSetParent)
+ {
+ if ($self->{'_parent'} == $child)
+ {
+ my $childName = $child->name();
+ return XML::Mini->Error("Element::appendChild() Tryng to append parent $childName as child of "
+ . $self->name());
+ }
+ $child->parent($self);
+ }
+
+ $self->{'_numElementChildren'}++; #Note that we're addind a Element child
+
+ my $idx = $self->{'_numChildren'}++;
+ $self->{'_children'}->[$idx] = $child;
+
+ return $self->{'_children'}->[$idx];
+}
+
+sub prependChild
+{
+ my $self = shift;
+ my $child = shift;
+
+ $self->_validateChild($child);
+
+ if ($self->{'_avoidLoops'} || $XML::Mini::AutoSetParent)
+ {
+ if ($self->{'_parent'} == $child)
+ {
+ my $childName = $child->name();
+ return XML::Mini->Error("Element::appendChild() Tryng to append parent $childName as child of "
+ . $self->name());
+ }
+ $child->parent($self);
+ }
+
+ $self->{'_numElementChildren'}++; #Note that we're addind a Element child
+
+ my $idx = $self->{'_numChildren'}++;
+ unshift(@{$self->{'_children'}}, $child);
+
+ return $self->{'_children'}->[0];
+}
+
+
+sub createChild
+{
+ my $self = shift;
+ my $name = shift;
+ my $value = shift; # optionally fill child with
+
+ unless (defined $name)
+ {
+ return XML::Mini->Error("Element::createChild() Must pass a NAME to createChild.");
+ }
+
+ my $child = XML::Mini::Element->new($name);
+
+ $child = $self->appendChild($child);
+
+ if (defined $value)
+ {
+ if ($value =~ m/^\s*[Ee\d\.\+-]+\s*$/)
+ {
+ $child->numeric($value);
+ } else {
+ $child->text($value);
+ }
+ }
+
+ $child->avoidLoops($self->{'_avoidLoops'});
+
+ return $child;
+}
+
+
+sub _validateChild {
+ my $self = shift;
+ my $child = shift;
+
+
+ return XML::Mini->Error("Element:_validateChild() need to pass a non-NULL Element child")
+ unless (defined $child);
+
+ return XML::Mini->Error("Element::_validateChild() must pass an Element object to appendChild.")
+ unless ($self->isElement($child));
+
+
+ my $childName = $child->name();
+
+ return XML::Mini->Error("Element::_validateChild() children must be named")
+ unless (defined $childName);
+
+ if ($child == $self)
+ {
+ return XML::Mini->Error("Element::_validateChild() Trying to append self as own child!");
+ } elsif ( $self->{'_avoidLoops'} && $child->parent())
+ {
+
+ return XML::Mini->Error("Element::_validateChild() Trying to append a child ($childName) that already has a parent set "
+ . "while avoidLoops is on - aborting");
+ }
+
+ return 1;
+}
+
+
+sub removeChild {
+ my $self = shift;
+ my $child = shift;
+
+
+ unless ($self->{'_numChildren'})
+ {
+ return XML::Mini->Error("Element::removeChild() called for element without any children.");
+ }
+
+ my $foundChild;
+ my $idx = 0;
+ while ($idx < $self->{'_numChildren'} && ! $foundChild)
+ {
+ if ($self->{'_children'}->[$idx] == $child)
+ {
+ $foundChild = $self->{'_children'}->[$idx];
+ } else {
+ $idx++;
+ }
+ }
+
+ unless ($foundChild)
+ {
+ XML::Mini->Log("Element::removeChild() No matching child found.") if ($XML::Mini::Debug);
+ return undef;
+ }
+
+ splice @{$self->{'_children'}}, $idx, 1;
+ $self->{'_numChildren'}--;
+ if ($foundChild->isElement())
+ {
+ $self->{'_numElementChildren'}--;
+ }
+
+ delete $foundChild->{'_parent'} ;
+ return $foundChild;
+}
+
+sub removeAllChildren {
+ my $self = shift;
+
+ return undef unless ($self->{'_numChildren'});
+
+ my $retList = $self->{'_children'};
+ delete $self->{'_children'};
+ $self->{'_numElementChildren'} = 0;
+ $self->{'_numChildren'} = 0;
+
+ foreach my $child (@{$retList})
+ {
+ delete $child->{'_parent'};
+ }
+
+ delete $self->{'_children'};
+ $self->{'children'} = [];
+
+ return $retList;
+}
+
+sub remove {
+ my $self = shift;
+
+ my $parent = $self->parent();
+
+ unless ($parent)
+ {
+ XML::Mini->Log("XML::Mini::Element::remove() called for element with no parent set. Aborting.");
+ return undef;
+ }
+
+ my $removed = $parent->removeChild($self);
+
+ return $removed;
+}
+
+sub parent {
+ my $self = shift;
+ my $parent = shift; # optionally set
+
+ if (defined $parent)
+ {
+ return XML::Mini->Error("Element::parent(): Must pass an instance of Element to set.")
+ unless ($self->isElement($parent));
+ $self->{'_parent'} = $parent;
+ }
+ return $self->{'_parent'};
+}
+
+sub avoidLoops
+{
+ my $self = shift;
+ my $setTo = shift; # optionally set
+ if (defined $setTo)
+ {
+ $self->{'_avoidLoops'} = $setTo;
+ }
+ return $self->{'_avoidLoops'};
+}
+
+
+sub toStructure {
+ my $self = shift;
+
+
+ my $retHash = {};
+ my $contents = "";
+ my $numAdded = 0;
+ if ($self->{'_attributes'})
+ {
+ while (my ($attname, $attvalue) = each %{$self->{'_attributes'}})
+ {
+ $retHash->{$attname} = $attvalue;
+ $numAdded++;
+ }
+ }
+
+ my $numChildren = $self->{'_numChildren'} || 0;
+ for (my $i=0; $i < $numChildren ; $i++)
+ {
+ my $thisChild = $self->{'_children'}->[$i];
+ if ($self->isElement($thisChild))
+ {
+ my $name = $thisChild->name();
+ my $struct = $thisChild->toStructure();
+ my $existing = $retHash->{$name};
+
+ if ($existing)
+ {
+ my $existingType = ref $existing || "";
+ if ($existingType eq 'ARRAY')
+ {
+ push @{$existing}, $struct;
+ } else {
+ my $arrayRef = [$existing, $struct];
+ $retHash->{$name} = $arrayRef;
+ }
+ } else {
+
+ $retHash->{$name} = $struct;
+ }
+
+
+ $numAdded++;
+
+ } else {
+ $contents .= $thisChild->getValue();
+ }
+ }
+
+ if ($numAdded)
+ {
+ if (length($contents))
+ {
+ $retHash->{'-content'} = $contents;
+ }
+
+ return $retHash;
+ } else {
+ return $contents;
+ }
+
+}
+
+
+sub toString
+{
+ my $self = shift;
+ my $depth = shift || 0;
+
+ if ($depth == $XML::Mini::NoWhiteSpaces)
+ {
+ return $self->toStringNoWhiteSpaces();
+ }
+
+ my $retString;
+ my $attribString = '';
+ my $elementName = $self->{'_name'};
+ my $spaces = $self->_spaceStr($depth);
+
+ foreach my $atName (sort keys %{$self->{'_attributes'}})
+ {
+ $attribString .= qq|$atName="$self->{'_attributes'}->{$atName}" |;
+ }
+
+ $retString = "$spaces<$elementName";
+
+ if ($attribString)
+ {
+ $attribString =~ s/\s*$//;
+ $retString .= " $attribString";
+ }
+
+ if (! $self->{'_numChildren'})
+ {
+ $retString .= " />\n";
+ return $retString;
+ }
+
+ # Else, we do have kids - sub element or nodes
+ $retString .= ">\n";
+
+ my $nextDepth = $depth + 1;
+
+ for(my $i=0; $i < $self->{'_numChildren'}; $i++)
+ {
+ my $newStr = $self->{'_children'}->[$i]->toString($nextDepth);
+ if (defined $newStr)
+ {
+ if ( $newStr !~ m|\n$|)
+ {
+ $newStr .= "\n";
+ }
+ $retString .= $newStr;
+ } # end if newStr returned
+ } # end loop over all children
+ $retString .= "$spaces</$elementName>\n";
+ return $retString;
+}
+
+sub toStringNoWhiteSpaces
+{
+ my $self = shift;
+
+ my $retString;
+ my $attribString = '';
+ my $elementName = $self->{'_name'};
+
+ while (my ($atName, $atVal) = each %{$self->{'_attributes'}})
+ {
+ $attribString .= qq|$atName="$atVal" |;
+ }
+
+ $retString = "<$elementName";
+
+ if ($attribString)
+ {
+ $attribString =~ s/\s*$//;
+ $retString .= " $attribString";
+ }
+
+ if (! $self->{'_numChildren'})
+ {
+ $retString .= '/>';
+ return $retString;
+ }
+
+ # Else, we do have kids - sub element or nodes
+
+ $retString .= '>';
+
+ for(my $i=0; $i < $self->{'_numChildren'}; $i++)
+ {
+ my $newStr = $self->{'_children'}->[$i]->toStringNoWhiteSpaces();
+ $retString .= $newStr if (defined $newStr);
+ } # end loop over all children
+
+ $retString .= "</$elementName>";
+ return $retString;
+}
+
+sub createNode
+{
+ my $self = shift;
+ my $value = shift;
+
+ my $newNode = XML::Mini::Node->new($value);
+ return undef unless ($newNode);
+
+ my $appendedNode = $self->appendNode($newNode);
+ return $appendedNode;
+}
+
+sub appendNode
+{
+ my $self = shift;
+ my $node = shift;
+
+ return XML::Mini->Error("Element::appendNode() need to pass a non-NULL XML::MiniNode.")
+ unless (defined $node);
+
+ return XML::Mini->Error("Element::appendNode() must pass a XML::MiniNode object to appendNode.")
+ unless ($self->isNode($node));
+
+
+
+ if ($XML::Mini::AutoSetParent)
+ {
+ $node->parent($self);
+ }
+
+ if ($XML::Mini::Debug)
+ {
+ XML::Mini->Log("Appending node to " . $self->{'_name'});
+ }
+
+ my $idx = $self->{'_numChildren'}++;
+ $self->{'_children'}->[$idx] = $node;
+
+ return $self->{'_children'}->[$idx];
+}
+
+1;
+
+__END__
+
+=head1 NAME
+
+XML::Mini::Element - Perl implementation of the XML::Mini Element API.
+
+=head1 SYNOPSIS
+
+ use XML::Mini::Document;
+
+ my $xmlDoc = XML::Mini::Document->new();
+
+ # Fetch the ROOT element for the document
+ # (an instance of XML::Mini::Element)
+ my $xmlElement = $xmlDoc->getRoot();
+
+ # Create an <?xml?> tag
+ my $xmlHeader = $xmlElement->header('xml');
+
+ # add the version to get <?xml version="1.0"?>
+ $xmlHeader->attribute('version', '1.0');
+
+ # Create a sub element
+ my $newChild = $xmlElement->createChild('mychild');
+
+ $newChild->text('hello mommy');
+
+
+ # Create an orphan element
+
+ my $orphan = $xmlDoc->createElement('annie');
+
+ $orphan->attribute('hair', '#ff0000');
+ $orphan->text('tomorrow, tomorrow');
+
+ # Adopt the orphan
+ $newChild->appendChild($orphan);
+
+
+ # ...
+ # add a child element to the front of the list
+ $xmlElement->prependChild($otherElement);
+
+ print $xmlDoc->toString();
+
+
+
+The code above would output:
+
+
+<?xml version="1.0" ?>
+ <mychild>
+ hello mommy
+ <annie hair="#ff0000">
+ tomorrow, tomorrow
+ </annie>
+ </mychild>
+
+=head1 DESCRIPTION
+
+Although the main handle to the xml document is the XML::Mini::Document object,
+much of the functionality and manipulation involves interaction with
+Element objects.
+
+A Element
+has:
+
+ - a name
+ - a list of 0 or more attributes (which have a name and a value)
+ - a list of 0 or more children (Element or XML::MiniNode objects)
+ - a parent (optional, only if MINIXML_AUTOSETPARENT > 0)
+
+=head2 new NAME
+
+Creates a new instance of XML::Mini::Element, with name NAME
+
+=head2 name [NEWNAME]
+
+If a NEWNAME string is passed, the Element's name is set
+to NEWNAME.
+
+Returns the element's name.
+
+=head2 attribute NAME [SETTO [SETTOALT]]
+
+
+The attribute() method is used to get and set the
+Element's attributes (ie the name/value pairs contained
+within the tag, <tagname attrib1="value1" attrib2="value2">)
+
+If SETTO is passed, the attribute's value is set to SETTO.
+
+If the optional SETTOALT is passed and SETTO is false, the
+attribute's value is set to SETTOALT. This is usefull in cases
+when you wish to set the attribute to a default value if no SETTO is
+present, eg $myelement->attribute('href', $theHref, 'http://psychogenic.com')
+will default to 'http://psychogenic.com'.
+
+
+Returns the value associated with attribute NAME.
+
+=head2 text [SETTO [SETTOALT]]
+
+The text() method is used to get or append text data to this
+element (it is appended to the child list as a new XML::MiniNode object).
+
+If SETTO is passed, a new node is created, filled with SETTO
+and appended to the list of this element's children.
+
+If the optional SETTOALT is passed and SETTO is false, the
+new node's value is set to SETTOALT. See the attribute() method
+for an example use.
+
+Returns a string composed of all child XML::MiniNodes' contents.
+
+
+Note: all the children XML::MiniNodes' contents - including numeric
+nodes are included in the return string.
+
+
+=head2 numeric [SETTO [SETTOALT]]
+
+The numeric() method is used to get or append numeric data to
+this element (it is appended to the child list as a XML::MiniNode object).
+
+If SETTO is passed, a new node is created, filled with SETTO
+and appended to the list of this element's children.
+
+If the optional SETTOALT is passed and SETTO is false, the
+new node's value is set to SETTOALT. See the attribute() method
+for an example use.
+
+Returns a space seperated string composed all child XML::MiniNodes'
+numeric contents.
+
+Note: ONLY numerical contents are included from the list of child XML::MiniNodes.
+
+=head2 header NAME
+
+The header() method allows you to add a new XML::Mini::Element::Header to this
+element's list of children.
+
+Headers return a <? NAME ?> string for the element's toString() method. Attributes
+may be set using attribute(), to create headers like
+<?xml-stylesheet href="doc.xsl" type="text/xsl"?>
+
+Valid XML documents must have at least an 'xml' header, like:
+<?xml version="1.0" ?>
+
+Here's how you could begin creating an XML document:
+
+
+
+ my $miniXMLDoc = XML::Mini::Document->new();
+ my $xmlRootNode = $miniXMLDoc->getRoot();
+ my $xmlHeader = $xmlRootNode->header('xml');
+ $xmlHeader->attribute('version', '1.0');
+
+This method was added in version 1.25.
+
+=head2 comment CONTENTS
+
+The comment() method allows you to add a new XML::Mini::Element::Comment to this
+element's list of children.
+
+Comments will return a <!-- CONTENTS --> string when the element's toString()
+method is called.
+
+Returns a reference to the newly appended XML::Mini::Element::Comment
+
+=head2 docType DEFINITION
+
+Append a new <!DOCTYPE DEFINITION [ ...]> element as a child of this
+element.
+
+Returns the appended DOCTYPE element. You will normally use the returned
+element to add ENTITY elements, like
+
+ my $newDocType = $xmlRoot->docType('spec SYSTEM "spec.dtd"');
+ $newDocType->entity('doc.audience', 'public review and discussion');
+
+=head2 entity NAME VALUE
+
+Append a new <!ENTITY NAME "VALUE"> element as a child of this
+element.
+
+Returns the appended ENTITY element.
+
+=head2 cdata CONTENTS
+
+Append a new <![CDATA[ CONTENTS ]]> element as a child of this element.
+Returns the appended CDATA element.
+
+=head2 getValue
+
+Returns a string containing the value of all the element's
+child XML::MiniNodes (and all the XML::MiniNodes contained within
+it's child Elements, recursively).
+
+
+=head2 getElement NAME [POSITION]
+
+Searches the element and it's children for an element with name NAME.
+
+Returns a reference to the first Element with name NAME,
+if found, NULL otherwise.
+
+NOTE: The search is performed like this, returning the first
+ element that matches:
+
+
+ - Check this element's immediate children (in order) for a match.
+ - Ask each immediate child (in order) to Element::getElement()
+ (each child will then proceed similarly, checking all it's immediate
+ children in order and then asking them to getElement())
+
+
+If a numeric POSITION parameter is passed, getElement() will return
+the POSITIONth element of name NAME (starting at 1). Thus, on document
+
+
+ <?xml version="1.0"?>
+ <people>
+ <person>
+ bob
+ </person>
+ <person>
+ jane
+ </person>
+ <person>
+ ralph
+ </person>
+ </people>
+
+$people->getElement('person') will return the element containing the text node
+'bob', while $people->getElement('person', 3) will return the element containing the
+text 'ralph'.
+
+
+
+
+=head2 getElementByPath PATH [POSITIONSARRAY]
+
+
+Attempts to return a reference to the (first) element at PATH
+where PATH is the path in the structure (relative to this element) to
+the requested element.
+
+For example, in the document represented by:
+
+ <partRateRequest>
+ <vendor>
+ <accessid user="myusername" password="mypassword" />
+ </vendor>
+ <partList>
+ <partNum>
+ DA42
+ </partNum>
+ <partNum>
+ D99983FFF
+ </partNum>
+ <partNum>
+ ss-839uent
+ </partNum>
+ </partList>
+ </partRateRequest>
+
+ $partRate = $xmlDocument->getElement('partRateRequest');
+
+ $accessid = $partRate->getElementByPath('vendor/accessid');
+
+Will return what you expect (the accessid element with attributes user = "myusername"
+and password = "mypassword").
+
+BUT be careful:
+ $accessid = $partRate->getElementByPath('partList/partNum');
+
+will return the partNum element with the value "DA42". To access other partNum elements you
+must either use the POSITIONSARRAY or the getAllChildren() method on the partRateRequest element.
+
+POSITIONSARRAY functions like the POSITION parameter to getElement(), but instead of specifying the
+position of a single element, you must indicate the position of all elements in the path. Therefore, to
+get the third part number element, you would use
+
+ my $thirdPart = $xmlDocument->getElementByPath('partRateRequest/partList/partNum', 1, 1, 3);
+
+The additional 1,1,3 parameters indicate that you wish to retrieve the 1st partRateRequest element in
+the document, the 1st partList child of partRateRequest and the 3rd partNum child of the partList element
+(in this instance, the partNum element that contains 'ss-839uent').
+
+Returns the Element reference if found, NULL otherwise.
+
+=head2 getAllChildren [NAME]
+
+Returns a reference to an array of all this element's Element children
+
+Note: although the Element may contain XML::MiniNodes as children, these are
+not part of the returned list.
+
+
+=head2 createChild ELEMENTNAME [VALUE]
+
+Creates a new Element instance and appends it to the list
+of this element's children.
+The new child element's name is set to ELEMENTNAME.
+
+If the optional VALUE (string or numeric) parameter is passed,
+the new element's text/numeric content will be set using VALUE.
+
+Returns a reference to the new child element
+
+
+=head2 appendChild CHILDELEMENT
+
+appendChild is used to append an existing Element object to
+this element's list.
+
+Returns a reference to the appended child element.
+
+NOTE: Be careful not to create loops in the hierarchy, eg
+
+ $parent->appendChild($child);
+ $child->appendChild($subChild);
+ $subChild->appendChild($parent);
+
+If you want to be sure to avoid loops, set the MINIXML_AVOIDLOOPS define
+to 1 or use the avoidLoops() method (will apply to all children added with createChild())
+
+
+=head2 prependChild CHILDELEMENT
+
+prependChild is used to add an existing Element object to
+this element's list. The added CHILDELEMENT will be prepended to the list, thus
+it will appear first in the XML output.
+
+Returns a reference to the prepended child element.
+
+See the note about creating loops in the above appendChild() description.
+
+
+=head2 insertChild CHILDELEMENT INDEX
+
+Inserts the child element at a specific location in this elements list of children.
+
+If INDEX is larger than numChildren(), the CHILDELEMENT will be added to the end of
+the list (same as appendChild() ).
+
+Returns the inserted child element.
+
+=head2 removeChild CHILDELEMENT
+
+Removes the element CHILDELEMENT from the list of this element's children, if it is
+found within this list.
+
+Returns the child element that was removed, else undef.
+
+=head2 removeAllChildren
+
+Clears the element's list of child elements. Returns an array ref of child elements
+that were removed.
+
+
+=head2 remove
+
+Removes this element from it's parent's list of children. The parent must be set for the
+element for this method to work - this can be done manually using the parent() method or
+automatically if $XML::Mini::AutoSetParent is true (set to false by default).
+
+
+
+
+=head2 parent NEWPARENT
+
+The parent() method is used to get/set the element's parent.
+
+If the NEWPARENT parameter is passed, sets the parent to NEWPARENT
+(NEWPARENT must be an instance of Element)
+
+Returns a reference to the parent Element if set, NULL otherwise.
+
+Note: This method is mainly used internally and you wouldn't normally need
+to use it.
+It get's called on element appends when $XML::Mini::AutoSetParent or
+$XML::Mini::AvoidLoops or avoidLoops() > 0
+
+=head2 avoidLoops SETTO
+
+The avoidLoops() method is used to get or set the avoidLoops flag for this element.
+
+When avoidLoops is true, children with parents already set can NOT be appended to any
+other elements. This is overkill but it is a quick and easy way to avoid infinite loops
+in the heirarchy.
+
+The avoidLoops default behavior is configured with the $XML::Mini::AvoidLoops variable but can be
+set on individual elements (and automagically all the element's children) with the
+avoidLoops() method.
+
+Returns the current value of the avoidLoops flag for the element.
+
+=head2 toString [SPACEOFFSET]
+
+toString returns an XML string based on the element's attributes,
+and content (recursively doing the same for all children)
+
+The optional SPACEOFFSET parameter sets the number of spaces to use
+after newlines for elements at this level (adding 1 space per level in
+depth). SPACEOFFSET defaults to 0.
+
+If SPACEOFFSET is passed as $XML::Mini::NoWhiteSpaces
+no \n or whitespaces will be inserted in the xml string
+(ie it will all be on a single line with no spaces between the tags.
+
+Returns the XML string.
+
+=head2 createNode NODEVALUE
+
+
+Private (?)
+
+Creates a new XML::MiniNode instance and appends it to the list
+of this element's children.
+The new child node's value is set to NODEVALUE.
+
+Returns a reference to the new child node.
+
+Note: You don't need to use this method normally - it is used
+internally when appending text() and such data.
+
+=head2 appendNode CHILDNODE
+
+
+appendNode is used to append an existing XML::MiniNode object to
+this element's list.
+
+Returns a reference to the appended child node.
+
+
+Note: You don't need to use this method normally - it is used
+internally when appending text() and such data.
+
+=head1 AUTHOR
+
+
+Copyright (C) 2002-2003 Patrick Deegan, Psychogenic Inc.
+
+Programs that use this code are bound to the terms and conditions of the GNU GPL (see the LICENSE file).
+If you wish to include these modules in non-GPL code, you need prior written authorisation
+from the authors.
+
+
+
+LICENSE
+
+ XML::Mini::Element module, part of the XML::Mini XML parser/generator package.
+ Copyright (C) 2002 Patrick Deegan
+ All rights reserved
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+
+Official XML::Mini site: http://minixml.psychogenic.com
+
+Contact page for author available at http://www.psychogenic.com/en/contact.shtml
+
+=head1 SEE ALSO
+
+
+XML::Mini, XML::Mini::Document
+
+http://minixml.psychogenic.com
+
+=cut
Added: packages/libxml-mini-perl/branches/upstream/current/lib/XML/Mini/Node.pm
===================================================================
--- packages/libxml-mini-perl/branches/upstream/current/lib/XML/Mini/Node.pm 2006-04-13 21:15:52 UTC (rev 2552)
+++ packages/libxml-mini-perl/branches/upstream/current/lib/XML/Mini/Node.pm 2006-04-13 21:19:04 UTC (rev 2553)
@@ -0,0 +1,193 @@
+package XML::Mini::Node;
+use strict;
+$^W = 1;
+use XML::Mini;
+use XML::Mini::TreeComponent;
+
+use vars qw ( $VERSION @ISA );
+
+push @ISA, qw ( XML::Mini::TreeComponent );
+$VERSION = '1.24';
+
+sub new
+{
+ my $class = shift;
+ my $value = shift;
+
+ my $self = {};
+ bless $self, ref $class || $class;
+
+ if (defined ($value))
+ {
+ if ($XML::Mini::IgnoreWhitespaces)
+ {
+ $value =~ s/^\s*(.*?)\s*$/$1/;
+ }
+
+ if ($XML::Mini::AutoEscapeEntities)
+ {
+ $value = XML::Mini->escapeEntities($value);
+ }
+
+ if ($XML::Mini::Debug)
+ {
+ XML::Mini->Log("Setting value of node to '$value'");
+ }
+
+ $self->{'_contents'} = $value;
+ }
+ return $self;
+}
+
+sub getValue
+{
+ my $self = shift;
+ if ($XML::Mini::Debug)
+ {
+ XML::Mini->Log("Returning value of node as '" . $self->{'_contents'} . "'");
+ }
+ return $self->{'_contents'};
+}
+
+sub text
+{
+ my $self = shift;
+ my $setToPrim = shift;
+ my $setToAlt = shift;
+
+ my $setTo = defined ($setToPrim) ? $setToPrim : $setToAlt;
+
+ if (defined ($setTo))
+ {
+ if ($XML::Mini::IgnoreWhitespaces)
+ {
+ $setTo =~ s/^\s*(.*?)\s*$/$1/;
+ }
+
+ if ($XML::Mini::AutoEscapeEntities)
+ {
+ $setTo = XML::Mini->escapeEntities($setTo);
+ }
+
+ if ($XML::Mini::Debug)
+ {
+ XML::Mini->Log("Setting text of node to '$setTo'");
+ }
+
+ $self->{'_contents'} = $setTo;
+ }
+ return $self->{'_contents'};
+}
+
+sub numeric
+{
+ my $self = shift;
+ my $setToPrim = shift;
+ my $setToAlt = shift;
+
+ my $setTo = defined ($setToPrim) ? $setToPrim : $setToAlt;
+
+ if (defined $setTo)
+ {
+ if ($setTo =~ m/^\s*[Ee\d\.\+-]+\s*$/)
+ {
+ return $self->text($setTo);
+ } else {
+ XML::Mini->Error("Node::numeric() Must pass a NUMERIC value to set ($setTo)");
+ }
+ }
+
+ return $self->{'_contents'};
+}
+
+sub toString
+{
+ my $self = shift;
+ my $depth = shift;
+
+ if ($XML::Mini::Debug)
+ {
+ XML::Mini->Log("Node::toString() call with depth $depth");
+ }
+
+ if ($depth == $XML::Mini::NoWhiteSpaces)
+ {
+ return $self->toStringNoWhiteSpaces();
+
+ }
+
+ my $spaces = $self->_spaceStr($depth);
+
+ my $retStr = $spaces;
+ $retStr .= "$self->{'_contents'}";
+ $retStr =~ s/\n\s*/\n$spaces/smg;
+
+ return $retStr;
+}
+
+sub toStringNoWhiteSpaces
+{
+ my $self = shift;
+ my $retStr = "$self->{'_contents'}";
+ return $retStr;
+}
+
+1;
+
+__END__
+
+=head1 class XML::Mini::Node
+
+Nodes are used as atomic containers for numerical and text data
+and act as leaves in the XML tree.
+
+They have no name or children.
+
+They always exist as children of XML::MiniElements.
+For example,
+<B>this text is bold</B>
+Would be represented as a XML::MiniElement named 'B' with a single
+child, a Node object which contains the string 'this text
+is bold'.
+
+a Node has
+
+
+ - a parent
+ - data (text OR numeric)
+
+
+=head2 getValue
+
+Returns the text or numeric value of this Node.
+
+
+=head2 text [SETTO [SETTOALT]]
+
+The text() method is used to get or set text data for this node.
+If SETTO is passed, the node's content is set to the SETTO string.
+
+If the optional SETTOALT is passed and SETTO is false, the
+node's value is set to SETTOALT.
+
+Returns this node's text, if set or NULL
+
+=head2 numeric [SETTO [SETTOALT]]
+
+The numeric() method is used to get or set numerical data for this node.
+
+If SETTO is passed, the node's content is set to the SETTO string.
+
+If the optional SETTOALT is passed and SETTO is NULL, the
+node's value is set to SETTOALT.
+
+Returns this node's text, if set or NULL
+
+=head2 toString [DEPTH]
+
+Returns this node's contents as a string.
+If the special DEPTH $XML::Mini::NoWhiteSpaces is passed,
+no whitespaces will be inserted.
+
+=cut
+
Added: packages/libxml-mini-perl/branches/upstream/current/lib/XML/Mini/TreeComponent.pm
===================================================================
--- packages/libxml-mini-perl/branches/upstream/current/lib/XML/Mini/TreeComponent.pm 2006-04-13 21:15:52 UTC (rev 2552)
+++ packages/libxml-mini-perl/branches/upstream/current/lib/XML/Mini/TreeComponent.pm 2006-04-13 21:19:04 UTC (rev 2553)
@@ -0,0 +1,166 @@
+package XML::Mini::TreeComponent;
+use strict;
+$^W = 1;
+
+use Data::Dumper;
+use XML::Mini;
+
+use vars qw ( $VERSION );
+$VERSION = '1.24';
+
+sub new
+{
+ my $class = shift;
+ my $self = {};
+ bless $self, ref $class || $class;
+ return $self;
+}
+
+sub name
+{
+ my $self = shift;
+ my $setTo = shift; # optionally set
+ return undef;
+}
+
+sub getElement
+{
+ my $self = shift;
+ my $name = shift;
+ return undef;
+}
+
+sub getValue
+{
+ my $self = shift;
+ return undef;
+}
+
+sub parent
+{
+ my $self = shift;
+ my $newParent = shift; # optionally set
+
+ if ($newParent)
+ {
+ my $ownType = ref $self;
+ my $type = ref $newParent;
+ if ($type && $type =~ /^$ownType/)
+ {
+ $self->{'_parent'} = $newParent;
+ } else {
+ return XML::Mini->Error("XML::MiniTreeComponent::parent(): Must pass an instance derived from "
+ . "XML::MiniTreeComponent to set.");
+ }
+ }
+ return $self->{'_parent'};
+}
+
+sub toString
+{
+ my $self = shift;
+ my $depth = shift || 0;
+ return undef;
+}
+
+sub dump
+{
+ my $self = shift;
+ return Dumper($self);
+}
+
+sub _spaceStr
+{
+ my $self = shift;
+ my $numSpaces = shift;
+ my $retStr = '';
+ if ($numSpaces)
+ {
+ $retStr = ' ' x $numSpaces;
+ }
+ return $retStr;
+}
+
+1;
+
+__END__
+
+=head1 NAME
+
+XML::Mini::TreeComponent - Perl implementation of the XML::Mini TreeComponent API.
+
+=head1 SYNOPSIS
+
+Don't use this class - only presents an interface for other derived classes.
+
+=head1 DESCRIPTION
+
+This class is only to be used as a base class
+for others.
+
+It presents the minimal interface we can expect
+from any component in the XML hierarchy.
+
+All methods of this base class
+simply return NULL except a little default functionality
+included in the parent() method.
+
+Warning: This class is not to be instatiated.
+Derive and override.
+
+=head2 parent [NEWPARENT]
+
+The parent() method is used to get/set the element's parent.
+
+If the NEWPARENT parameter is passed, sets the parent to NEWPARENT
+(NEWPARENT must be an instance of a class derived from XML::MiniTreeComponent)
+
+Returns a reference to the parent XML::MiniTreeComponent if set, NULL otherwise.
+
+
+=head2 toString [DEPTH]
+
+Return a stringified version of the XML representing
+this component and all sub-components
+
+=head2 dump
+
+Debugging aid, dump returns a nicely formatted dump of the current structure of the
+XML::Mini::TreeComponent-derived object.
+
+=head1 AUTHOR
+
+LICENSE
+
+ XML::Mini::TreeComponent module, part of the XML::Mini XML parser/generator package.
+ Copyright (C) 2002 Patrick Deegan
+ All rights reserved
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+
+Official XML::Mini site: http://minixml.psychogenic.com
+
+Contact page for author available at http://www.psychogenic.com/en/contact.shtml
+
+=head1 SEE ALSO
+
+
+XML::Mini, XML::Mini::Document, XML::Mini::Element
+
+http://minixml.psychogenic.com
+
+=cut
+
Added: packages/libxml-mini-perl/branches/upstream/current/lib/XML/Mini.pm
===================================================================
--- packages/libxml-mini-perl/branches/upstream/current/lib/XML/Mini.pm 2006-04-13 21:15:52 UTC (rev 2552)
+++ packages/libxml-mini-perl/branches/upstream/current/lib/XML/Mini.pm 2006-04-13 21:19:04 UTC (rev 2553)
@@ -0,0 +1,254 @@
+package XML::Mini;
+use strict;
+$^W = 1;
+
+use vars qw (
+ $AutoEscapeEntities
+ $AutoSetParent
+ $AvoidLoops
+ $CaseSensitive
+ $Debug
+ $IgnoreWhitespaces
+ $NoWhiteSpaces
+
+ $VERSION
+ );
+
+$VERSION = '1.28';
+
+$AvoidLoops = 0;
+$AutoEscapeEntities = 1;
+$Debug = 0;
+$IgnoreWhitespaces = 1;
+$CaseSensitive = 0;
+$AutoSetParent = 0;
+$NoWhiteSpaces = -999;
+
+sub Log
+{
+ my $class = shift;
+
+ print STDERR "XML::Mini LOG MESSAGE:" ;
+ print STDERR join(" ", @_) . "\n";
+}
+
+sub Error
+{
+ my $class = shift;
+
+ print STDERR "XML::Mini Error MESSAGE:" ;
+ print STDERR join(" ", @_) . "\n";
+
+ exit(254);
+}
+
+sub escapeEntities
+{
+ my $class = shift;
+ my $toencode = shift;
+
+ return undef unless (defined $toencode);
+
+ $toencode=~s/&/&/g;
+ $toencode=~s/\"/"/g;
+ $toencode=~s/>/>/g;
+ $toencode=~s/</</g;
+ $toencode=~s/([\xA0-\xFF])/"&#".ord($1).";"/ge;
+ return $toencode;
+}
+
+1;
+__END__
+
+=head1 NAME
+
+XML::Mini - Perl implementation of the XML::Mini XML create/parse interface.
+
+=head1 SYNOPSIS
+
+ use XML::Mini::Document;
+
+ use Data::Dumper;
+
+
+ ###### PARSING XML #######
+
+ # create a new object
+ my $xmlDoc = XML::Mini::Document->new();
+
+ # init the doc from an XML string
+ $xmlDoc->parse($XMLString);
+
+ # You may use the toHash() method to automatically
+ # convert the XML into a hash reference
+ my $xmlHash = $xmlDoc->toHash();
+
+ print Dumper($xmlHash);
+
+
+ # You can also manipulate the elements like directly, like this:
+
+ # Fetch the ROOT element for the document
+ # (an instance of XML::Mini::Element)
+ my $xmlRoot = $xmlDoc->getRoot();
+
+ # play with the element and its children
+ # ...
+ my $topLevelChildren = $xmlRoot->getAllChildren();
+
+ foreach my $childElement (@{$topLevelChildren})
+ {
+ # ...
+ }
+
+
+ ###### CREATING XML #######
+
+ # Create a new document from scratch
+
+ my $newDoc = XML::Mini::Document->new();
+
+ # This can be done easily by using a hash:
+ my $h = {
+ 'spy' => {
+ 'id' => '007',
+ 'type' => 'SuperSpy',
+ 'name' => 'James Bond',
+ 'email' => 'mi5 at london.uk',
+ 'address' => 'Wherever he is needed most',
+ },
+ };
+
+ $newDoc->fromHash($h);
+
+
+
+ # Or new XML can also be created by manipulating
+ #elements directly:
+
+ my $newDocRoot = $newDoc->getRoot();
+
+ # create the <? xml ?> header
+ my $xmlHeader = $newDocRoot->header('xml');
+ # add the version
+ $xmlHeader->attribute('version', '1.0');
+
+ my $person = $newDocRoot->createChild('person');
+
+ my $name = $person->createChild('name');
+ $name->createChild('first')->text('John');
+ $name->createChild('last')->text('Doe');
+
+ my $eyes = $person->createChild('eyes');
+ $eyes->attribute('color', 'blue');
+ $eyes->attribute('number', 2);
+
+ # output the document
+ print $newDoc->toString();
+
+
+This example would output :
+
+
+
+ <?xml version="1.0"?>
+ <person>
+ <name>
+ <first>
+ John
+ </first>
+ <last>
+ Doe
+ </last>
+ </name>
+ <eyes color="blue" number="2" />
+ </person>
+
+
+
+
+
+=head1 DESCRIPTION
+
+XML::Mini is a set of Perl classes that allow you to access XML data and create valid XML output with a tree-based hierarchy of elements. The MiniXML API has both Perl and PHP implementations.
+
+It provides an easy, object-oriented interface for manipulating XML documents and their elements. It is currently being used to send requests and understand responses from remote servers in Perl or PHP applications. An XML::Mini based parser is now being tested within the RPC::XML framework.
+
+XML::Mini does not require any external libraries or modules and is pure Perl. If available, XML::Mini will use the Text::Balanced module in order to escape limitations of the regex-only approach (eg "cross-nested" tag parsing).
+
+
+The Mini.pm module includes a number of variables you may use to tweak XML::Mini's behavior. These include:
+
+
+$XML::Mini::AutoEscapeEntities - when greater than 0, the values set for nodes are automatically escaped, thus
+$element->text('4 is > 3') will set the contents of the appended node to '4 is > 3'. Default setting is 1.
+
+
+$XML::Mini::IgnoreWhitespaces - when greater than 0, extraneous whitespaces will be ignored (maily useful when parsing). Thus
+<mytag> Hello There </mytag> will be parsed as containing a text node with contents 'Hello There' instead
+of ' Hello There '. Default setting is 1.
+
+
+$XML::Mini::CaseSensitive - when greater than 0, element names are treated as case sensitive. Thus, $element->getElement('subelement') and $element->getElement('SubElement') will be equivalent. Defaults to 0.
+
+
+=head1 Class methods
+
+
+=head2 escapeEntites TOENCODE
+
+This method returns ToENCODE with HTML sensitive values
+(eg '<', '>', '"', etc) HTML encoded.
+
+=cut
+
+=head2 Log MESSAGE
+
+Logs the message to STDERR
+
+=head2 Error MESSAGE
+
+Logs MESSAGE and exits the program, calling exit()
+
+
+=head1 AUTHOR
+
+Copyright (C) 2002-2003 Patrick Deegan, Psychogenic Inc.
+
+Programs that use this code are bound to the terms and conditions of the GNU GPL (see the LICENSE file).
+If you wish to include these modules in non-GPL code, you need prior written authorisation
+from the authors.
+
+
+LICENSE
+
+ XML::Mini module, part of the XML::Mini XML parser/generator package.
+ Copyright (C) 2002, 2003 Patrick Deegan, Psychogenic.com
+ All rights reserved
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+
+Official XML::Mini site: http://minixml.psychogenic.com
+
+Contact page for author available at http://www.psychogenic.com/
+
+=head1 SEE ALSO
+
+XML::Mini::Document, XML::Mini::Element
+
+http://minixml.psychogenic.com
+
+=cut
Added: packages/libxml-mini-perl/branches/upstream/current/t/01parseable.t
===================================================================
--- packages/libxml-mini-perl/branches/upstream/current/t/01parseable.t 2006-04-13 21:15:52 UTC (rev 2552)
+++ packages/libxml-mini-perl/branches/upstream/current/t/01parseable.t 2006-04-13 21:19:04 UTC (rev 2553)
@@ -0,0 +1,26 @@
+use Test;
+use strict;
+$^W = 1; # play nice with old perl
+
+BEGIN { plan tests=>1 }
+use XML::Mini;
+use XML::Mini::Document;
+use XML::Mini::Element;
+use XML::Mini::Node;
+use XML::Mini::TreeComponent;
+use XML::Mini::Element::CData;
+use XML::Mini::Element::Comment;
+use XML::Mini::Element::DocType;
+use XML::Mini::Element::Entity;
+
+require XML::Mini;
+require XML::Mini::Document;
+require XML::Mini::Element;
+require XML::Mini::Node;
+require XML::Mini::TreeComponent;
+require XML::Mini::Element::CData;
+require XML::Mini::Element::Comment;
+require XML::Mini::Element::DocType;
+require XML::Mini::Element::Entity;
+
+ok(1);
\ No newline at end of file
Added: packages/libxml-mini-perl/branches/upstream/current/t/02parsexml.t
===================================================================
--- packages/libxml-mini-perl/branches/upstream/current/t/02parsexml.t 2006-04-13 21:15:52 UTC (rev 2552)
+++ packages/libxml-mini-perl/branches/upstream/current/t/02parsexml.t 2006-04-13 21:19:04 UTC (rev 2553)
@@ -0,0 +1,62 @@
+use Test;
+use strict;
+$^W = 1; # play nice with old perl
+
+BEGIN { plan tests=> 46 }
+
+use FileHandle;
+require XML::Mini::Document;
+use strict;
+
+my $sample = './t/sample/vocpboxes.xml';
+my $numBoxes = 20;
+
+{
+ my $miniXML = XML::Mini::Document->new();
+
+ my $numchildren = $miniXML->fromFile($sample);
+
+ ok($numchildren, 2);
+
+ my $vocpBoxList = $miniXML->getElementByPath('VOCPBoxConfig/boxList') || ok(0);
+ ok(1);
+
+ $numchildren = $vocpBoxList->numChildren();
+
+ ok($numchildren, $numBoxes);
+
+
+ my $childList = $vocpBoxList->getAllChildren();
+
+ ok($childList);
+
+ ok(scalar @{$childList}, $numBoxes);
+
+ foreach my $child (@{$childList})
+ {
+
+ my $childName = $child->name();
+ ok($childName, '/^box$/', "boxList child with invalid name (should be 'box')");
+
+ my $boxnum = $child->attribute('number');
+
+ ok($boxnum, '/\d+$/', "box with invalid number (should be all digits)");
+
+ }
+
+
+ my $inputFileHandle = FileHandle->new();
+ unless ($inputFileHandle->open("<$sample"))
+ {
+ ok(0);
+ }
+
+ my $sampleFile = join('', $inputFileHandle->getlines());
+ $inputFileHandle->close();
+
+ my $xmlOut = $miniXML->toString();
+
+ ok($sampleFile, $xmlOut);
+
+}
+
Added: packages/libxml-mini-perl/branches/upstream/current/t/03genxml.t
===================================================================
--- packages/libxml-mini-perl/branches/upstream/current/t/03genxml.t 2006-04-13 21:15:52 UTC (rev 2552)
+++ packages/libxml-mini-perl/branches/upstream/current/t/03genxml.t 2006-04-13 21:19:04 UTC (rev 2553)
@@ -0,0 +1,88 @@
+use Test;
+use strict;
+$^W = 1; # play nice with old perl
+
+BEGIN { plan tests=> 101 }
+
+use XML::Mini::Document;
+use strict;
+
+my $expectedXML =
+ qq|<?xml version="1.0"?>\n|
+.qq| <tag1>\n|
+.qq| hola\n|
+.qq| </tag1>\n|
+.qq| <tag2 stuff="bla" />\n|
+.qq| <tag3 stuff="morestuff">\n|
+.qq| halo & hola\n|
+.qq| <inside joke="hah" />\n|
+.qq| </tag3>\n|
+.qq| <tag4 />\n\n|;
+
+{
+ my $miniXMLDoc = XML::Mini::Document->new();
+
+ my $xmlRootNode = $miniXMLDoc->getRoot();
+
+ ok($xmlRootNode);
+ my $xmlHeader = $xmlRootNode->header('xml');
+ $xmlHeader->attribute('version', '1.0');
+
+ my $tag1 = $xmlRootNode->createChild('tag1', 'hola');
+ ok($tag1);
+
+ my $tag2 = $xmlRootNode->createChild('tag2');
+ ok($tag2);
+ $tag2->attribute('stuff', 'bla');
+
+ my $orphan = $miniXMLDoc->createElement('tag3');
+ ok($orphan);
+ $orphan->text('halo & hola');
+ $xmlRootNode->appendChild($orphan);
+ $orphan->attribute('stuff', 'morestuff');
+
+ my $insideEl = $orphan->createChild('inside');
+ $insideEl->attribute('joke', 'hah');
+
+ my $tag4 = $xmlRootNode->createChild('tag4');
+
+ my $xmlOutput = $miniXMLDoc->toString();
+ ok($xmlOutput);
+
+ ok($xmlOutput, $expectedXML);
+
+ my $pathStr = '';
+ my $leafChild = $tag4;
+ for(my $i=0; $i<90; $i++)
+ {
+ $pathStr .= '/nested';
+ $leafChild = $leafChild->createChild('nested');
+ ok($leafChild);
+ }
+
+ $leafChild->text('--> Where Am I <--');
+
+ $pathStr =~ s|^/(.+)$|$1|;
+
+ my $foundElement = $xmlRootNode->getElementByPath($pathStr);
+ ok($foundElement);
+
+ my $text = $foundElement->getValue();
+ ok($text, '--> Where Am I <--');
+
+ my $removedChild = $xmlRootNode->removeChild($tag4);
+ my $newNumChildren = $xmlRootNode->numChildren();
+
+ ok($newNumChildren, 4);
+
+ my $prepended = $orphan->prependChild($removedChild);
+ ok($prepended);
+
+ my $retList = $orphan->removeAllChildren();
+ $newNumChildren = $orphan->numChildren();
+
+
+ ok($newNumChildren, 0);
+
+}
+
Added: packages/libxml-mini-perl/branches/upstream/current/t/04crossnested.t
===================================================================
--- packages/libxml-mini-perl/branches/upstream/current/t/04crossnested.t 2006-04-13 21:15:52 UTC (rev 2552)
+++ packages/libxml-mini-perl/branches/upstream/current/t/04crossnested.t 2006-04-13 21:19:04 UTC (rev 2553)
@@ -0,0 +1,41 @@
+use Test;
+use strict;
+$^W = 1; # play nice with old perl
+
+BEGIN { plan tests=> 2 }
+
+use FileHandle;
+require XML::Mini::Document;
+use strict;
+my $textBalancedUnavail;
+
+my $sample = './t/sample/xnested.xml';
+
+{
+eval "use Text::Balanced";
+if ($@)
+{
+ $textBalancedUnavail = 'Text::Balanced unavailable. Cross-nested XML *will* fail.';
+}
+ # Text::Balanced is unavailable
+ $XML::Mini::AutoEscapeEntities = 0;
+ my $miniXML = XML::Mini::Document->new();
+
+ my $numchildren = $miniXML->fromFile($sample);
+
+ skip($textBalancedUnavail, $numchildren, 4);
+ my $inputFileHandle = FileHandle->new();
+ unless ($inputFileHandle->open("<$sample"))
+ {
+ ok(0);
+ }
+
+ my $sampleFile = join('', $inputFileHandle->getlines());
+ $inputFileHandle->close();
+
+ my $xmlOut = $miniXML->toString();
+
+ skip($textBalancedUnavail, $sampleFile, $xmlOut);
+
+}
+
Added: packages/libxml-mini-perl/branches/upstream/current/t/05parsefunc.t
===================================================================
--- packages/libxml-mini-perl/branches/upstream/current/t/05parsefunc.t 2006-04-13 21:15:52 UTC (rev 2552)
+++ packages/libxml-mini-perl/branches/upstream/current/t/05parsefunc.t 2006-04-13 21:19:04 UTC (rev 2553)
@@ -0,0 +1,49 @@
+use Test;
+use strict;
+$^W = 1; # play nice with old perl
+
+BEGIN { plan tests=> 4 }
+
+use FileHandle;
+require XML::Mini::Document;
+use strict;
+
+
+# Tests the various values passed through the parse() call
+
+my $sample = './t/sample/vocpboxes.xml';
+my $numBoxes = 20;
+
+{
+ my $miniXML = XML::Mini::Document->new();
+
+ my $numchildren = $miniXML->parse($sample);
+
+ ok($numchildren, 2);
+
+ $miniXML->init();
+ if (! open(INFILE, "<$sample"))
+ {
+ ok(0);
+ }
+
+ $numchildren = $miniXML->parse(*INFILE);
+ ok($numchildren, 2);
+
+ $miniXML->init();
+ my $fhObj = FileHandle->new();
+ $fhObj->open($sample);
+ $numchildren = $miniXML->parse($fhObj);
+ ok($numchildren, 2);
+
+
+ $miniXML->init();
+ $fhObj = FileHandle->new();
+ $fhObj->open("<$sample");
+ my $contents = join('', $fhObj->getlines());
+ $fhObj->close();
+ $numchildren = $miniXML->parse($contents);
+ ok($numchildren, 2);
+
+}
+
Added: packages/libxml-mini-perl/branches/upstream/current/t/06getelem.t
===================================================================
--- packages/libxml-mini-perl/branches/upstream/current/t/06getelem.t 2006-04-13 21:15:52 UTC (rev 2552)
+++ packages/libxml-mini-perl/branches/upstream/current/t/06getelem.t 2006-04-13 21:19:04 UTC (rev 2553)
@@ -0,0 +1,51 @@
+use Test;
+use strict;
+$^W = 1; # play nice with old perl
+
+BEGIN { plan tests=> 5 }
+
+use FileHandle;
+require XML::Mini::Document;
+use strict;
+
+my $XMLString =
+qq|<?xml version="1.0"?>
+ <people> <person>
+ bob
+ </person> <person> ralph </person> <person> cindy
+ </person>
+ <person> <name> <first>
+ Noam </first> <last>
+ Chomsky </last> </name> <hair color="brown" /> </person>
+ </people>
+|;
+
+
+{
+ my $miniXML = XML::Mini::Document->new();
+
+ my $numchildren = $miniXML->parse($XMLString);
+
+ ok($numchildren, 2);
+
+ my $name1 = $miniXML->getElement('person')->getValue() || ok(0);
+
+ ok($name1, 'bob');
+
+ my $name3 = $miniXML->getElement('person', 3)->getValue() || ok(0);
+
+ ok($name3, 'cindy');
+
+
+ my $name2 = $miniXML->getElementByPath('people/person', 1, 2)->getValue();
+
+ ok($name2, 'ralph');
+
+ my $people = $miniXML->getElement('people') || ok(0);
+
+ my $noam = $people->getElementByPath('person/name/first',4)->getValue();
+
+ ok($noam, 'Noam');
+
+}
+
Added: packages/libxml-mini-perl/branches/upstream/current/t/07ToFromHash.t
===================================================================
--- packages/libxml-mini-perl/branches/upstream/current/t/07ToFromHash.t 2006-04-13 21:15:52 UTC (rev 2552)
+++ packages/libxml-mini-perl/branches/upstream/current/t/07ToFromHash.t 2006-04-13 21:19:04 UTC (rev 2553)
@@ -0,0 +1,194 @@
+use Test;
+use strict;
+$^W = 1; # play nice with old perl
+
+BEGIN { plan tests=> 11 }
+
+use FileHandle;
+require XML::Mini::Document;
+use Data::Dumper;
+use strict;
+
+my $sample = './t/sample/vocpboxes.xml';
+my $numberOfBoxes = 20;
+
+{
+ my $miniXML = XML::Mini::Document->new();
+
+ my $numchildren = $miniXML->parse($sample);
+
+ ok($numchildren, 2);
+
+ my $XMLhash = $miniXML->toHash();
+
+ my $boxes = $XMLhash->{'VOCPBoxConfig'}->{'boxList'}->{'box'};
+ ok($boxes);
+
+ ok(ref $boxes, 'ARRAY');
+ my $numBoxes = @{$boxes};
+
+ ok($numBoxes, $numberOfBoxes);
+
+ #print STDERR Dumper($XMLhash);
+ my $attribs = {
+ 'attributes' => {
+ '-all' => [ 'id', 'number', 'version'],
+ 'email' => 'type',
+ },
+ };
+
+ my $newDocHash = {
+ 'person' => [
+ {
+ 'id' => '001',
+ 'name' => 'Pat D',
+ 'type' => 'SuperFly SuperSpy',
+ 'email' => [
+ {
+ 'type' => 'public',
+ '-content' => 'spam-me at psychogenic.com',
+ },
+ 'noattrib at example.com',
+ {
+ 'type' => 'private',
+ '-content' => 'dontspam at psychogenic.com',
+ }
+ ],
+ 'address' => '1234 Skid Row, Irvine, CA 92618',
+ },
+ {
+ 'id' => '007',
+ 'type' => 'SuperSpy',
+ 'name' => 'James Bond',
+ 'email' => 'mi5 at london.uk',
+ 'address' => 'Wherever he is needed most',
+ },
+
+ {
+ 'id' => '006',
+ 'number' => 6,
+ 'name' => 'Number 6',
+ 'email' => 'prisoner at aol.com',
+ 'comment' => 'I am not a man, I am a free number',
+ 'address' => '6 Prison Island Road, Prison Island, Somewhere',
+ }
+ ],
+
+ };
+
+ $numchildren = $miniXML->fromHash($newDocHash, $attribs);
+
+ ok($numchildren, 3);
+
+
+
+
+my $xmlString =
+qq|
+<people>
+ <person id="007">
+ <email>
+ mi5\@london.uk
+ </email>
+ <name>
+ James Bond
+ </name>
+ <address>
+ Wherever he is needed most
+ </address>
+ <type>
+ SuperSpy
+ </type>
+ </person>
+ <person id="006" number="6">
+ <comment>
+ I am not a man, I am a free number
+ </comment>
+ <name>
+ Number 6
+ </name>
+ <email type="private">prisoner\@aol.com</email>
+ <address>
+ 6 Prison Island Road, Prison Island, Somewhere
+ </address>
+ </person>
+</people>
+|;
+
+ $miniXML->init();
+ $numchildren = $miniXML->parse($xmlString);
+
+
+ ok($numchildren, 1);
+
+ my $toHash = $miniXML->toHash();
+ # print STDERR Dumper($toHash);
+
+ ok($toHash->{'people'}->{'person'}->[0]->{'id'}, '007');
+
+ ok($toHash->{'people'}->{'person'}->[1]->{'id'}, '006');
+
+
+ my $options = {
+ 'attributes' => {
+ 'spy' => 'id',
+ 'email' => 'type',
+ 'friend' => ['name', 'age'],
+ }
+ };
+
+
+ my $h = {
+
+ 'spy' => {
+ 'id' => '007',
+ 'type' => 'SuperSpy',
+ 'name' => 'James Bond',
+ 'email' => {
+ 'type' => 'private',
+ '-content' => 'mi5 at london.uk',
+
+ },
+ 'address' => {
+ 'type' => 'residential',
+ '-content' => 'Wherever he is needed most',
+ },
+
+ 'friend' => [
+ {
+ 'name' => 'claudia',
+ 'age' => 25,
+ 'type' => 'close',
+ },
+
+ {
+ 'name' => 'monneypenny',
+ 'age' => '40something',
+ 'type' => 'tease',
+ },
+
+ {
+ 'name' => 'Q',
+ 'age' => '10E4',
+ 'type' => 'pain',
+ }
+ ],
+
+ },
+ };
+
+
+
+ $numchildren = $miniXML->fromHash($h, $options);
+
+ ok($numchildren, 1);
+
+ my $spyname = $miniXML->getElementByPath('spy/name');
+ ok($spyname);
+
+ my $name = $spyname->getValue();
+
+ ok($name, 'James Bond');
+
+}
+
Added: packages/libxml-mini-perl/branches/upstream/current/t/sample/vocpboxes.xml
===================================================================
--- packages/libxml-mini-perl/branches/upstream/current/t/sample/vocpboxes.xml 2006-04-13 21:15:52 UTC (rev 2552)
+++ packages/libxml-mini-perl/branches/upstream/current/t/sample/vocpboxes.xml 2006-04-13 21:19:04 UTC (rev 2553)
@@ -0,0 +1,304 @@
+<?xml version="1.0"?>
+ <VOCPBoxConfig>
+ <boxList>
+ <box number="001">
+ <message>
+ root.rmd
+ </message>
+ <testtag />
+ <testtag />
+ <testtag myattr="somevalue" />
+ <testtag />
+ <testtag myattr="someothervalue">
+ There are lots of test tags here, it would seem...
+ </testtag>
+ <testtag />
+ <owner>
+ root
+ </owner>
+ <branch>
+ 0=998,1=011,2=012
+ </branch>
+ </box>
+ <box number="011">
+ <message>
+ menu_en.rmd
+ </message>
+ <owner>
+ pat
+ </owner>
+ <branch>
+ 0=998,1=101,2=556,3=201,4=301,9=001
+ </branch>
+ </box>
+ <box number="012">
+ <message>
+ menu_fr.rmd
+ </message>
+ <owner>
+ pat
+ </owner>
+ <branch>
+ 0=998,1=557,2=102,3=202,4=302,9=001
+ </branch>
+ </box>
+ <box number="100">
+ <type>
+ mail
+ </type>
+ <owner>
+ pat
+ </owner>
+ <email>
+ someuser at psychogenic.com
+ </email>
+ </box>
+ <box number="101">
+ <message>
+ generic_en.rmd
+ </message>
+ <autojump>
+ 100
+ </autojump>
+ </box>
+ <box number="102">
+ <message>
+ pat_fr.rmd
+ </message>
+ <autojump>
+ 100
+ </autojump>
+ </box>
+ <box number="150">
+ <message>
+ system/pager.rmd
+ </message>
+ <type>
+ pager
+ </type>
+ <owner>
+ root
+ </owner>
+ <email>
+ someuser at psychogenic.com
+ </email>
+ </box>
+ <box number="201">
+ <message>
+ generic_en.rmd
+ </message>
+ <type>
+ group
+ </type>
+ <members>
+ 100,555
+ </members>
+ </box>
+ <box number="202">
+ <message>
+ generic_fr.rmd
+ </message>
+ <type>
+ group
+ </type>
+ <members>
+ 100,555
+ </members>
+ </box>
+ <box number="300">
+ <type>
+ script
+ </type>
+ <owner>
+ root
+ </owner>
+ <autojump>
+ 001
+ </autojump>
+ <script>
+ /usr/local/vocp/bin/toggleEmail2Vm.pl
+ </script>
+ <input>
+ raw
+ </input>
+ <return>
+ tts
+ </return>
+ </box>
+ <box number="301">
+ <message>
+ generic_en.rmd
+ </message>
+ <type>
+ group
+ </type>
+ <members>
+ 100,555
+ </members>
+ </box>
+ <box number="302">
+ <message>
+ generic_fr.rmd
+ </message>
+ <type>
+ group
+ </type>
+ <members>
+ 100,555
+ </members>
+ </box>
+ <box number="400">
+ <type>
+ faxondemand
+ </type>
+ <file2fax>
+ /usr/local/vocp/faxtest.g3
+ </file2fax>
+ </box>
+ <box number="500">
+ <type>
+ script
+ </type>
+ <owner>
+ pat
+ </owner>
+ <autojump>
+ 001
+ </autojump>
+ <script>
+ /var/spool/voice/commands/motd.pl
+ </script>
+ <return>
+ exit
+ </return>
+ </box>
+ <box number="555">
+ <type>
+ mail
+ </type>
+ <owner>
+ fireball
+ </owner>
+ <email>
+ otheruser at psychogenic.com
+ </email>
+ </box>
+ <box number="556">
+ <message>
+ helene_en.rmd
+ </message>
+ <owner>
+ fireball
+ </owner>
+ <autojump>
+ 555
+ </autojump>
+ </box>
+ <box number="557">
+ <message>
+ helene_fr.rmd
+ </message>
+ <owner>
+ fireball
+ </owner>
+ <autojump>
+ 555
+ </autojump>
+ </box>
+ <box number="600">
+ <type>
+ command
+ </type>
+ <owner>
+ root
+ </owner>
+ <commandList>
+ <command selection="100">
+ <input>
+ text
+ </input>
+ <return>
+ output
+ </return>
+ <run>
+ ip.pl
+ </run>
+ </command>
+ <command selection="150">
+ <input>
+ none
+ </input>
+ <return>
+ output
+ </return>
+ <run>
+ ip.pl eth0 hohohohoho 3rdparam
+ </run>
+ </command>
+ <command selection="200">
+ <input>
+ none
+ </input>
+ <return>
+ tts
+ </return>
+ <run>
+ motd.pl
+ </run>
+ </command>
+ <command selection="250">
+ <input>
+ raw
+ </input>
+ <return>
+ output
+ </return>
+ <run>
+ echo.pl
+ </run>
+ </command>
+ </commandList>
+ </box>
+ <box number="666">
+ <type>
+ command
+ </type>
+ <owner>
+ root
+ </owner>
+ <commandList>
+ <command selection="100">
+ <input>
+ none
+ </input>
+ <return>
+ output
+ </return>
+ <run>
+ date.pl
+ </run>
+ </command>
+ <command selection="200">
+ <input>
+ none
+ </input>
+ <return>
+ exit
+ </return>
+ <run>
+ date.pl
+ </run>
+ </command>
+ </commandList>
+ </box>
+ <box number="998">
+ <message>
+ system/goodbye.rmd
+ </message>
+ <type>
+ exit
+ </type>
+ </box>
+ </boxList>
+ </VOCPBoxConfig>
+
Added: packages/libxml-mini-perl/branches/upstream/current/t/sample/xnested.xml
===================================================================
--- packages/libxml-mini-perl/branches/upstream/current/t/sample/xnested.xml 2006-04-13 21:15:52 UTC (rev 2552)
+++ packages/libxml-mini-perl/branches/upstream/current/t/sample/xnested.xml 2006-04-13 21:19:04 UTC (rev 2553)
@@ -0,0 +1,46 @@
+<?xml version="1.0"?>
+ <?xml-stylesheet href="doc.xsl" type="text/xsl"?>
+ <!--
+ this test checks cross nested tags, ie <a><b><a>..</a></b></a>
+ -->
+ <methodResponse>
+ <params>
+ <param>
+ <value>
+ <array>
+ <data>
+ <value>
+ <i4>
+ 12
+ </i4>
+ </value>
+ <value>
+ <string>
+ Egypt
+ </string>
+ </value>
+ <value>
+ <boolean>
+ 0
+ </boolean>
+ </value>
+ <value>
+ <data>
+ <value>
+ <data>
+ <value>
+ <i4>
+ -31
+ </i4>
+ </value>
+ </data>
+ </value>
+ </data>
+ </value>
+ </data>
+ </array>
+ </value>
+ </param>
+ </params>
+ </methodResponse>
+
More information about the Pkg-perl-cvs-commits
mailing list