Solved

Splitting a large XML file into smaller ones

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Load XML file into a SQL Server Table using SSIS 2012 9 76
API Soap Calls 4 116
XSLT: how to increment number value if attribute present 4 43
XML XSLT If loop 4 26
The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

772 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