使用 XMLStarlet 时出现命名空间错误

发布于 2024-08-08 01:40:28 字数 798 浏览 3 评论 0原文

我有一个 xml 配置文件,它在 Java 中运行良好,我正在尝试使用脚本内的 XMLStarlet 从中解析出一些信息。我收到的错误是:

xml sel -t -m "Config/Application" -v "@rmiPort" -n config.xml
namespace error : Namespace prefix log4j on configuration is not defined
                    <log4j:configuration>
                                        ^

config.xml 有这样的声明:

<?xml version="1.0"?>
<!DOCTYPE Config SYSTEM "../../../dtds/Config.dtd">
<Config>
...
<Logger>
 <log4j:configuration>
...

config.dtd 看起来像这样:

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

<!ENTITY % log4j:configuration SYSTEM "log4j.dtd">
%log4j:configuration;
...
    <!ELEMENT Logger ((log4j:configuration)*)>

知道如何修复命名空间或消除错误吗?

I have an xml configuration file which works fine in Java, and I'm trying to parse out some info from it using XMLStarlet inside a script. The error I'm getting is:

xml sel -t -m "Config/Application" -v "@rmiPort" -n config.xml
namespace error : Namespace prefix log4j on configuration is not defined
                    <log4j:configuration>
                                        ^

config.xml has this declaration:

<?xml version="1.0"?>
<!DOCTYPE Config SYSTEM "../../../dtds/Config.dtd">
<Config>
...
<Logger>
 <log4j:configuration>
...

config.dtd looks like this:

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

<!ENTITY % log4j:configuration SYSTEM "log4j.dtd">
%log4j:configuration;
...
    <!ELEMENT Logger ((log4j:configuration)*)>

Any idea how I can fix the namespace, or quiet the error?

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

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

发布评论

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

评论(1

坏尐絯 2024-08-15 01:40:28

您需要在 select 的全局选项中声明名称空间。

Log4j 使用下面的命名空间。

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">

您还没有向我们提供完整的 config.xml,但据猜测,我认为您的 XMLStarlet 命令应该类似于以下内容。

xml sel -N log4j="http://jakarta.apache.org/log4j/" -t -m "Config/Application/Logger/log4j:configiguration/" -v "@rmiPort" -n config.xml

希望有帮助。

You need to declare the namespace in the global options of the select.

Log4j uses the namespace below.

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">

You haven't given us your full config.xml but from a guess I think your XMLStarlet command should be something like the following.

xml sel -N log4j="http://jakarta.apache.org/log4j/" -t -m "Config/Application/Logger/log4j:configiguration/" -v "@rmiPort" -n config.xml

Hope that helps.

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