Ignoring your typo in the XML declaration :) - If all you want to do is get that value and this is the entirety of your document then you probably want to go with XML::Simple :
#!/usr/bin/perl -w
use XML::Simple;
use strict;
local $/;
my $data = XMLin(<DATA>);
print $data->{FILE_SIZE};
__DATA__
<?xml version="1.0"?>
<Document_Confirmation>
<FILE_NAME>ack_mr00000001.xml</FILE_NAME>
<DATE_RECEIVED>11/27/2001</DATE_RECEIVED>
<FILE_SIZE>2022</FILE_SIZE>
</Document_Confirmation>
This is of course is reading from DATA - you will replace the <DATA> with a variable containing your XML document.
/J\ | [reply] [d/l] |
Thank you.
bad news, our box does not have XML/Simple.pm on it, and no, they won't add it because its their machine damn it, and I'll need to find another way to do it.
There is nothing like cooperation, and our systems people our nothing like cooperative.
| [reply] |
Does your box have XML::Parser on it?
Install XML::Simple in your user space,
then. Yes, it's a pain. Yes, it's worth it. XML
parsing is a complex, often subtle problem that's
difficult to get right -- so let other people get
it right, and use the wheels they invent.
If you don't have the requisite modules for
XML::Simple (and that includes a compiled
Expat library, IIRC), you're in deeper trouble.
You might have some luck with XML::Parser::Lite,
which I haven't tried but seems to be entirely
Perl-based. If you insist on building your own
parser, consider using XML::RegExp.
It might be easier to seek a political solution
to the problem (i.e. have your manager lean on the
systems people until XML/Simple.pm appears in your
@INC).
I don't mean to be condescending, but parsing
XML really is a lot harder than you think. Writing
a half-assed collection of regexes (you'd have more
luck using Text::Balanced, of course) that
breaks on 90% of the XML out there is easy. Getting
it to work properly is insanely hard. (I've been
there. I gave up.) Telling your boss that your
parser reads XML, but not XML with newfangled
features foo, bar, and baz, is probably not acceptable.
Good luck.
--
:wq
| [reply] |
| [reply] |
use lib qw(/path/to/your/custom/install);
use XML::Parser;
... etc.
HTH
Update:
FoxtrotUniform caught that typo. Thanks, FU ;-) | [reply] [d/l] [select] |
I recently posted Working with XML and received some excellent responses and module suggestions there. I'm sure the thread will be of use to you as well. :)
| [reply] |
If your system doesn't have expat on, you can use the pure perl parser built into XML::SAX. Installed it locally in your user space and then use XML::SAX::Simple (also on CPAN, it's a XML::Simple look-alike module that uses SAX) to access the XML. | [reply] |