Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

xml

Say you have an XML element you want to read in an app, however you have multiple environments where the path of 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 would want to make a reference to the relative directory

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

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

Can you use a variable declared in the XML itself to reference the relative directory path?

like image 995
kick811 Avatar asked Feb 25 '14 14:02

kick811


People also ask

How do you declare a variable in XML?

An XML variable can be defined as a string or file reference variable. Regular XML variables and XML file reference variables can be defined in all host languages with a few exceptions. REXX supports file reference variables for XML. Java™ supports XML and file reference variables for XML.

How do you're assign a value to a variable in XSLT?

You cannot - 'variables' in XSLT are actually more like constants in other languages, they cannot change value. Save this answer. Show activity on this post.


1 Answers

You would need to add a DOCTYPE declaration to your file, declare an entity there and then reference that entity in the document body.

<!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>
like image 192
Ian Roberts Avatar answered Nov 06 '22 05:11

Ian Roberts