Results 1 to 7 of 7

Thread: Splitting XML Messages

  1. #1
    Join Date
    Sep 2008
    Location
    Mannheim,Germany
    Posts
    125

    Question Splitting XML Messages

    Hi, I have upgraded my application to SI 1.0. I have a JDOM document which already has a namespace prefix.How do I split them into each divisions when I already have a prefix "div". Also in svn repository the "xml" example compares only one orderItem's isbn but how to compare the rest of orderItem elements and also the "quantity" in tht example??Is it going to be a loop or is it possible with xpath to iterate through the elements. An example cod would be appreacited

    JDOM Document:
    Code:
    <div:divisionResponse xmlns:div="http://gid.com/div/schemas">
        <div:Divisions ID="1">
               <div:Division>AX</div:Division>
               <div:Name>CropProtection</div:Name>
               <div:Operational>Y</div:Operational>
               <div:ValidFrom>2000-01-01 00:00:00.0</div:ValidFrom>
               <div:ValidTo>9999-12-31 00:00:00.0</div:ValidTo>
       </div:Divisions>
    
        <div:Divisions ID="32">
                <div:Division>CS</div:Division>
               <div:Name>Inorganics</div:Name>
               <div:Operational>Y</div:Operational>
               <div:ValidFrom>2008-08-18 00:00:00.0</div:ValidFrom>
               <div:ValidTo>9999-12-31 00:00:00.0</div:ValidTo>
    </div:Divisions>
    </div:divisionResponse>
    I tried the following ways but none worked! Please let me know where did I go wrong.
    Trial 1
    Code:
    <si-xml:xpath-splitter id="divisionsSplitter" input-channel="documentChannel" output-channel="checkChangeChannel" create-documents="true">
    
    		<si-xml:xpath-expression expression="/divNs:divisionResponse/divNs:Divisions" namespace-map="divNamespaceMap"/>
    
    </si-xml:xpath-splitter>
    
    <util:map id="divNamespaceMap">
    		<beans:entry key="divNs" value="http://gid.com/div/schemas" />
    </util:map>
    <stream:stdout-channel-adapter id="checkChangeChannel"/>
    Trial 2:

    Code:
    <si-xml:xpath-splitter id="divisionsSplitter" input-channel="documentChannel" output-channel="checkChangeChannel" create-documents="true">
    		<si-xml:xpath-expression expression="/div:divisionResponse/div:Divisions" ns-prefix="div"  ns-uri="http://gid.com/div/schemas" />
    	</si-xml:xpath-splitter>
    <stream:stdout-channel-adapter id="checkChangeChannel"/>
    Last edited by ashleyvijay; Dec 8th, 2008 at 09:00 AM.

  2. #2
    Join Date
    Oct 2007
    Location
    London, England
    Posts
    108

    Default

    There is not currently any support for using JDOM in conjunction with any of the out of the box xml payload functionality. I suspect that you will find this message is being routed to the error channel.

    It would be possible to provide the XPathMessageSplitter with your own implementation of XmlPayloadConverter that can convert the org.jdom.Document to an org.w3c.dom.Node.

    Feel free to add a feature request to JIRA.
    Jonas Partner
    OpenCredo

  3. #3
    Join Date
    Sep 2008
    Location
    Mannheim,Germany
    Posts
    125

    Default

    Ah ok..Thanks for the info..Well if I convert to a Dom document I would still have the prefix so how would my XPath expression be??
    I created a Jira Issue as u said : http://jira.springframework.org/browse/INT-509
    Last edited by ashleyvijay; Dec 8th, 2008 at 10:48 AM.

  4. #4
    Join Date
    Oct 2007
    Location
    London, England
    Posts
    108

    Default

    Either should work as long as you are consistent with the prefix. Your two versions use 'divNs' and 'div' but they are consistent in themselves so that will be fine since the prefix does not need to match that used in the document.
    Jonas Partner
    OpenCredo

  5. #5
    Join Date
    Sep 2008
    Location
    Mannheim,Germany
    Posts
    125

    Default

    Hi,
    I know tht xpath splitter splits the xml messages according to xpath expressions.For example in the Bookprocessing example it splits the whole document into orderItems documents . I have a few questions in this area

    1.Are these splitted documents sent to the Stock checker all at once or are they sent one by one for processing??

    2. Does the below xpath expression extracts at a time all the isbns of all the orderItems or just the isbn for first orderItem or just the isbn for each orderItem after each one is processed ??
    Code:
    <si-xml:xpath-expression id="selectIsbnXpath" namespace-map="orderNamespaceMap" expression="/orderNs:orderItem/orderNs:isbn/text()" />

  6. #6
    Join Date
    Oct 2007
    Location
    London, England
    Posts
    108

    Default

    OK so what happens is the splitter evaluates the XPath on the document and returns a list of Nodes. Note it is Node by default if you want each Node returned by the XPath evaluation to be a Document you need to set create-documents="true". These are then set as the payload of a number of messages which are then sent to the reply channel. See AbstractMessageSplitter and AbstractReplyProducingMessageHandler for details.

    So as to whether they are sent one by one to whoever is further down the processing line this is not controlled by the splitter but is a function of the channel that the split messages are sent to. This is the way SI works. So a direct channel (default) will use the thread that passed the message into the splitter to send the message and that thread will be blocked while the message is processed. In the case of a queue channel the split messages will all be sent to the channel and the sending thread will not be blocked while they are processed down the line.

    Your second question is really a question on XPath but the short answer is that this will give you all ISBN's.
    Jonas Partner
    OpenCredo

  7. #7
    Join Date
    Sep 2008
    Location
    Mannheim,Germany
    Posts
    125

    Default

    Thank u so much for the explanation Jonas. Everything is clear!

Posting Permissions

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