1

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.

1
  • <beans> node is in default namespace, if you followed the article correctly -and if I understood the article correctly-, this should work : :beans/jaxrs:server notice colon (:) at the beginning of the xpath Commented Apr 29, 2015 at 8:14

1 Answer 1

1

I tested this in .NET, and I figured XPATH is XPATH, right?

"//*[namespace-uri(.)='http://cxf.apache.org/jaxrs']"

Let me know if it works.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.