Solved

Splitting a large XML file into smaller ones

Posted on 2004-04-10
5
391 Views
Last Modified: 2008-03-10
I have a large XML similar to the one below:

<BookStore>
<Book>book1</Book>
<Book>book2</Book>
.....
<Book>book1000</Book>
<Book>book1001</Book>
......
</BookStore>

The <Book> element may occur in 1000's. I want to create several smaller XML file each containing say only 250 <Book> elements. As far as I know, the two ways it could be done is either using XSLT or loading the entire XML into a DataSet and then create smaller subset DataSets. Since I am not an expert on either of them, any help is appreciated
0
Comment
Question by:nadarajan
5 Comments
 
LVL 15

Accepted Solution

by:
dualsoul earned 250 total points
ID: 10798331
It can be done in a number of ways.

1. You can do it without xml processing at all. Just use regular exprssions to get <Book>....</Book>  string and output them to different files by 250 per file.

2. You can do it thourgh SAX or XmlReader interfaces. Read portions of 250 Book elements and output them to different files. For me, i'll prefer SAX solution.

3. You can use DOM model, and traverse through Book elements saving them to file by 250. Easy to write this one :)

4. You can write XSLT to output to different files, something like this:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
      
      <xsl:template match="/">
            <xsl:for-each select="BookStore/Book">
                  <xsl:if test="position() mod 250=0">
                        <!-- change output file name here -->                  
                  </xsl:if>
                  
                  <xsl:copy-of select="."/>
            </xsl:for-each>
      </xsl:template>
</xsl:stylesheet>

, but the mechanism to change output file depends on particular XSLT processor, so if tell us what's yout XSLT processor....we can help you more.

So, you see, there are number of options :)
0
 
LVL 6

Assisted Solution

by:metalmickey
metalmickey earned 250 total points
ID: 10805650
Dual soul fixed summut for me recently that divides xml docs

http://www-106.ibm.com/developerworks/xml/library/x-tipdivbig/

i think it uses a java class....

anyway heres my roginal prob and  Dualsouls solution

http://oldlook.experts-exchange.com:8080/Web/Web_Languages/XML/Q_20908134.html

No points please

MM
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Automatically Generate Documents from XML database 10 46
XSLT question to add element to a particular xpath... 13 30
DOM question 5 78
parse convert xml feed to text (python) 2 66
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now