I am trying to extract the database credentials from standalone.xml(Wildfly 9.0) (link to 8.1 version). Using XPath for this, I am facing the issue that my XPathExpression
is not working correctly,
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = null;
builder = factory.newDocumentBuilder();
org.w3c.dom.Document doc = builder.parse(System.getProperty("jboss.server.config.dir") + "/standalone.xml");
XPathFactory xPathfactory = XPathFactory.newInstance();
XPath xpath = xPathfactory.newXPath();
XPathExpression expr = xpath.compile("/server/subsystem[@xmlns='urn:jboss:domain:datasources:3.0']/text()");
NodeList nl = (NodeList)expr.evaluate(doc, XPathConstants.NODESET);
System.out.println("NodeList count " + nl.getLength());
the line,
"/server/subsystem[@xmlns='urn:jboss:domain:datasources:3.0']/text()"
is not fetching the nodes from the subsystem element(NodeList count is 0),
"/server"
works fine(NodeList count is 7).Below is the file,
<server xmlns="urn:jboss:domain:3.0">
<profile>
<subsystem xmlns="urn:jboss:domain:bean-validation:1.0"/>
<subsystem xmlns="urn:jboss:domain:datasources:3.0">
<datasources>
<datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true">
<connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE</connection-url>
<driver>h2</driver>
<security>
<user-name>sa</user-name>
<password>sa</password>
</security>
</datasource>
</datasources>
</subsystem>
<subsystem xmlns="urn:jboss:domain:deployment-scanner:2.0">
<deployment-scanner path="deployments" relative-to="jboss.server.base.dir" scan-interval="5000" runtime-failure-causes-rollback="${jboss.deployment.scanner.rollback.on.failure:false}"/>
</subsystem>
</profile>
</server>
Can anyone please tell me what is the issue here?