in reply to XML parsing

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\

Replies are listed 'Best First'.
Re: Re: XML parsing
by geekoid (Initiate) on Mar 19, 2002 at 21:33 UTC
    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.

      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

        They do not have XML::Parser. There not planning on putting it on there at this time, however, they want me to manipulate these incoming XML files. The incoming XML file only have 2 pieces of information in it, and they could just send a normal file, but noooo, they want to use XML so they can say they use XML. Bah. Thanks for your advice everybody, I appreciate it. If I had know ahead of time they weren't going to give me the tools I need to do the job they mandated correctly, I wouldn't have bothered you. so I get to do this instead:
        @ar = `tail -2 "$ack_filename"`; print $ar[0]; $file_size = substr($ar[0],13,-13); print $file_size;
        hope there file format doesn't change. oh, and I can't put it in my space because we all use the same logon and password. yes you read correctly. I've been trying to get them to change that for almost a year, but they have more important things to do. Like work on there golf game. fortuanatly, my year here will be up at the end of july, and I can flee.
      Just get the tar ball from CPAN yourself, and install it in your own area (along with your programs). Is that not possible?

      Of course, you need to consider the dependencies too (like XML::Parser which XML::Simple depends on), but you get the idea.

      /prakash

      quick helpful addition:

      there are a couple ways to include whatever modules you install in your own space. the one i tend to use for situations like this is:

      use qw(/path/to/your/custom/install);

      use lib qw(/path/to/your/custom/install); use XML::Parser;
      ... etc.

      HTH

      Update:

      FoxtrotUniform caught that typo. Thanks, FU ;-)