XML-XUpdate-LibXML-0.6.0/0000755001407700135600000000000010240670274014673 5ustar pajasufal00000000000000XML-XUpdate-LibXML-0.6.0/lib/0000755001407700135600000000000010240670274015441 5ustar pajasufal00000000000000XML-XUpdate-LibXML-0.6.0/lib/XML/0000755001407700135600000000000010240670274016101 5ustar pajasufal00000000000000XML-XUpdate-LibXML-0.6.0/lib/XML/Normalize/0000755001407700135600000000000010240670274020041 5ustar pajasufal00000000000000XML-XUpdate-LibXML-0.6.0/lib/XML/Normalize/LibXML.pm0000644001407700135600000001012507763350212021470 0ustar pajasufal00000000000000# $Id: LibXML.pm,v 1.8 2003/12/03 12:01:14 pajas Exp $ package XML::Normalize::LibXML; use strict; use Exporter; use XML::LibXML; use XML::LibXML::Iterator; use vars qw(@ISA @EXPORT_OK $VERSION); BEGIN { @ISA = qw(Exporter); @EXPORT_OK = qw(trim xml_normalize xml_strip_whitespace xml_strip_element); $VERSION='0.2' } sub trim { my ($text)=@_; $text=~s/^\s*//; $text=~s/\s*$//; return $text; } sub xml_normalize { my ($node) = @_; my $prev = undef; # previous Text node foreach my $node ($node->childNodes()) { my $type = $node->nodeType; if ($type == XML::LibXML::XML_TEXT_NODE) { if ($prev) { $prev->setData($prev->getData().$node->getData()); $node->unbindNode(); } else { $prev=$node; } } else { $prev = undef; if ($type == XML::LibXML::XML_ELEMENT_NODE) { xml_normalize($node); } } } } sub xml_strip_whitespace_text_node { my ($node)=@_; if ($node->nodeType() == XML::LibXML::XML_TEXT_NODE) { my $data=trim($node->getData()); if ($data ne "") { $node->setData($data); } else { $node->unbindNode(); } } } sub xml_strip_whitespace_attributes { my ($node)=@_; if ($node->nodeType() == XML::LibXML::XML_ELEMENT_NODE) { foreach my $attr ($node->attributes()) { $node->setValue(trim($node->getValue())); } } } sub xml_strip_whitespace { my ($dom, $strip_attributes)=@_; xml_normalize($dom); my $iter= XML::LibXML::Iterator->new( $dom ); if ($strip_attributes) { $iter->iterate(sub { xml_strip_whitespace_attributes($_[1]); xml_strip_whitespace_text_node($_[1]); }); } else { $iter->iterate(sub { xml_strip_whitespace_text_node($_[1]); }); } } sub xml_strip_element { my ($node)=@_; return unless $node->nodeType == XML::LibXML::XML_ELEMENT_NODE; my $f = $node->firstChild; while ($f and $f->nodeType == XML::LibXML::XML_TEXT_NODE and $f->getData =~ /^\s/) { my $data=$f->getData(); $data=~s/^\s+//; if ($data ne "") { $f->setData($data); last; } else { $f->unbindNode(); $f = $node->firstChild; } } my $f = $node->lastChild; while ($f and $f->nodeType == XML::LibXML::XML_TEXT_NODE and $f->getData =~ /\s$/) { my $data=$f->getData(); $data=~s/\s+$//; if ($data ne "") { $f->setData($data); last; } else { $f->unbindNode(); $f = $node->lastChild; } } } 1; __END__ =pod =head1 NAME XML::Normalize::LibXML - simple whitespace striping functions =head1 SYNOPSIS use XML::Normalize::LibXML qw(trim xml_normalize xml_strip_whitespace); $greeting=trim(" hallo world "); # returns "hallo world" xml_normalize($dom->getDocumentElement()); xml_strip_whitespace($dom->getDocumentElement()); =head1 DESCRIPTION This module provides simple whitespace striping and text-node normalizing functions. =head2 C Returns the string with any whitespace occuring at its beginning or end removed. =head2 C Puts all Text nodes in the full depth of the sub-tree underneath this Element into a normal form where only markup (e.g., tags, comments, processing instructions, CDATA sections, and entity references) separates Text nodes, i.e., there are no adjacent Text nodes. This can be used to ensure that the DOM view of a document is the same as if it were saved and re-loaded, and is useful when operations (such as XPointer lookups) that depend on a particular document tree structure are to be used. =head2 C Normalizes the subtree and trims whitespace from all Text nodes within the subtree. If the optional argument $include_attributes is defined and non-zero, this function trims whitespace also from all Attribute nodes. =head2 C Removes leading and trailing whitespace from a given element. =head1 AUTHOR Petr Pajas, pajas@matfyz.cz =head1 COPYRIGHT Copyright 2002-2003 Petr Pajas, All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 SEE ALSO L =cut XML-XUpdate-LibXML-0.6.0/lib/XML/XUpdate/0000755001407700135600000000000010240670274017453 5ustar pajasufal00000000000000XML-XUpdate-LibXML-0.6.0/lib/XML/XUpdate/LibXML.pm0000644001407700135600000003254110240670232021077 0ustar pajasufal00000000000000# $Id: LibXML.pm,v 1.15 2005/05/12 15:04:58 pajas Exp $ package XML::XUpdate::LibXML; use XML::LibXML; use XML::LibXML::XPathContext; use strict; use vars qw(@ISA $debug $VERSION); BEGIN { $debug=0; $VERSION = '0.6.0'; } sub strip_space { my ($text)=@_; $text=~s/^\s*//; $text=~s/\s*$//; return $text; } sub new { my $class=(ref($_[0]) || $_[0]); my $var_pool = {}; my $xpc = XML::LibXML::XPathContext->new(); $xpc->registerVarLookupFunc(\&_get_var,$var_pool); return bless [$var_pool, "http://www.xmldb.org/xupdate", $xpc ], $class; } sub registerNs { my ($self,$prefix, $uri)=@_; $self->[2]->registerNs($prefix,$uri); } sub init { my ($self,$doc)=@_; $self->[2]->setContextNode($doc); } sub _context { my ($self,$name,$value)=@_; return $self->[2]; } sub _set_var { my ($self,$name,$value)=@_; print STDERR "DEBUG: Storing $name as ",ref($value),"\n" if $debug; $self->[0]->{$name}=$value; } sub _get_var { my ($data,$name)=@_; return $data->{$name}; } sub set_namespace { my ($self,$URI)=@_; $self->[1]=$URI; } sub namespace { my ($self)=@_; return $self->[1]; } sub process { my ($self,$dom,$updoc)=@_; return unless ref($self); $self->init($dom); print STDERR "DEBUG: Updating ",$dom->nodeName,"\n" if $debug; foreach my $command ($updoc->getDocumentElement()->childNodes()) { if ($command->nodeType == XML::LibXML::XML_ELEMENT_NODE) { if (lc($command->getNamespaceURI()) eq $self->namespace()) { print STDERR "DEBUG: applying ",$command->toString(),"\n" if $debug; $self->xupdate_command($dom,$command); } else { print STDERR "DEBUG: Ignorint element ",$command->toString(),"\n" if $debug; } } } } sub get_text { my ($self,$node)=@_; my $text=""; foreach ($node->childNodes()) { if ($_->nodeType() == XML::LibXML::XML_TEXT_NODE || $_->nodeType() == XML::LibXML::XML_CDATA_SECTION_NODE) { $text.=$_->getData(); } } return strip_space($text); } sub add_attribute { my ($self, $node, $attr_node)=@_; $node->setAttributeNS($attr_node->getNamespaceURI, $attr_node->getName(), $attr_node->getValue); } sub append { my ($self,$node,$results)=@_; foreach (@$results) { if ($_->nodeType == XML::LibXML::XML_ATTRIBUTE_NODE) { $self->add_attribute($node,$_); } else { $node->appendChild($_); } } } sub insert_after { my ($self,$node,$results)=@_; if ($node->nodeType == XML::LibXML::XML_ATTRIBUTE_NODE) { $self->append($node->getOwnerElement(),$results); } else { foreach (reverse @$results) { if ($_->nodeType == XML::LibXML::XML_ATTRIBUTE_NODE) { $self->add_attribute($node->parentNode(),$_); } else { $node->parentNode()->insertAfter($_,$node); } } } } sub insert_before { my ($self,$node,$results)=@_; if ($node->nodeType == XML::LibXML::XML_ATTRIBUTE_NODE) { $self->append($node->getOwnerElement(),$results); } else { foreach (@$results) { if ($_->nodeType == XML::LibXML::XML_ATTRIBUTE_NODE) { $self->add_attribute($node->parentNode(),$_); } else { $node->parentNode()->insertBefore($_,$node); } } } } sub append_child { my ($self,$node,$results,$child)=@_; return unless @$results; if ($child ne "") { # XUpdate WD is weird: # child=1 should mean make the new node 1st child # child=last() should mean make new node last child # but if there are n children before insertion, # last() evaluates to n but they want the new node # to be (n+1)th. # so we must add it first, then calculate the position: my $ctxt = $self->_context(); $self->append($node,$results); my ($ref)=$ctxt->findnodes("node()[$child]",$node); return unless $ref; # check whether we should move results before $ref node foreach (@$results) { return if $ref->isSameNode($_); } # now move them foreach (@$results) { $_->unbindNode(); $node->insertBefore($_,$ref); } } else { $self->append($node,$results); } } sub update { my ($self,$node,$results)=@_; if ($node->nodeType == XML::LibXML::XML_TEXT_NODE || $node->nodeType == XML::LibXML::XML_CDATA_SECTION_NODE) { $self->insert_after($node,$results); $node->unbindNode(); } elsif ($node->nodeType == XML::LibXML::XML_ATTRIBUTE_NODE || $node->nodeType == XML::LibXML::XML_PI_NODE) { $node->setValue(strip_space(join "", map { $_->to_literal() } @$results)); } elsif ($node->nodeType == XML::LibXML::XML_ELEMENT_NODE) { foreach ($node->childNodes()){ $_->unbindNode(); } $self->append($node,$results); } } sub remove { my ($self, $node)=@_; $node->unbindNode(); } sub rename { my ($self,$node,$name)=@_; $node->setName($name); } sub process_instructions { my ($self, $dom, $command)=@_; my @result=(); foreach my $inst ($command->childNodes()) { print STDERR "DEBUG: Instruction ",$command->toString(),"\n" if $debug; if ( $inst->nodeType == XML::LibXML::XML_ELEMENT_NODE ) { if ( $inst->getLocalName() eq 'element' ) { my $new; if ($inst->hasAttribute('namespace') and $inst->getAttribute('name')=~/:/) { $new=$dom->getOwnerDocument()->createElementNS( $inst->getAttribute('namespace'), $inst->getAttribute('name') ); } else { $new=$dom->getOwnerDocument()->createElement($inst->getAttribute('name')); } $self->append($new,$self->process_instructions($dom,$inst)); push @result,$new; } elsif ( $inst->getLocalName() eq 'attribute' ) { if ($inst->hasAttribute('namespace') and $inst->getAttribute('name')=~/:/) { my $att= $dom->getOwnerDocument()-> createAttributeNS( $inst->getAttribute('namespace'), $inst->getAttribute('name') ); $att->setValue($self->get_text($inst)); push @result,$att; } else { my $att= $dom->getOwnerDocument()-> createAttribute( $inst->getAttribute('name') ); $att->setValue($self->get_text($inst)); push @result,$att; } } elsif ( $inst->getLocalName() eq 'text' ) { push @result,$dom->getOwnerDocument()->createTextNode($self->get_text($inst)); } elsif ( $inst->getLocalName() eq 'processing-instruction' ) { push @result,$dom->getOwnerDocument()->createProcessingInstruction( $inst->getAttribute('name'), $self->get_text($inst) ); } elsif ( $inst->getLocalName() eq 'comment' ) { push @result,$dom->getOwnerDocument()->createComment($self->get_text($inst)); } elsif ( $inst->getLocalName() eq 'value-of' ) { my $value=$self->get_select($dom,$inst); if ($value->isa('XML::LibXML::NodeList')) { push @result, map { $_->cloneNode(1) }$value->get_nodelist; } else { push @result,$dom->getOwnerDocument()->createTextNode($value->to_literal()); } } else { # not in XUpdate DTD but in examples of XUpdate WD push @result,$dom->getOwnerDocument()->importNode($inst) unless (lc($inst->getNamespaceURI) eq $self->namespace()); } } elsif ( $inst->nodeType == XML::LibXML::XML_CDATA_SECTION_NODE || $inst->nodeType == XML::LibXML::XML_TEXT_NODE) { push @result,$dom->getOwnerDocument()->importNode($inst); } } return \@result; } sub get_select { my ($self,$dom,$node)=@_; my $xpath=$node->getAttribute('select'); if ($xpath eq "") { die "Error: Required attribute select is missing or empty at:\n". $node->toString()."\nAborting!\n"; } return $self->_context->find($xpath); } sub get_test { my ($self,$dom,$node)=@_; my $xpath=$node->getAttribute('test'); if ($xpath eq "") { die "Error: Required attribute test is missing or empty at:\n". $node->toString()."\nAborting!\n"; } return $self->_context->find($xpath); } sub xupdate_command { my ($self,$dom,$command)=@_; return unless ($command->getType == XML::LibXML::XML_ELEMENT_NODE); if ($command->getLocalName() eq 'variable') { my $select=$self->get_select($dom,$command); $self->_set_var($command->getAttribute('name'), $select); } elsif ($command->getLocalName() eq 'if') { # xu:if my $test=$self->get_test($dom,$command); if ($test) { print STDERR "DEBUG: Conditional execution of ",$dom->nodeName,"\n" if $debug; foreach my $subcommand ($command->childNodes()) { if ($subcommand->nodeType == XML::LibXML::XML_ELEMENT_NODE) { if (lc($subcommand->getNamespaceURI()) eq $self->namespace()) { print STDERR "DEBUG: Applying ",$subcommand->toString(),"\n" if $debug; $self->xupdate_command($dom,$subcommand); } else { print STDERR "DEBUG: Ignoring element ",$subcommand->toString(),"\n" if $debug; } } } } } else { my $select=$self->get_select($dom,$command); if ($select->isa('XML::LibXML::NodeList')) { my @refnodes=$select->get_nodelist(); if (@refnodes) { # xu:insert-after if ($command->getLocalName eq 'insert-after') { foreach (@refnodes) { $self->insert_after($_, $self->process_instructions($dom,$command)); } # xu:insert-before } elsif ($command->getLocalName eq 'insert-before') { foreach (@refnodes) { $self->insert_before($_, $self->process_instructions($dom,$command)); } # xu:append } elsif ($command->getLocalName eq 'append') { foreach (@refnodes) { my $results=$self->process_instructions($dom,$command); my $child=$command->getAttribute('child'); $self->append_child($_,$results,$child); } # xu:update } elsif ($command->getLocalName eq 'update') { foreach (@refnodes) { my $results=$self->process_instructions($dom,$command); # Well, XUpdate WD is not very specific about this. # The content of this element should be PCDATA only. # I'm extending WD by allowing instruction list. $self->update($_,$results); } # xu:remove } elsif ($command->getLocalName eq 'remove') { foreach (@refnodes) { $self->remove($_); } # xu:rename } elsif ($command->getLocalName eq 'rename') { foreach (@refnodes) { $self->rename($_,$self->get_text($command)); } } } } else { die "XPath does not lead to a nodelist: ",$command->getAttribute('select'),"\n"; } } } 1; __END__ =pod =head1 NAME XML::XUpdate::LibXML - Simple implementation of XUpdate format =head1 SYNOPSIS use XML::LibXML; use XML::XUpdate::LibXML; $parser = XML::LibXML->new(); $dom = $parser->parse_file("mydoc.xml"); $actions = $parser->parse_file("update.xml"); $xupdate = XML::XUpdate::LibXML->new(); $xupdate->process($dom->getDocumentElement(), $actions); print $dom->toString(),"\n"; =head1 DESCRIPTION This module implements the XUpdate format described in XUpdate Working Draft from 2000-09-14 (http://www.xmldb.org/xupdate/xupdate-wd.html). The implementation is based on XML::LibXML DOM API. =head2 C my $xupdate = XML::XUpdate::LibXML->new(); Creates a new XUpdate object. You may use this object to update several different DOM trees using several different XUpdate descriptions. The advantage of it is that an xupdate object remembers values all variables declared in XUpdate documents. =head2 C<$xupdate-EregisterNs($prefix,$uri)> Tell the XPath engine to resolve given namespace prefix as the given namespace URI. This is particularly useful to bind a default namespace to a prefix because XPath doesn't honour default namespaces. =head2 C<$xupdate-Eprocess($document_dom,$xupdate_dom)> This function takes two DOM trees as its arguments. It works by updating the first tree according to all XUpdate commands included in the second one. All XUpdate commands must be children of the root element of the second tree and must all belong to XUpdate namespace "http://www.xmldb.org/xupdate". The namespace URI may be changed with set_namespace method. =head2 C<$xupdate-Eset_namespace($URI)> You may use this method to change the namespace of XUpdate elements. The default namespace is "http://www.xmldb.org/xupdate". =head2 C<$xupdate-Enamespace()> Returns XUpdate namespace URI used by XUpdate processor to identify XUpdate commands. =head2 EXPORT None. =head1 DIFFERENCES BETWEEN 0.2.x and 0.3.x In 0.3.x different implementation of XUpdate variables is used. Now variables contain the actual objects resulting from an XPath query, and not their textual content as in versions 0.2.x of XML::XUpdate::LibXML. Also, value-of instruction results in copies of the actual objects it selects rather than their textual content as in 0.2.x. I hope the new implementation is more conformant with the (not very clear) XUpdate Working Draft and therefore more compatible with other XUpdate implementations. =head1 DIFFERENCES BETWEEN 0.3.x and 0.4.x Commands are applied to all nodes of the select nodeset, not just the first one. =head1 DIFFERENCES BETWEEN 0.4.x and 0.5.x XML::LibXML::XPathContext is used for variable code providing more flexible and powerfull implementation. New and hopefully correct implementation of the problematic child attribute of update command has been introduced. Support for registrering namespace prefix with the XPath engine (allows binding document's default namespace to a prefix). Several bug fixes. =head1 DIFFERENCES BETWEEN 0.5.x and 0.6.x xu:if command implementation contributed by Amir Guindehi. =head1 AUTHOR Petr Pajas, pajas@matfyz.cz =head1 COPYRIGHT Copyright 2002-2005 Petr Pajas, All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 SEE ALSO L L =cut XML-XUpdate-LibXML-0.6.0/META.yml0000644001407700135600000000066610240670273016153 0ustar pajasufal00000000000000# http://module-build.sourceforge.net/META-spec.html #XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX# name: XML-XUpdate-LibXML version: 0.6.0 version_from: lib/XML/XUpdate/LibXML.pm installdirs: site requires: XML::LibXML: 1.54 XML::LibXML::Iterator: 0 XML::LibXML::XPathContext: 0.04 distribution_type: module generated_by: ExtUtils::MakeMaker version 6.17 XML-XUpdate-LibXML-0.6.0/test.pl0000644001407700135600000000123107441365270016212 0ustar pajasufal00000000000000# Before `make install' is performed this script should be runnable with # `make test'. After `make install' it should work as `perl test.pl' ######################### We start with some black magic to print on failure. # Change 1..1 below to 1..last_test_to_print . # (It may become useful if the test is moved to ./t subdirectory.) BEGIN { $| = 1; print "1..1\n"; } END {print "not ok 1\n" unless $loaded;} use XML::XUpdate::LibXML; $loaded = 1; print "ok 1\n"; ######################### End of black magic. # Insert your test code below (better if it prints "ok 13" # (correspondingly "not ok 13") depending on the success of chunk 13 # of the test code): XML-XUpdate-LibXML-0.6.0/Changes0000644001407700135600000000435507736006743016207 0ustar pajasufal00000000000000Revision history for Perl extension XML::XUpdate::LibXML. 0.01 Wed Mar 6 10:04:47 2002 Petr Pajas - original version; created by h2xs 1.20 with options -Xn XML::XUpdate::LibXML 0.02 Fri Mar 15 17:04:52 2002 Petr Pajas - fixed segmentation fault with LibXML 1.40 0.2.1 Petr Pajas - XML::XUpdate::LibXML bugfix in 'update' 0.2.2 Mon Jun 24 16:37:06 2002 Petr Pajas - XML::Normalize::LibXML doc typo fixed 0.2.3 Wed Jul 3 11:51:33 2002 thnx2 Steve McKay - bugfixes: allow multiple variable replacements in select - fixed double literalization in xupdate:value-of handling Sat Jul 13 16:25:00 2002 Petr Pajas - XML::Normalize::LibXML xml_strip_whitespace now also removes empty text_nodes 0.3.0 Thu Nov 7 10:52:19 2002 Petr Pajas - Different implementation of XUpdate variables is used. Now variables contain the actual objects resulting from an XPath query, and not their textual content as in versions 0.2.x of XML::XUpdate::LibXML. - value-of instruction result in copies of the actual objects it select rather than its textual content - extra indentation option -j added - indentation implies removable ws stripping XML parser 0.4.0 Mon Mar 10 15:07:17 2003 Petr Pajas XML::XUpdate::LibXML: - commands apply to all nodes of a selected node-set - xu:comment instruction support - insert_before/insert_after work even if applied on attribute nodes xupdate: - some whitespace treatment changes (yes, again) - added --debug|-D flag XML::Normalize::LibXML: - now uses XML::LibXML::Iterator 0.5.0 Mon Sep 29 12:45:18 2003 Petr Pajas XML::XUpdate::LibXML: - using XML::LibXML::XPathContext as a XPath engine (for better variable and NS support) - xu:append/@child reimplemented - xu:attribute bug fixed - regiserNs added xupdate: - --namespace|-n added - allow compact command-line flags - die on command-line parsing errors XML::Normalize::LibXML: - fixed serious bug in xml_strip_element XML-XUpdate-LibXML-0.6.0/MANIFEST0000644001407700135600000000026107736006412016026 0ustar pajasufal00000000000000Changes MANIFEST Makefile.PL lib/XML/Normalize/LibXML.pm lib/XML/XUpdate/LibXML.pm test.pl xupdate META.yml Module meta-data (added by MakeMaker) XML-XUpdate-LibXML-0.6.0/xupdate0000755001407700135600000001155407763350262016311 0ustar pajasufal00000000000000#!/usr/bin/perl # $Id: xupdate,v 1.18 2003/12/03 12:01:54 pajas Exp $ use FindBin; use lib ("$FindBin::RealBin", "$FindBin::RealBin/../lib", "$FindBin::Bin","$FindBin::Bin/../lib", "$FindBin::Bin/lib", "$FindBin::RealBin/lib", "$FindBin::Bin/../lib/site_perl" ); use strict; use Getopt::Long; use Pod::Usage; use vars qw($VERSION $REVISION $keep_ws $strip_ws $print_version $help $usage $indent $extra_indent @prefixmap); use XML::LibXML; use XML::XUpdate::LibXML; use XML::Normalize::LibXML qw(xml_strip_element); BEGIN { Getopt::Long::Configure ("bundling"); GetOptions('-help|h' => \$help, '-version|V' => \$print_version, '-keep-ws|k' => \$keep_ws, '-strip-ws|s' => \$strip_ws, '-indent|i' => \$indent, '-extra-indent|j' => \$extra_indent, '-namespace|n=s' => \@prefixmap, '-usage|u' => \$usage, '-debug|D' => \$XML::XUpdate::LibXML::debug, ) || die "Wrong command-line arguments\n"; $VERSION='0.4'; $REVISION='$Revision: 1.18 $'; } if ($print_version) { print "Current version is $VERSION ($REVISION)\n"; print "Current version of XML::XUpdate::LibXML is $XML::XUpdate::LibXML::VERSION\n"; exit 1; } pod2usage(-exitstatus => 0, -verbose => 2) if $help; pod2usage() if ($usage or @ARGV<2); my $parser = XML::LibXML->new(); my $xupdate = XML::XUpdate::LibXML->new(); foreach (@prefixmap) { my ($prefix,$uri)= split /\s*=\s*/,$_; if ($prefix ne '' and $uri ne '') { $xupdate->registerNs($prefix,$uri); } } if ($extra_indent||$strip_ws) { $parser->keep_blanks(0); } else { $parser->keep_blanks(1); } my $dom = $parser->parse_file($ARGV[1]); if ($keep_ws) { $parser->keep_blanks(1); } else { $parser->keep_blanks(0); } my $actions = $parser->parse_file($ARGV[0]); unless ($keep_ws) { my $command=$actions->getDocumentElement->firstChild; while ($command) { xml_strip_element($command); $command = $command->nextSibling(); } } $xupdate->process($dom->getDocumentElement(), $actions); print $dom->toString(0+($indent||$extra_indent)+$extra_indent); 1; __END__ =head1 xupdate xupdate - Process XUpdate commands over an XML document =head1 SYNOPSIS xupdate [options] Options: -u | --usage print brief help on usage -h | --help print documentation -n | --namespace prefix=namespace-uri associate a namespace with a prefix for use in XPath selections in XUpdate file (this option may occur several times) -k | --keep-ws preserve whitespace in the XUpdate file -s | --strip-ws strip ignorable whitespace from the input file -V | --version print current version and revision -i | --indent indent the output XML -j | --extra-indent like -i, but also adds a leading and a trailing linebreak to every text node. but also put an extra newline after every start-tag and before every end-tag =head1 OPTIONS =over 8 =item B<--usage> Print a brief help message on usage and exits. =item B<--help> Prints the manual page and exits. =item B<--namespace> prefix=namespace-uri Associate a namespace with a prefix. The prefix may be used in the XPath selections in the XUpdate file to address nodes of the source document that belong to the given namespace. This is especially useful for mapping the default namespace to a prefix because XPath by definition doesn't honour default namespaces. This option may occur several times. =item B<--keep-ws> Preserves any whitespace in XUpdate file. The default behaviour is to remove all ignorable whitespace and any leading or trailing whitespace in all XUpdate command elements in the XUpdate file. =item B<--strip-ws> Remove "ignorable" whitespace from the input file. The default behaviour is to keep any whitespace unless the --extra-indent (-j) option is used. Note that the whitespace being present or not may affect results returned by some XPath expressions (such as /foo/bar/text()[2]). =item B<--version> Print version and revision number of B command and version number of XML::XUpdate library used. =item B<--indent> Indent the resulting document on output. =item B<--extra-indent> Indent the resulting document on output as --indent, but also add a leading and a trailing linebreak to every text node. =item B<--debug> Print some debugging information about commands being applied. =back =head1 DESCRIPTION B will parse the given XUpdate file and the input file and print the input file updated accordingly. XUpdate file format is described in XUpdate Working Draft from 2000-09-14 (http://www.xmldb.org/xupdate/xupdate-wd.html). =cut =head1 AUTHOR Petr Pajas, pajas@matfyz.cz =head1 COPYRIGHT Copyright 2002-2003 Petr Pajas, All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. XML-XUpdate-LibXML-0.6.0/Makefile.PL0000644001407700135600000000103407736005465016655 0ustar pajasufal00000000000000# $Id: Makefile.PL,v 1.5 2003/09/29 10:36:37 pajas Exp $ use strict; use ExtUtils::MakeMaker; WriteMakefile( 'NAME' => 'XML::XUpdate::LibXML', 'VERSION_FROM' => 'lib/XML/XUpdate/LibXML.pm', # finds $VERSION 'PREREQ_PM' => { 'XML::LibXML' => 1.54, 'XML::LibXML::Iterator' => 0, 'XML::LibXML::XPathContext' => 0.04 }, 'AUTHOR' => 'Petr Pajas (pajas@matfyz.cz)', 'ABSTRACT' => 'update XML documents according to XUpdate file', 'EXE_FILES' => ['xupdate'], );