简体   繁体   中英

How to read attributes using XML apache commons configuration

I am using Apache Commons Configuration for reading configuration in xml file - standalone-full-ha.xml in Wildfly 8 application server.

<?xml version="1.0" ?>
<server xmlns="urn:jboss:domain:2.2">
...
...
<profile>
...
...
  <subsystem xmlns="urn:jboss:domain:datasources:2.0">
    <datasources>
      <datasource jta="true" jndi-name="java:/TestDB" pool-name="TestDB" enabled="true" use-java-context="true" spy="false" use-ccm="true">
      <connection-url>jdbc:sybase:Tds:ip:port/db-name</connection-url>
      ...
...
  </subsystem>
 </profile>
</server>

How to read jndi name java:/TestDB and connection url jdbc:sybase:Tds:ip:port/db-name from the above xml.

I tried the below but no result is obtained.

XMLConfiguration conf = new XMLConfiguration();
((XMLConfiguration) conf).setDelimiterParsingDisabled(true);
((XMLConfiguration) conf).load("xml file location");
String url = conf.getString("server/profile/subsystem[xmlns= 'urn:jboss:domain:datasources:2.0']/datasources/datasource/connection-url");
String jndiName = conf.getString("server/profile/subsystem[xmlns= 'urn:jboss:domain:datasources:2.0']/datasources/datasource[jndi-name]");

Can anyone please suggest about how to read jndi name and connection url from the xml using XML apache commons configuration. Thanks.

WildFly has a Management API

( https://docs.jboss.org/author/display/WFLY8/Management+API+reference )

I would suggest using that API in order to Access the WildFly Configuration instead of parsing it 'manually'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM