1

as you can see in the title I want to use the environmental variable Userprofile in a XML-File. Already searched for awhile, couldn`t find anything suitable for my case.

Here`s my XML-File:

<?xml version="1.0" encoding="UTF-8"?>
<Reports>
<Destination>%USERPROFILE%\Desktop\Report_PDP</Destination>
    <Report id="5917">
        <DIS_PDP>300000212491</DIS_PDP>
        <DIS_FOLDER>300000203351</DIS_FOLDER>
        <PATH_PDP>%USERPROFILE%\AppData\Roaming\KPIReport\Test\300000212491.xlsm</PATH_PDP>
        <PATH_FOLDER>%USERPROFILE%\AppData\Roaming\KPIReport\Test\300000203351.xlsx</PATH_FOLDER>
    </Report>
    <Report id="5783">
        <DIS_PDP>300000169285</DIS_PDP>
        <DIS_FOLDER>300000168963</DIS_FOLDER>
        <PATH_PDP>%USERPROFILE%\AppData\Roaming\KPIReport\Test\300000169285.xlsm</PATH_PDP>
        <PATH_FOLDER>%USERPROFILE%\AppData\Roaming\KPIReport\Test\300000168963.xlsx</PATH_FOLDER>
    </Report>
    <Report id="5633">
        <DIS_PDP>300000113104</DIS_PDP>
        <DIS_FOLDER>300000112815</DIS_FOLDER>
        <PATH_PDP>%USERPROFILE%\AppData\Roaming\KPIReport\Test\300000113104.xlsm</PATH_PDP>
        <PATH_FOLDER>%USERPROFILE%\AppData\Roaming\KPIReport\Test\300000112815.xlsx</PATH_FOLDER>
    </Report>
</Reports>

The position of the variable is marked with %USERPROFILE%, that is how I use it in the main code, did`nt work out for the XML though.

I want to get the result of the Userprofile like: "C:\Users\FMichal" and then use it for each path in my XML.

Hope you can understand my problem so far.

F. Michal
  • 19
  • 2
  • 10
  • And you are hoping that this will automagically work? – H H Jan 10 '17 at 10:59
  • Well, for example in my powershell code I just had to change to $env:userprofile to work automatically, so I was actually hoping it will work for XML in a similar way as well :P – F. Michal Jan 10 '17 at 11:02
  • No such luck - you'll have to encode them in an XML-safe way and post-process to expand the values. – H H Jan 10 '17 at 11:07
  • Do you have any links to helpful websites? I`m still not able to solve this on my own. – F. Michal Jan 10 '17 at 11:32
  • Not really, it looks like just another form of "XML processing". Pick your programming language and hit Google. – H H Jan 10 '17 at 13:13
  • I found another solution, just removed the part of the userprofile in the xml and connected the strings in the code, I already could read the userprofile. – F. Michal Jan 10 '17 at 13:41

0 Answers0