Perl newbie needs regexp to extract multiline data between <para></para> in multiple xml files

I am going mad and need some experts help please.

I am trying to extract the data between the first <para></para> in 12 xml files, but  because the data spans several lines, I can't get it to work.

So far I have tried every idea I have seen on the web but no luck, I either get the wrong paragraph, too little or too much.

As I have just started out in Perl, I would appreciate answers that are more than just a link or one line of reg exp as I want to get away from CTRL C + V coding and understand what it is I am doing. To this end, I have put the points at 125 (I know, not huge but...) as I would like a quick explanation of what the regexp is doing.

I may not respond to your answers immediately as I am lying down in a dark room with a cold wet flannel across my forehead just now.

One of the files I am working on is:

<?xml version="1.0"?>
<?xpp file-name;57_09_Miller.xml?>
<!DOCTYPE book PUBLIC "-//Letterpart//DTD Letterpart Book//EN"><?xpp MAIN;1;0;0;0;137;0;0?><book><title abb-r-head="Philosophy"><?xpp xych;1?>Philosophy</title><chapter section="miller"><title abb-r-head="Need, Care and Obligation">Need, Care and Obligation</title> <source>Sarah Clark Miller</source> <para>All humans experience needs.<?xpp foot;f1;an?><?xpp FOOT;f1;1?><footnote-para> I would like to thank Soran Reader for her very helpful comments on this article.</footnote-para> <?xpp /FOOT?>
At times needs cut deep, inhibiting persons&rsquo; abilities to act as agents in the world, to live in distinctly human ways, or to achieve life goals of significance to them. In considering such potentialities, several questions arise: Are any needs morally important, meaning that they operate as morally relevant details of a situation? What is the correct moral stance to take with regard to situations of need? Are moral agents ever required to tend to others&rsquo; well-being by meeting their needs? What justification or foundation, if any, can be given for requiring moral agents to respond to others&rsquo; needs?<?xpp foot;f2;an?><?xpp FOOT;f2;1?><footnote-para> As a variety of philosophers have it, the scope or extent of our obligation to help others runs the gamut between two extreme positions: the minimal libertarian position that we must only respect the rights of others, leaving charity as optional, not mandatory, and a maximal position like that of Peter Singer&rsquo;s, through which we are required to give to the needy until we are diminished to their level of need. Thomas Hill identifies these two extreme positions in &lsquo;Meeting Needs and Doing Favors&rsquo;. See T. Hill, Jr., <?xpp italic?>Human Welfare and Moral Worth: Kantian Perspectives<?xpp /italic?> (Oxford: Clarendon, 2002), 201&#8211;243. The Singer position (a consequentialist one) can be famously found in his earlier piece, &lsquo;Famine, Affluence, and Morality&rsquo;, <?xpp italic?>Philosophy and Public Affairs<?xpp /italic?> <?xpp bold?>1<?xpp /bold?>, No. 1 (Spring 1972), 229&#8211;43. Singer has somewhat modified his position in more recent work. See P. Singer, <?xpp italic?>One World<?xpp /italic?> (New Haven: Yale University Press, 2002).</footnote-para> <?xpp /FOOT?>
</para> <para>In answering these questions, my argument will take place in several parts. I begin explanatorily, describing care ethics for those unfamiliar with this particular ethical approach. This discussion reveals that care ethicists assert the moral importance of needs. Their position, however, does not offer comment on whether or not we are required to respond to the needs of others. I propose that our human interdependence and finitude give rise to an obligation to care for a certain subset of needs, namely, the constitutive needs of others. Through analysis of both the <?xpp italic?>Groundwork<?xpp /italic?> and the <?xpp italic?>Metaphysics of Morals<?xpp /italic?>, I present an interpretation of Kant&rsquo;s duty of beneficence that lays the foundation for the duty to care. After acknowledging the strengths of the Kantian approach, I cite one of <?xpp /MAIN?>
<?xpp MAIN;2;0;0;0;138;0;0?>its most significant shortcomings: although helpful in clarifying the foundation and scope of the duty to care, Kantian ethics requires supplementation with regard to content. Insights from feminist care ethicists provide indispensable enhancement, promoting a robust sense of the content of the duty to care, as represented by two elements: (1) the importance of moral perception and moral judgment in establishing how best to care for others and (2) dignifying care, a notion demonstrating that it is not enough <?xpp italic?>that<?xpp /italic?> we meet the needs of others, as <?xpp italic?>how<?xpp /italic?> we do so seriously affects both the agency and dignity of those in need.</para> <head-a><title abb-r-head="1. Care Ethics: Methods and Themes">1. Care Ethics: Methods and Themes</title> <para>The appearance of Carol Gilligan&rsquo;s <?xpp italic?>In a Different Voice<?xpp /italic?><?xpp foot;f3;an?><?xpp FOOT;f3;1?><footnote-para> C. Gilligan, <?xpp italic?>In a Different Voice: Psychological Theory and Women&rsquo;s Development<?xpp /italic?> (Cambridge, Mass.: Harvard University Press, 1982). See also C. Gilligan, &lsquo;Moral Orientation and Moral Development&rsquo; in <?xpp italic?>Women and Moral Theory<?xpp /italic?>, ed. E. F. Kittay and D. T. Meyers (Totowa, NJ: Rowman and Littlefield, 1987), 19&#8211;33. To understand the theoretical framework that Gilligan was arguing against, see L. Kohlberg, <?xpp italic?>The Philosophy of Moral Development: Moral Stages and the Idea of Justice<?xpp /italic?> (San Francisco: Harper and Row, 1981).</footnote-para> <?xpp /FOOT?>

many thanks,

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

LetterpartAuthor Commented:
When I run XML Simple it gives me the error:

syntax error at line 3, column 62, byte 119 at C:/Perl/site/lib/XML/ line 187

It appears to be this part of the xml file that is causing this:

<!DOCTYPE book PUBLIC "-//Letterpart//DTD Letterpart Book//EN">

but when I remove this (just to test it it was this causing the error), it then stops at

undefined entity at line 4, column 43, byte 536 at C:/Perl/site/lib/XML/ line 187

LetterpartAuthor Commented:

have manaaged to solve this.

Now I am sure all you hardcore Perl coders out there will throw their arms up in disgust at my sloppy coding, and will point out how to do this in one line.

But, I'm new at this and it works, so I am pleased.

The code I used is:

if($_ =~ m/<\/para>/i) {
      $para_end +=1;
if ($para_end <= 1) {
      $abstract .=$_;


sub abstract_stripper {
#print "abstract is $abstract\n\n";
$abstract =~ s/\n//gmi;                                          # Strip new line globally
$abstract =~ s/<\?xpp.*?>//gmi;                  # Remove <? xpp blah> tags globally
$abstract =~ s/.*?<para>//mi;                        # Remove everything before 1st <para>
$abstract =~ m/(.*?)<\/para>/i;                  # Collect everything before 1st </para>
$abstract = $1;                                                                  # Assign it to $abstract
$abstract =~ s/<.*?>//gmi;                              # Remove everything between < >
@abstract_large = split / /, $abstract;            # Split $1 into words and assign to abstract array
                  my $ab_length = "";
                  $ab_length = @abstract_large;
                  if ($ab_length <=249) {
                        @abstract_array = @abstract_large;
                  else {
                        @abstract_array = @abstract_large[0..249];
$para_end =0;
Closed, 50 points refunded.
The Experts Exchange
Community Support Moderator of all Ages

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.