RE: Looking for simple example for parsing a XML-file
by Stuart Arnold other posts by this author
Aug 9 2005 3:39AM messages near this date
view in the new Beta List Site
Looking for simple example for parsing a XML-file
|
Re: Looking for simple example for parsing a XML-file
& XSLT Have a look at XML:XPath;
use XML:XPath;
my $xml;
my $fname = "foo.xml";
eval q {
$xml = XML::XPath-> new( filename => $fname );
};
die ("XML::XPath failed on ($fname): $@") if ($@);
is typically how its called. Read on some of it caveats as well.
--
It is MDT, Inc's policy to delete mail containing unsolicited file
attachments. Please be sure to contact the MDT staff member BEFORE sending
an e-mail with any file attachments; they will be able to arrange for the
files to be received. This email, and any files transmitted with it, is
confidential and intended solely for the use of the individual or entity to
whom they are addressed. If you have received this email in error, please
advise postmaster@[...].com <mailto:postmaster@[...].com> .
- Stuart Arnold
MDT Software
Alpharetta, GA
W: 678.297.1027
Email(W): sja@[...].com <mailto:sja@[...].com>
-----Original Message-----
From: perl-xml-bounces@[...].com
[mailto:perl-xml-bounces@[...].com]On Behalf Of Jarle H.
Knudsen
Sent: Monday, August 08, 2005 4:49 PM
To: perl-xml@[...].com
Subject: Looking for simple example for parsing a XML-file
I'm trying to find out how I can parse an XML-file using Perl, and I'm
having trouble finding working example that can introduce me to this.
Here is an example of what I need to do:
Given this XML:
<?xml version="1.0" encoding="iso-8859-1"?>
<course name="My Course">
<chapter number="01" name="Chapter 1">
<text> Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</text>
<bullet> This is a bullet</bullet>
<text> Duis ultricies. Phasellus augue sapien, auctor ac.</text>
</chapter>
<chapter number="02" name="Chapter 2">
<text> Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</text>
</chapter>
</course>
the following should be done:
- Create directory "My Course"
- Create directory "My Course/Chapter 1"
- Create file "My Course/Chapter 1/text1" containing "Lorem ipsum
dolor sit amet, consectetuer adipiscing elit."
- Create file "My Course/Chapter 1/bullet2" containing "This is a
bullet"
- Create file "My Course/Chapter 1/text3" containing " Duis
ultricies. Phasellus augue sapien, auctor ac."
- Create directory "My Course/Chapter 2"
- Create file "My Course/Chapter 2/text1" containing "Lorem ipsum
dolor sit amet, consectetuer adipiscing elit."
As you can see, the order of the nodes is important, so I can't use
XML::Simple.
Any help, hints, examples, which module to use, etc. is appreciated.
Best regards,
Jarle Hammen Knudsen
_______________________________________________
Perl-XML mailing list
Perl-XML@[...].com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
_______________________________________________
Perl-XML mailing list
Perl-XML@[...].com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Thread:
Jarle H. Knudsen
Stuart Arnold
Jarle H. Knudsen
Mark - BLS CTR Thomas
|