开发者

namespace error when using XMLStarlet

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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜