如何在 XML 文件的 xi:include 中使用环境变量?
我想在 XML 文件的 xi:include
节点的 href 链接中使用环境变量。目前 Perl XInclude 解析器不支持任何变量,只支持绝对路径。有没有一种方法可以克服这个问题? 例如,我的 xi:include 节点将如下所示:
<xi:include href="$GLOBAL_ROOT/alternative.xml">
稍后可以通过加载不同的设置来更改由 $GLOBAL_ROOT
引用的路径,并且解析器仍然应该能够在相应的位置查找该文件。
I would like to use an environment variable in the href link of the xi:include
node of an XML file. Currently the Perl XInclude parser doesn't support any variables but only absolute paths. Is there a method where this can be overcome?
for example, my xi:include
node will look like this:
<xi:include href="$GLOBAL_ROOT/alternative.xml">
The path referred by $GLOBAL_ROOT
can be changed later by loading a different setting and still the parser should be able to look up in the respective location for the file.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为什么不使用符号链接(相对或绝对)?或用户主目录位置(~/.xml)?
Why not use a symbolic link (either relative or absolute)? or a user home dir location (~/.xml)?
您在专门使用私有方法(按照惯例用前导下划线表示)的基础上不稳定,但作者可以通过提供更多钩子来提供帮助。假设您正在使用
XML::Filter::XInclude
:然后向工厂传递一个
MyXInclude::ExpandEnvironmentVars
实例作为Handler
参数。You're on shaky ground specializing a private method (indicated by convention with a leading underscore), but the author could help by providing more hooks. Assuming you're using
XML::Filter::XInclude
:Then pass the factory an instance of
MyXInclude::ExpandEnvironmentVars
as theHandler
parameter.