How to get the xpath of the below jaxrs:server element using java? I can't solve it.
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:jaxrs="http://cxf.apache.org/jaxrs" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://cxf.apache.org/bindings/soap http://cxf.apache.org/schemas/configuration/soap.xsd http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd">
<bean id="discoverRSByeBean" class="discovery.hello.DiscoverRSBye"/>
<jaxrs:server id="discoverRSBye" address="/discover_r_s_bye">
<jaxrs:serviceBeans>
<ref bean="discoverRSByeBean"/>
</jaxrs:serviceBeans>
</jaxrs:server>
<bean id="DiscoveryRSHelloBean" class="discovery.hello.DiscoveryRSHello"/>
<jaxrs:server id="DiscoveryRSHello" address="/discovery_r_s_hello">
<jaxrs:serviceBeans>
<ref bean="DiscoveryRSHelloBean"/>
</jaxrs:serviceBeans>
</jaxrs:server>
</beans>
here is the code segment i used
InputStream configStream = getConfigLocation(context.getServletContext());
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(configStream);
XPathFactory xPathfactory = XPathFactory.newInstance();
XPath xpath = xPathfactory.newXPath();
xpath.setNamespaceContext(new HardcodedNamespaceResolver());
NodeList nodeList = (NodeList) xpath.evaluate("beans/jaxrs:server", doc, XPathConstants.NODESET);
HardcodedNamespaceResolver class have all the namespace I need to use I followed this article to do it.
<beans>node is in default namespace, if you followed the article correctly -and if I understood the article correctly-, this should work ::beans/jaxrs:servernotice colon (:) at the beginning of the xpath