我需要将变量放入 XML 文件中

发布于 2025-01-09 16:55:09 字数 1172 浏览 0 评论 0原文

在 XML 文件中,有引用图像的节点,而且数量很多!我想做的是在文档顶部创建一个变量来指定驱动器和路径(C:\IMAGES),这样如果我想更改路径或驱动器或两者,那么我只需在一行。但是,我尝试了不同的格式,但无法让它在节点内工作。

这就是现在的样子:

<?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>

简化

我想用这样的东西 :

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你穿错了嫁妆 2025-01-16 16:55:09

实体对此效果很好。您可以将 path 声明为 DTD 内的实体:

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

然后在 XML 中将 path 实体引用为 &path;

应用于您的文档:

<?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>

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文