Solved

Splitting a large XML file into smaller ones

Posted on 2004-04-10
5
398 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Problem to event 3 112
XSLT list item selection criteria not working 12 37
How can I assign SimpleXMLElements to variables? 5 71
ASP.NET reading ATOM 2 73
The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

763 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