1

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"/>

Mads Hansen
  • 63,927
  • 12
  • 112
  • 147
Jim Barber
  • 15
  • 3
  • See here: https://www.w3schools.com/xml/xml_xlink.asp although this functionality only seems to be supported by some XML tool kits or languages depending on the type used, so it would entirely depend on the application/service that needs to read your XML file, otherwise use a simple script or find and replace function with your favourite text editor to update the paths. If you have access to the source code of the application doing the reading, then you can do whatever you wish of course including your suggestion. – sorifiend Feb 24 '22 at 01:16

1 Answers1

1

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>
Mads Hansen
  • 63,927
  • 12
  • 112
  • 147
  • The main problem with this approach is that it's not easy to change the value of the path entity. One solution to that is to use external entities (where the value is defined in a separate file). But I would take a look at the overall workflow, and in many cases I would construct a pipeline in which the XML is generated on-the-fly (for example, using XSLT, perhaps within an Ant or Gradle or XProc pipeline), which allows plenty of opportunties for parameterisation. – Michael Kay Feb 24 '22 at 08:07
  • Thank you for your help... most appreciative! – Jim Barber Feb 25 '22 at 19:26