[英]How to get the xpath of the namespace attribute using java
How to get the xpath of the below jaxrs:server element using java? 如何使用Java获取以下jaxrs:server元素的xpath? 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. HardcodedNamespaceResolver
类有我需要用我遵守的所有命名空间这个文章做。
I tested this in .NET, and I figured XPATH is XPATH, right? 我在.NET中对此进行了测试,发现XPATH是XPATH,对吗?
"//*[namespace-uri(.)='http://cxf.apache.org/jaxrs']"
Let me know if it works. 让我知道它是否有效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.