Coyote has asked for the wisdom of the Perl Monks concerning the following question:
I am working on a project to take scanned articles from an academic journal which have been marked up in XML by hand and do nifty things with the documents (i.e., produce HTML, TeX, and PDF output; pull abstracts from the articles; cross reference the articles and so on). The articles have APA style references such as (author1 & author2, 1999) embedded in the text and the occasional article has a bare > or < as part of the text. I am using mirod's excellent XML::Twig module to parse and process the data. As you would expect, the parser dies when it comes across an &, >, or <. For example, if I have the following code with an XML sample embedded as a here doc --
The parser dies with this error message -- not well-formed at line 8, column 50, byte 198 at C:/Perl/site/lib/XML/Parser.pm line 168 Now I know where the parser died, and a quick examination of the XML turns up a bare & which is a malformed entity. I would like to be able to correct this error as while the document is parsing, however I can't seem to find an option in either the XML::Parser or XML::Twig man pages to allow me to handle the error or at least report the error and continue parsing the document so I can gather all the problems with the document in one pass. Am I using the right tool for the job with XML::Twig? Should I write some sort of preprocessor or filter to fix these problems before passing the data to XML::Twig? Has someone already written a module to do this? Any advice will be appreciated. I would rather not get into the XML parser writting business if I don't have to(see On XML parsing).use strict; use warnings; use XML::Twig; my $xml = <<XML; <reference> <authors> <author>Lindsley, O.R.</author> </authors> <year>1992</year> <title>Precision teaching: Discoveries & effects.</title> <source>Journal of Applied Behavior Analysis</source> <volume>25</volume> <pages>51-57</pages> </reference> XML my $twig = new XML::Twig(); $twig->parse($xml);
--
Coyote
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Dealing with Malformed XML
by mirod (Canon) on Jan 09, 2001 at 12:35 UTC | |
by vili (Monk) on Mar 02, 2005 at 23:42 UTC | |
|
(Ovid) Re: Dealing with Malformed XML
by Ovid (Cardinal) on Jan 09, 2001 at 05:25 UTC | |
by Coyote (Deacon) on Jan 09, 2001 at 07:50 UTC | |
|
(tye)Re: Dealing with Malformed XML
by tye (Sage) on Jan 09, 2001 at 05:33 UTC | |
by Coyote (Deacon) on Jan 09, 2001 at 23:15 UTC | |
|
Re: Dealing with Malformed XML
by myocom (Deacon) on Jan 09, 2001 at 05:19 UTC | |
|
Re: Dealing with Malformed XML
by Coyote (Deacon) on Jan 10, 2001 at 00:21 UTC | |
|
(jptxs)Re: Dealing with Malformed XML
by jptxs (Curate) on Jan 09, 2001 at 20:28 UTC |