RE: using xml::libxml to find replace in xml documents

2004-07-10 Thread Eric Lease Morgan
I wrote:
Has anybody here written one or more Perl scripts using XML::LibXML to
find  replace in XML documents?...
Thank you the all the replies. One person recommending a Perl module 
called XML::Twig. Another person recommended I use regular expressions. 
Two people recommended the use of XSLT. One of these provided sample 
code. The other wrote a full-blown program! (Thanks, Andrew 
Houghton!)

In the end I re-read some of my Perl/XML books and decided to write a 
SAX filter using XML::SAX::ParserFactory. Such a filter has the 
following shape:

  use strict;
  use XML::SAX::ParserFactory;
  my $handler = MyHandler-new();
  my $parser = XML::SAX::ParserFactory-parser(Handler = $handler);
  $parser-parse_uri($ARGV[0]);
  exit;
  package MyHandler;
  sub new {
  my $type = shift;
  return bless {}, $type;
  }
  sub start_element {
  my ($self, $element) = @_;
  print Starting element $element-{Name}\n;
  }
  sub end_element {
  my ($self, $element) = @_;
  print Ending element $element-{Name}\n;
  }
  sub characters {
  my ($self, $characters) = @_;
  print characters: $characters-{Data}\n;
  }
  1;
I have saved my script at the following location:
  http://infomotions.com/musings/getting-started/fix-ead.txt
The script will eventually be a part of a workshop I am giving called 
Shining a LAMP on XML. the outline, to date, is here:

  http://infomotions.com/musings/getting-started/LAMP.txt
'More later.
--
Eric Lease Morgan


using xml::libxml to find replace in xml documents

2004-07-08 Thread Eric Lease Morgan
Has anybody here written one or more Perl scripts using XML::LibXML to 
find  replace in XML documents?

I have a set of 700 XML files. Each one has an incorrect attribute 
value in a processing instruction, a few invalid attributes in a 
particular element, and a set of elements that are no longer valid 
against the DTD.

I want to use XML::LibXML to clean up these files, and I'm hope someone 
out there has already done this to some extent and can share their 
code. While the XML::LibXML modules are very functional, I wish they 
had more examples in their PODs.

--
Eric Lease Morgan
University Libraries of Notre Dame