views:

185

answers:

1

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?

+1  A: 

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/"&gt;

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.

Simon Brangwin