1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Split Xml by lines

Discussion in 'General Programming Chat' started by NosokOrg, Jan 16, 2016.

Tags:
  1. NosokOrg

    NosokOrg Jr. VIP Jr. VIP

    Joined:
    Jun 21, 2015
    Messages:
    155
    Likes Received:
    16
    Hello to all. I have a regular task to split large xml files ( for example 580k lines ) to little files by 10k lines in each? Is any some script or solution to make it automatically ?
     
  2. jazzc

    jazzc Moderator Staff Member Moderator Jr. VIP

    Joined:
    Jan 27, 2009
    Messages:
    2,612
    Likes Received:
    11,243
    Occupation:
    Pusillanimous Knitter
    Location:
    Buenos Aires
    If it was plain text, sure - but xml has structure, it's not just standalone lines.
     
    • Thanks Thanks x 1
  3. NosokOrg

    NosokOrg Jr. VIP Jr. VIP

    Joined:
    Jun 21, 2015
    Messages:
    155
    Likes Received:
    16
    EmEditor works fine in windows. Not automatically, but dont suspend in case to open large file.
     
  4. AppCentral

    AppCentral Newbie

    Joined:
    Oct 7, 2015
    Messages:
    32
    Likes Received:
    8
    It's as Jazzc says, there's no reason to split XML up into seperate lines, as it's not a line-by-line format, however if you still want to do this you can write a simple application to do so, take a look at the BufferedReader and BufferedWriter classes in Java. You can write an application with minimal programming knowledge to do this in around ten minutes.
     
    • Thanks Thanks x 2
  5. Sheraf

    Sheraf Registered Member

    Joined:
    Jan 19, 2014
    Messages:
    61
    Likes Received:
    8
    Depends the structure of your file and why do you want to split it for.
    If you have a main root tag and then a bunch of subitem, you probably want to recreate the root tag in each splitted file.
    You should start by finding an xml library for the language you're using, then read the file into some kind of array, from here you'll be able to split easily, then write it back using that same library.
     
  6. nonin

    nonin Power Member

    Joined:
    Apr 26, 2010
    Messages:
    732
    Likes Received:
    501
    Gender:
    Male
    Location:
    I connect dots..
    Home Page:
    as far as I know - no, you can't do that.

    but, is there a chance the size is that huge as you don't use css?
     
  7. Sheraf

    Sheraf Registered Member

    Joined:
    Jan 19, 2014
    Messages:
    61
    Likes Received:
    8
    What's css doing in here?
     
  8. xrfanatic

    xrfanatic Jr. VIP Jr. VIP

    Joined:
    Aug 28, 2010
    Messages:
    419
    Likes Received:
    176
    Location:
    http://bit.ly/slb64
    Home Page:
    OP, can you post an example of what exactly you would like to achieve ? If so, maybe I will be able to help you.
     
  9. kahuna74

    kahuna74 Regular Member

    Joined:
    Aug 19, 2014
    Messages:
    270
    Likes Received:
    102
    Gender:
    Male
    Occupation:
    Software Developer
    Location:
    Grand Rapids, MI
    Why would you want to do that? Obviously you're going to have to process the file, and what if one chunk only has half of a node? Bam. Invalid XML and you won't be able to read it. Grab the entire file and use an efficient parser. There's one for every programming language.