Thursday, November 25, 2010

Avoid namespace verification in xpath processing


Recently I dealt with a lot of xpath expressions, when implementing and it becomes cumbersome sometime to concern on namespaces when it’s not that much essential. We can use Regular expressions to bypass the namespace verfication on xpath.

eg -
<bpel:from part="payload" variable="profileProcessorInput">
    <bpel:query queryLanguage="urn:oasis:names:tc:wsbpel:2.0:sublang:xpath1.0">
        <![CDATA[tns:profiles/ns1:Profile[round($itemIterator)]/ns1:club_code]]>
    </bpel:query>
</bpel:from>  

Can be replaced by
<bpel:from part="payload" variable="profileProcessorInput">
    <bpel:query queryLanguage="urn:oasis:names:tc:wsbpel:2.0:sublang:xpath1.0">
        <![CDATA[tns:profiles/*[local-name() = 'Profile'][round($itemIterator)]/*[local-name() = 'club_code']]]>
    </bpel:query>
</bpel:from>

1 comment:

Kabeer said...

If you are struggling with xml namespaces, there is a great tutorial on xpath namespaces at xml reports. It walks you through it in very simple steps
URL: http://www.xml-reports.com/2011/05/xml-namespaces-for-dummies-part-1.html