How do you get a node via XPath that is namespace-aware?
I realise it has to do with the PrefixResolver that you pass in as an argument to either the XPath constructor or to the XPath.execute(), but I am not sure how to go about it.
e.g.: 1) Do you need to pass the same resolver in both the constructor and the execute method? 2) How do I specify my expressions?
Take for example this fragment of XML
<mm7:SubmitReq xmlns:mm7="http://www.3gpp.org/ftp/Specs/archive/23_series/23.140/schema/REL-5-MM7-1-2"> <mm7:MM7Version>5.5.0</mm7:MM7Version> <mm7:SenderIdentification> <mm7:VASPID>MIG</mm7:VASPID> <mm7:VASID>Mig-test4</mm7:VASID> <mm7:SenderAddress> <mm7:Number>+6140955555</mm7:Number> </mm7:SenderAddress> </mm7:SenderIdentification>
... The above SubmitReq element is not the root element, but is obtained via Apache-SOAP:
Node submitReqNode = (Node) envelope.getBody().getBodyEntries().get( 0 );
Now once I got the SubmitReq node above, here's what I do:
PrefixResolverDefault resolver = new PrefixResolverDefault( submitReqNode ); XPath xpath = new XPath( "//SenderIdentification/SenderAddress/Number", this.locator, resolver, XPath.SELECT ); XObject xobject = xpath.execute( context, submitReqNode, resolver ); String senderString = (String) xobject.castToType( XObject.CLASS_STRING, context );
The above code will not retrieve the the number +6140955555. ... but it will if I remove the mm7 prefixes.
So what do I need to do? I would have assumed that PrefixResolverDefault would have been namespace-aware.
