in reply to Re: Using environment variables in xi:include
in thread Using environment variables in xi:include

This is the sample code

use XML::DOM; use strict; use File::Find; use XML::SAX; use XML::SAX::Writer; use XML::Filter::XInclude; use File::Copy; use IO::File; my $output = new IO::File "> output.xml"; my $parser = XML::SAX::ParserFactory->parser( Handler => XML::Filter::XInclude->new( Handler => XML::SAX::Writer->new(Output=>$output) ) ); $parser->parse_uri("./project.xml");

output.xml has a has some data and also has a xinclude, ie reference to another file in another location. As of now the paths are absolute, but can it support any variable?

Replies are listed 'Best First'.
Re^3: Using environment variables in xi:include
by dHarry (Abbot) on Jan 15, 2010 at 12:09 UTC

    I'm not sure if I understand you correctly. Sure you can use variables instead of hardcoding the paths. You can also use Perl environment variables by using %ENV. Try the code below to get an overview.

    use strict; use warnings; foreach my $key (keys(%ENV)) { printf("%-10.10s: $ENV{$key}\n", $key); }

    Output on my system (slightly edited)

    HOME : /Users/dharry LOGNAME : dharry DISPLAY : /tmp/launch-uz3Zcp/:0 COMMAND_MO: unix2003 VERSIONER_: no PATH : /usr/bin:/bin:/usr/sbin:/sbin APP_ICON_2: ../Resources/Eclipse.icns SHELL : /bin/bash JAVA_START: 1 SSH_AUTH_S: /tmp/launch-tK7iUz/Listeners Apple_PubS: /tmp/launch-SmQdNX/Render TMPDIR : /var/folders/F9/tmp/ USER : dharry VERSIONER_: 5.10.0

    You can also set certain variables like LOGDIR.

    Cheers

    Harry

    Update

    Missed something the first time I read the post.

    When i try to invoke the xinclude parser, it is not able to access the file even though i initialize the variable with a pre-determined path.

    Does the variable contains what you think it does? Does the parser throw an error? Try adding use warnings as well. At first glance I see no reason why it shouldn't work.