Any XML Experts? Environment Variable Question
Any XML Experts? Environment Variable Question
Author
Discussion

miniman

Original Poster:

29,713 posts

288 months

Friday 16th April 2004
quotequote all
I need to read Windows environment variables (e.g. TEMP folder location etc.) from an XML or XSLT document. Basically, I want one XML page to read another XML file for config settings (CONFIG.XML). This file is created by an application on startup and is written to a defined location (Windows TEMP location) - but this varies by user / machine and I need to "tell the XML page where to find it".

Any ideas appreciated...

Plotloss

67,280 posts

296 months

Friday 16th April 2004
quotequote all
Not sure I get what you mean.

Do you want to read all the Environment options and dump them in an XML file and then have a process that reads that XML file from another XML via the DOM?

miniman

Original Poster:

29,713 posts

288 months

Friday 16th April 2004
quotequote all
No, I want to use the environment variables in the XML file itself.

Like in VB, I might use something like

Dim XLocn
XLocn = %WIN_TEMP_PATH%£myfolder

where when the program ran, it might set XLocn to c:£temp£myfolder on one machine and c:£documents and settings£temp£myfolder on another.

The file CONFIG.XML holds info such as language selected, brands available etc and I need to use that information within another XML file.

Edit: backslashes removed by PH - changed them to "£"

>> Edited by miniman on Friday 16th April 10:56

pdV6

16,442 posts

287 months

Friday 16th April 2004
quotequote all
If I've read you right, the file already exists but you just need to know how to find the TEMP folder for the current user.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/base/gettemppath.asp

miniman

Original Poster:

29,713 posts

288 months

Friday 16th April 2004
quotequote all
Yes, that's what I want to do, but within an XML file. Can I use the GetTempPath within an XML document?

Plotloss

67,280 posts

296 months

Friday 16th April 2004
quotequote all
The process thats building the XML document needs to call GetTempPath and then insert a row into the XML.

pdV6

16,442 posts

287 months

Friday 16th April 2004
quotequote all
Wouldn't have thought so. Essentially an XML document is simply a text file with fancy formatting. The clever bits need to be supplied by the application that reads and processes the file.

Therefore, if the XML file contains 'special' markers for things like the TEMP path, your program would need to spot these and translate them accordingly.

{clarification: I was replying to miniman, not Plotloss!}

>> Edited by pdV6 on Friday 16th April 11:08

miniman

Original Poster:

29,713 posts

288 months

Friday 16th April 2004
quotequote all
Sorry, I'm not being clear. It's in XSL rather than XML. Here is the command:

xsl:when test="document('../../../../Config.xml')//Language='CF'"

Config.XML is stored in the Temp Path. I effectively want to do:

xsl:when test="document('$WINTEMPPATH$/Config.xml')//Language='CF'"

pdV6

16,442 posts

287 months

Friday 16th April 2004
quotequote all
Ah. You've got me there. Haven't had any need to use XSL yet, so the grey matter's a bit light on suggestions...

Plotloss

67,280 posts

296 months

Friday 16th April 2004
quotequote all
Yep XSL got me too.

XML and webservices yes but XSL no.

There are a load of XSL sites out there though. Have you tried Google groups?

FunkyGibbon

3,853 posts

290 months

Friday 16th April 2004
quotequote all
this thread, whislt not exactly what you are trying to do kinda implies that you cannot.

TheGroover

1,043 posts

301 months

Friday 16th April 2004
quotequote all
miniman said:
Sorry, I'm not being clear. It's in XSL rather than XML. Here is the command:

xsl:when test="document('../../../../Config.xml')//Language='CF'"

Config.XML is stored in the Temp Path. I effectively want to do:

xsl:when test="document('$WINTEMPPATH$/Config.xml')//Language='CF'"

What you would have to do is set up an XML file using something like VB which would write a line into the xml, something like :

<VARIABLES>
<COMPUTERNAME Value="XXXXXX">
</VARIABLE>

Then in the xsl create a variable which will read this out of the xml file for use:-

<xsl:variable name="computername" select="//COMPUTERNAME/@Value"/>

you can then use this variable in the xsl sheet:
<xsl:when test="Something=$computername"

greenv8s

31,003 posts

310 months

Friday 16th April 2004
quotequote all
Depending what you're using to read the XML document you could provide an entity resolver that resolves entity references to environment variable values for you. Probably not much help though unless you are accessing the document programatically.