marcinwieckowski opened a new pull request, #25561:
URL: https://github.com/apache/camel/pull/25561

   # Description
   
   Adds a `namespacesRef` attribute to `NamespaceAwareExpression` (the shared 
base class for `XPathExpression`, `XQueryExpression`, and 
`XMLTokenizerExpression`/xtokenize), letting users reference a registry bean 
instead of declaring namespaces inline.
   
   **Why**: today, namespace-aware languages only support namespaces declared 
inline via `<namespace>` child elements (or programmatically via a 
`Map`/`Namespaces` object in Java DSL). There's no way to define a reusable set 
of namespace mappings once and reference it by name from multiple 
expressions/routes, which becomes repetitive for XML payloads with many 
namespaces reused across a route's XPath conditions.
   
   **How**:
   - `namespacesRef` is a plain string attribute (bean id) on 
`NamespaceAwareExpression`, available to XPath, XQuery, and Xtokenize.
   - At reification time (`XPathExpressionReifier`, `XQueryExpressionReifier`, 
`XMLTokenizerExpressionReifier`), if no inline namespaces are present, the 
referenced bean is looked up via `mandatoryLookup(ref, Namespaces.class)` — 
intentionally typed to `org.apache.camel.support.builder.Namespaces` - the same 
class used in Java DSL for xpath namespaces.
   - Inline `<namespace>` elements still take priority when present, for 
backward compatibility.
   - Works across all three configuration surfaces: Java DSL (via the model 
API), XML DSL, and YAML DSL — including defining the `Namespaces` bean itself 
declaratively (XML `<bean>` / YAML `beans:`), using Camel's `foo[bar]` 
map-syntax property binding against `Namespaces.getNamespaces()`.
   
   **Tests**: one test per surface (`camel-core`, `camel-xml-io-dsl`, 
`camel-yaml-dsl`), each covering a bean with two namespace prefixes, a positive 
match per namespace, a data-mismatch negative (correct namespace, wrong value), 
and a namespace-mismatch negative (correct value, wrong namespace URI).
   
   # Target
   
   - [x] I checked that the commit is targeting the correct branch (Camel 4 
uses the `main` branch)
   
   # Tracking
   
   - [ ] If this is a large change, bug fix, or code improvement, I checked 
there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for 
the change :   >>>>> I didnt create a Jira for that feature, it is something we 
needed in our internal project and decided it is general and useful enough to 
share.
   
   # Apache Camel coding standards and style
   
   - [x] I checked that each commit in the pull request has a meaningful 
subject line and body.
   - [x] I have run `mvn clean install -DskipTests` locally from root folder 
and I have committed all auto-generated changes.
   
   # AI-assisted contributions
   
   - [x] If this PR includes AI-generated code, commits have proper 
co-authorship attribution (e.g., `Co-authored-by` trailers) and the PR 
description identifies the AI tool used.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to