Results 1 to 3 of 3

Thread: Namespace issue in spring-integration

  1. #1
    Join Date
    Oct 2011
    Posts
    2

    Default 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. #2
    Join Date
    Aug 2005
    Location
    Atlanta
    Posts
    124

    Default

    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,
    Gunnar Hillert
    SpringSource/VMWare, Spring Integration team
    SpringSource Team - Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/ghillert
    http://blog.hillert.com/
    http://blog.springsource.com/author/ghillert/

  3. #3
    Join Date
    Oct 2011
    Posts
    2

    Default

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •