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

Discussion in 'XML' started by Albretch, Nov 7, 2004.

  1. Albretch

    Albretch Guest

    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?
    Albretch, Nov 7, 2004
    #1
    1. Advertising

  2. Albretch

    Oscar kind Guest

    Albretch <> wrote:
    > 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.


    --
    Oscar Kind http://home.hccnet.nl/okind/
    Software Developer for contact information, see website

    PGP Key fingerprint: 91F3 6C72 F465 5E98 C246 61D9 2C32 8E24 097B B4E2
    Oscar kind, Nov 7, 2004
    #2
    1. Advertising

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

    Albretch wrote:
    > 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.


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Nov 7, 2004
    #3
  4. Albretch

    Albretch Guest

    Martin Honnen <> wrote in message news:<418e5604$0$22607$-online.net>...
    > 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 . . .
    Albretch, Nov 8, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. 195.229.241.2
    Replies:
    5
    Views:
    4,054
    Tor Iver Wilhelmsen
    Aug 4, 2003
  2. Albretch
    Replies:
    1
    Views:
    374
    Oscar kind
    Nov 7, 2004
  3. B N
    Replies:
    4
    Views:
    872
  4. Replies:
    5
    Views:
    644
  5. bthumber
    Replies:
    0
    Views:
    364
    bthumber
    Jul 6, 2010
Loading...

Share This Page