Video of XML splitter script for splitting XML files

This screencast video demonstrates splitting a large XML file with the free firstobject XML editor (be sure to get release 2.3.5 or later), much the same as I explained how to do with CMarkup in the article Split XML file into smaller pieces. Below the video you will find a copy of the script used in the video.

Here is the script shown in the video. I've highlighted the following things you will need to change to fit your own purposes:

  • 50MB.xml - open your own input filename
  • //ACT - loop through the elements in the input file that you need to transfer
  • piece - name your output files
  • root - name your root element and any container elements needed in the output file
  • 5 - set the maximum of those subdocuments per output file
  • split()
    {
      CMarkup xmlInput, xmlOutput;
      xmlInput.Open( "50MB.xml", MDF_READFILE );
      int nObjectCount = 0, nFileCount = 0;
      while ( xmlInput.FindElem("//ACT") )
      {
        if ( nObjectCount == 0 )
        {
          ++nFileCount;
          xmlOutput.Open( "piece" + nFileCount + ".xml", MDF_WRITEFILE );
          xmlOutput.AddElem( "root" );
          xmlOutput.IntoElem();
        }
        xmlOutput.AddSubDoc( xmlInput.GetSubDoc() );
        ++nObjectCount;
        if ( nObjectCount == 5 )
        {
          xmlOutput.Close();
          nObjectCount = 0;
        }
      }
      if ( nObjectCount )
        xmlOutput.Close();
      xmlInput.Close();
      return nFileCount;
    }

    There is also another article about how to split XML with the editor and naming the output files based on information contained in the XML.

    See also:

    Format XML, indent align beautify clean up XML
    Tree customization in the firstobject XML editor
    firstobject Access Language
    Counting XML tag names and values with foal
    Convert ANSI file to Unicode