Can you declare and use a variable inside XML without using XSL to transform / parse XML

Say that you have an XML element that you want to read in the application, but you have several environments in which the path to the dependent files may change.

<root> <element ID="MyConfigFile" url="c:\Program Files\MyProgram\resources\MyProgramconfig.xml" /> <element ID="Executable" url="c:\Program Files\MyProgram\Prog.exe" /> </root> 

... so you want to link to a relative directory

@path = "c: \ Program Files \ MyProgram \"

 <root> <element ID="MyConfigFile" url="@path\resources\MyProgramconfig.xml" /> <element ID="Executable" url="@path\Prog.exe" /> </root> 

Is it possible to use a variable declared in XML itself to refer to a relative directory path?

+6
source share
2 answers

You will need to add a DOCTYPE declaration to your file, declare an object, and then reference that object in the body of the document.

 <!DOCTYPE root [ <!ENTITY path "c:\Program Files\MyProgram"> ]> <root> <element ID="MyConfigFile" url="&path;\resources\MyProgramconfig.xml" /> <element ID="Executable" url="&path;\Prog.exe" /> </root> 
+10
source

not sure try with entity

 <!ENTITY path "c:\Program Files\MyProgram\"> <element ID="MyConfigFile" url={&path + "resources\MyProgramconfig.xml"} /> 
0
source

All Articles