Announcement Announcement Module
Collapse
No announcement yet.
Splitter from large xml to small xml chunks Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Splitter from large xml to small xml chunks

    Is there a way in Spring integration to chunk large xml file to small xml files. For e.g. The below xml I would like to divide into 2 xmls each containing 2 books.


    <?xml version="1.0" encoding="UTF-8"?>
    <BookCatalogue xmlns="http://www.publishing.org">
    <Book>
    <Title>Yogasana Vijnana: the Science of Yoga</Title>
    <Author>Dhirendra Brahmachari</Author>
    </Book>

    <Book>
    <Title>The First and Last Freedom</Title>
    <Author>J. Krishnamurti</Author>
    </Book>

    <Book>
    <Title>XXX The First and Last Freedom</Title>
    <Author>J. Krishnamurti</Author>
    </Book>

    <Book>
    <Title>YYY The First and Last Freedom</Title>
    <Author>J. Krishnamurti</Author>
    </Book>
    </BookCatalogue>

  • #2
    You might want to look at the XPath splitter (and its 'create-documents' attribute).

    http://static.springsource.org/sprin...path-splitting

    But, when you say *large* files, what size do you expect?

    Comment


    • #3
      Thanks for your reply Mark. I have checked the spring integration basic/xml example which is splitting. However, What I would be looking for is that the Book catalogue to be divided into files. Referencing to the above example, I would be looking to divide xml into 2 files each containing 2 books.
      file_1
      <?xml version="1.0" encoding="UTF-8"?>
      <BookCatalogue xmlns="http://www.publishing.org">
      <Book>
      <Title>Yogasana Vijnana: the Science of Yoga</Title>
      <Author>Dhirendra Brahmachari</Author>
      </Book>

      <Book>
      <Title>The First and Last Freedom</Title>
      <Author>J. Krishnamurti</Author>
      </Book>

      </BookCatalogue>

      file_2
      <?xml version="1.0" encoding="UTF-8"?>
      <BookCatalogue xmlns="http://www.publishing.org">
      <Book>
      <Title>XXX The First and Last Freedom</Title>
      <Author>J. Krishnamurti</Author>
      </Book>

      <Book>
      <Title>YYY The First and Last Freedom</Title>
      <Author>J. Krishnamurti</Author>
      </Book>
      </BookCatalogue>

      Comment


      • #4
        Hello!

        The first: try to wrap, please, your code with [ CODE ] & [ /CODE ] or [ HTML ] & [ /HTML ] without whitespaces to make your posts more readable.

        Now on the matter: don't try to mix the patterns in one place at once. Spring Integration components do what they are called.
        So, <si-xml:xpath-splitter> takes some Message with payload as Document, String or File and produces some xml-entity: Node or Document. But File isn't his responsibility.
        Then you should transform the 'Book' Document to the String through StringSourceFactory and payload#toString()
        and in the end just use <int-file:outbound-channel-adapter> to write each 'Book' into separate File.
        Also keep in mind: a splitter's 'output-channel' may be an ExecutorChannel to allow your process your sub-xml in the parallel manner.
        So, your config may be like this:
        HTML Code:
        <si-xml:xpath-splitter input-channel="input" output-channel="writeToFileChannel" create-documents="true">
        	<si-xml:xpath-expression expression="//Book"/>
        </si-xml:xpath-splitter>
        
        <si:channel id="writeToFileChannel">
        	<si:dispatcher task-executor="asyncTaskExecutor"/>
        </si:channel>
        
        <si:chain input-channel="writeToFileChannel">
        	<si:transformer ref="stringSourceFactory" method="createSource"/>
        	<si:transformer expression="payload.toString()"/>
        	<int-file:outbound-channel-adapter/>
        </si:chain>
        Try to improve it and let us know how it is.

        Cheers,
        Artem

        Comment

        Working...
        X