How do you read in an environment variable in an XML file? . . .

A

Albretch

that was set up for and/or by this user in the OS.

Say, you set WEB_DIR as an environment variable pointing to certain
folder or root directory

Could you go like this

<?xml version='1.0' encoding='utf-8'?>
<XMLExample Att1="69" Att2=$WEB_DIR"rest_of_it">

.. . .

</XMLExample>

for attributes or values?

And when a program parses the XML doc it should pick the current env.
var. value.

I think of using it for tomcat's configuration files which are more
XMLish than true XML ones.

There are ways to pass in parameters to the JVM when you run a java
prog., but I don't know of a way to read in an external environment
variable from the OS into an updated conf doc and use this value

How do you do something like that?
 
O

Oscar kind

Albretch said:
that was set up for and/or by this user in the OS.

Say, you set WEB_DIR as an environment variable pointing to certain
folder or root directory

Could you go like this

<?xml version='1.0' encoding='utf-8'?>
<XMLExample Att1="69" Att2=$WEB_DIR"rest_of_it">

. . .

</XMLExample>

for attributes or values? [...]
How do you do something like that?

Yourself. AFAIK, XML parsers don't expand environemtn variables.

To get the value of an environment variable, see:
- System#getProperty(String)
- Integer#getInteger(String)
- Long#getLong(String)
- And similar methods in these classes.
 
M

Martin Honnen

Albretch said:
that was set up for and/or by this user in the OS.

Say, you set WEB_DIR as an environment variable pointing to certain
folder or root directory

Could you go like this

<?xml version='1.0' encoding='utf-8'?>
<XMLExample Att1="69" Att2=$WEB_DIR"rest_of_it">

. . .

</XMLExample>

for attributes or values?

And when a program parses the XML doc it should pick the current env.
var. value.

I think of using it for tomcat's configuration files which are more
XMLish than true XML ones.

There are ways to pass in parameters to the JVM when you run a java
prog., but I don't know of a way to read in an external environment
variable from the OS into an updated conf doc and use this value

How do you do something like that?

There is no general XML mechanism for that. XSLT 1.0 knows global
parameters defined as
<xsl:param name="paramName" />
which you can then set before you run an XSLT transformation. JAXP has a
method serParameter to set such parameters before you do a transformation.
 
A

Albretch

Martin Honnen said:
There is no general XML mechanism for that. XSLT 1.0 knows global
parameters defined as
<xsl:param name="paramName" />
which you can then set before you run an XSLT transformation. JAXP has a
method serParameter to set such parameters before you do a transformation.

I think that would do it in a clean way:

1._ Set up purposed/altered/parameterised xml conf files

2._ Check out TC's sources to chnage the code segments where it reads
these conf files and

3._ pass them first through an XSLT transformation that would:
3.1_ read the values in from env. vars
3.2_ inject them in the files
on the fly

4._ before these files reach TC proper . . .
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,998
Messages
2,570,242
Members
46,834
Latest member
vina0631

Latest Threads

Top