tags:

views:

35

answers:

1

Hi, I am trying to get the XPath "/deployment/service". Tested on this site: http://www.xmlme.com/XpathTool.aspx

<?xml version="1.0" encoding="UTF-8" standalone="no"?>

<deployment xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org  /axis/wsdd/providers/java">

 <service name="kontowebservice" provider="java:RPC" style="rpc" use="literal">
  <parameter name="wsdlTargetNamespace" value="http://strategies.spine"/&gt;
  <parameter name="wsdlServiceElement" value="ExposerService"/>
  <parameter name="wsdlServicePort" value="kontowebservice"/>
  <parameter name="className" value="some.package.internal.KontoWebServiceImpl_WS"/>
  <parameter name="wsdlPortType" value="Exposer"/>
  <parameter name="typeMappingVersion" value="1.2"/>
  <operation xmlns:operNS="http://strategies.spine" xmlns:rtns="http://www.w3.org/2001/XMLSchema" name="expose" qname="operNS:expose" returnQName="exposeReturn" returnType="rtns:anyType" soapAction="">
    <parameter xmlns:tns="http://www.w3.org/2001/XMLSchema" qname="in0" type="tns:anyType"/>
  </operation>
  <parameter name="allowedMethods" value="expose"/>
  <parameter name="scope" value="Request"/>

</service>
</deployment>

I absolutely can't find out why it always tells me that my xpath does not match... This may be stupid, but am I missing something?

EDIT

Thanks to the answer from Dimitre Novatchev I was able to find a workaround:

<xmltask failwithoutmatch="true" report="false">
    <fileset dir="${src.gen}/" includes="**/*-deploy.wsdd" />
    <copy path="//*[local-name()='service']" buffer="tmpServiceBuf" append="true" />
</xmltask>
<xmltask failwithoutmatch="true" report="false" source="${basedir}/env/axis/WEB-INF/server-config.wsdd" dest="${build.stage}/resources/WEB-INF/server-config.wsdd">
    <insert path="//*[local-name()='transport'][last()]" buffer="tmpServiceBuf" position="after" />
</xmltask>

Binding namespaces with xmltask (which is the tool that gave me the headaches) seems not to be possible. The code above did the trick.

+1  A: 

The Problem: This XML document has a default namespace. XPath considers any unprefixed names to be in "no-namespace". It tries to select /deployment/service where the elements deployment and service are in no-namespace and doesn't select any node, because in the provided XML documents there are no such elements that are in "no- namespace (they all are in the "http://xml.apache.org/axis/wsdd/" namespace)

The solution: Using the language which hosts XPath (such as C#, Jave, XSLT, or any other language that you may be using) bind a prefix (say x:) to the namespace "http://xml.apache.org/axis/wsdd/".

Then, change:

/deployment/service

to

/x:deployment/x:service

Now the last XPath expression correctly selects the desired node.

Dimitre Novatchev