Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xpath with namespaces (XPath 2.0 support) #234

Closed
assimbly opened this issue Jun 5, 2019 · 3 comments
Closed

Xpath with namespaces (XPath 2.0 support) #234

assimbly opened this issue Jun 5, 2019 · 3 comments
Assignees
Milestone

Comments

@assimbly
Copy link
Collaborator

assimbly commented Jun 5, 2019

Currently only default links are supported like this:

/root/somefiled/text()

How sometimes there are namespaces:

/hdr:root/xf:somefiled/text()

The code in Assimbly code connector can be found in this file:

https://github.com/assimbly/connector/blob/master/src/main/java/org/assimbly/connector/routes/DefaultRoute.java

On line 235 the xpath is used

The is xpath on headers. See:

https://github.com/apache/camel/blob/master/components/camel-xpath/src/main/docs/xpath-language.adoc
https://people.apache.org/~dkulp/camel/xpath.html

Preferable the user can use the xpath with namespace without using the url (setting)

@assimbly assimbly added this to the 1.5.1 milestone Jun 5, 2019
@dhardjo
Copy link
Collaborator

dhardjo commented Jun 20, 2019

I used the following XML with NS to conduct related Integration tests:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soapenv:Header>
      <metadata xmlns="http://ns.yyyy.nl/msg/header/v2">
         <timestamp>2014-01-09T13:33:55.804Z</timestamp>
         <application>TRC</application>
         <service>externalevent</service>
         <label>Company XXX B.V.</label>
         <debiteurnummer>1299342999</debiteurnummer>
         <operatie>voorlopigeVorderingVastgelegd</operatie>
         <messageId>00f790f8-b812-407e-b178-9028bb02f05c</messageId>
         <correlationId>00f790f8-b812-407e-b178-9028bb02f05c</correlationId>
         <userId>TRC</userId>
         <environment>ONT</environment>
      </metadata>
   </soapenv:Header>
   <soapenv:Body>
      <ns5:voorlopigeVorderingVastgelegd xmlns="http://ns.yyyy.nl/msg/debiteur/v1" xmlns:ns2="http://ns.yyyy.nl/msg/transactie/v1" xmlns:ns3="http://ns.yyyy.nl/msg/financieelproduct/v1" xmlns:ns4="http://ns.yyyy.nl/msg/bankrekening/v1" xmlns:ns5="http://ns.yyyy.nl/events/ext/transactie/v1">
         <klantnummerExternePartij>
            <klantnummer>99342999</klantnummer>
         </klantnummerExternePartij>
         <ns2:transactie>
            <ns2:actor>TRC</ns2:actor>
            <**ns2:label**>Company XXX B.V.<**/ns2:label**>
            <ns2:debiteurnummer>1299342999</ns2:debiteurnummer>
         </ns2:transactie>
      </ns5:voorlopigeVorderingVastgelegd>
   </soapenv:Body>
</soapenv:Envelope>

On June 19 (yesterday) I tested the XPathBuilder handling by defining within the JHipster/Angular Headers as follows:

Key label01 with XPath expression value: //[local-name()='transactie']/[local-name()='label']/text()
Key label02 with XPath expression value: //ns2:label/text()
Key label03 with XPath expression value: //label/text()

label02 causes:

org.apache.camel.builder.xml.InvalidXPathExpression: Invalid xpath: //ns2:label/text(). Reason: javax.xml.xpath.XPathExpressionException: com.sun.org.apache.xpath.internal.domapi.XPathStylesheetDOM3Exception: Prefix must resolve to a namespace: ns2

label03 returned only an empty "no result", and

label01 is the only expression that returns a viable correct result, albeit that it remains more verbose than the other two label XPath expressions, of course.

Conclusion: we have stick to the verbose local-name() for NS-prefix XML tag based XPath / XPathBuilder extraction from the XML (soap) payload to the desired header key values.

@dhardjo
Copy link
Collaborator

dhardjo commented Jun 20, 2019

Of course, in the XML above, instead of <**ns2:label**>Company XXX B.V.<**/ns2:label**> one should read: <ns2:label>Company XXX B.V.</ns2:label>

@assimbly assimbly changed the title Xpath with namespaces Xpath with namespaces (XPath 2.0 support) Jun 29, 2019
@assimbly assimbly modified the milestones: 1.5.1, 1.6.0 Jun 29, 2019
@assimbly
Copy link
Collaborator Author

Test the xpath functionality. Now users can use the asterisk * signs

@assimbly assimbly removed their assignment Jul 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant