Announcement Announcement Module
Collapse
No announcement yet.
Namespace issue in spring-integration Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Namespace issue in spring-integration

    Hi Guys,

    I have written custom message selector which uses xpath expressions to evaluate incoming messages but evaluation fails due to presence of xmlns='http://svn.msk.trd.ru/xsd/fixml'. If I remove it then xpath evaluation succeeds. I have tried to specify namespace and passed it to createXPathExpression but it did not solve my problem:

    Map<String, String> namespaces = new HashMap<String, String>();
    namespaces.put("", "http://svn.msk.trd.ru/xsd/fixml");
    XPathExpressionFactory.createXPathExpression(xPath Expression, namespaces);


    Can you please help me out with that.

    Here is sample XML message:

    <?xml version='1.0' encoding='UTF-8' standalone='yes'?><TrdCaptRpt xmlns='http://svn.msk.trd.ru/xsd/fixml' TrdID='3233345' TransTyp='0' RptTyp='2' TrdTyp='54' ExecTyp='F' RptID2='3233345' QtyTyp='0' LastQty='100' LastPx='1540.65' Ccy='RUR' SettlCcy='RUR' TrdDt='2011-11-28T17:16:06.261+03:00' TxnTm='2011-11-28T17:16:06.261+03:00' SettlDt='2011-11-28T17:16:06.261+03:00' ValueDt='2011-11-28T17:16:06.261+03:00'><Instrmt Sym='GAZP' CFI='OECCN'/><RptSide Side='2' AcrdIntAmt='0' NetMny='100' SettlCurrAmt='100' BOTrdType='Обл2Трд' BOTrdType2='1' BOTrdIdCounter='1'><Pty ID='**CPMP_A' R='1'/><Pty ID='SYSTEM_A' R='16'/><Pty ID='*FI' R='83'/><Pty ID='Cliring' R='1101'/><Pty ID='**CPMP_A' R='1102'/><Pty ID='*TD_A' R='1103'/><Pty ID='0' R='1104'/><Pty ID='DEUCH' R='1105'/><Pty ID='' R='1106'/><Pty ID='0' R='1107'/></RptSide></TrdCaptRpt>

  • #2
    Hi,

    Sorry for the belated response. This is an interesting issue. It is actually not related to Spring Integration but just how the underlying JAXP implementation works (and I believe Jaxen would handle this similarly; see link below).

    Essentially you have 2 options to handle your use-case:

    1) Don't provide a namespace prefix (Just an empty String. Null is not allowed.). Then your Xpath Expression will use a colon ":" to indicate the default namespace. If you leave the colon off, the XPath expression will not match.

    Code:
     BooleanTestXPathMessageSelector selector = new BooleanTestXPathMessageSelector(
         "boolean(/:TrdCaptRpt)", "", "http://svn.msk.trd.ru/xsd/fixml");
    
     selector.accept(new GenericMessage<String>(xml)));
    2) The second option is to provide an arbitrarily chosen namespace prefix. It turns out that the namespace Uri is the really important piece of information, not the prefix itself. Please see the following explanation at:

    http://jaxen.codehaus.org/faq.html

    "In XPath 1.0, all unprefixed names are unqualified. There is no requirement that the prefixes used in the XPath expression are the same as the prefixes used in the document being queried. Only the namespace URIs need to match, not the prefixes."

    Therefore, the following example will work as well:

    Code:
     BooleanTestXPathMessageSelector selector = new BooleanTestXPathMessageSelector(
         "boolean(/foobar:TrdCaptRpt)", "foobar", "http://svn.msk.trd.ru/xsd/fixml");
    
     selector.accept(new GenericMessage<String>(xml)));
    Both example (using your provided XML sample) will return true. For some more explanations, please see:

    http://www.edankert.com/defaultnamespaces.html

    I certainly agree that this is poorly (not) documented in our reference docs and not easily to find on the internet either. Therefore, I have created a Jira to improve the respective documentation: https://jira.springsource.org/browse/INT-2292

    Cheers,

    Comment


    • #3
      Hi,

      Thank you very much for your response! I will definitely look into your options. By the way, I have found another possible solution to my problem which is to ignore namespaces and still get desirable result. The solution is to use XPath local-name() function which allows to get expected result and don't worry about namespaces.

      Cheers

      Comment

      Working...
      X