xml - How to get the xpath of the namespace attribute using java -
how xpath of below jaxrs:server element using java? 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 code segment 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 namespace need use followed this article it.
i tested in .net, , figured xpath xpath, right?
"//*[namespace-uri(.)='http://cxf.apache.org/jaxrs']"
let me know if works.
Comments
Post a Comment