I need to put a variable inside an XML file

Viewed 574

In the XML file, there are nodes that reference images and there are a lot of them! What I'm trying to do is create a variable at the top of the doc to specify drive and path (C:\IMAGES) so that if I want to change the path or drive or both, then I only have to do it in one line. However, I've tried different formats but can't get it to work inside the node.

This is what it looks like now:

<?xml version="1.0" encoding="UTF-8" standalone="no" ?>

<CustSection xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <FileVersion IncrementalVersion="3" MajorVersion="0" MinorVersion="1" UserVersion="0"/>
  <Header>...
   </Header>
       <MenuMacro UID="ID_EPSOutput">
        <Macro type="Any">
          <Revision MajorVersion="16" MinorVersion="2" UserVersion="1"/>
          <Name UID="XLS_1309" xlate="true">Create EPS output for IOC</Name>
          <Command>-vbarun acadproject.main.Run_EPSOutput </Command>
          <SmallImage Name="F:\COMMON\CAREM-B18\Images\EPS.bmp"/>
          <LargeImage Name="F:\COMMON\CAREM-B18\Images\EPS.bmp"/>
        </Macro>
      </MenuMacro>

I want to simplify <SmallImage Name="F:\COMMON\CAREM-B18\Images\EPS.bmp"/>

with something like this: <SmallImage Name="{$path}EPS.bmp"/>

1 Answers

Entities work well for this. You can declare the path as an entity inside of a DTD:

<!DOCTYPE CustSection [<!ENTITY path "F:\COMMON\CAREM-B18\Images\">]>

and then reference the path entity in the XML as &path;.

Applied to your document:

<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<!DOCTYPE CustSection [<!ENTITY path "F:\COMMON\CAREM-B18\Images\">]>
<CustSection xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <FileVersion IncrementalVersion="3" MajorVersion="0" MinorVersion="1" UserVersion="0"/>
    <Header>...
    </Header>
    <MenuMacro UID="ID_EPSOutput">
        <Macro type="Any">
            <Revision MajorVersion="16" MinorVersion="2" UserVersion="1"/>
            <Name UID="XLS_1309" xlate="true">Create EPS output for IOC</Name>
            <Command>-vbarun acadproject.main.Run_EPSOutput </Command>
            <SmallImage Name="&path;EPS.bmp"/>
            <LargeImage Name="&path;EPS.bmp"/>
        </Macro>
    </MenuMacro>
</CustSection>
Related