0

I would like to keep these question as generic as possible so it is relevant for others as I believe it is a common question/query that people face over and over.

This question has been asked before but the answers weren't very detailed or specific or overly complex eg code that isn't commented or a reference to another site

Okay there can be many reasons to need to split a large XML file into smaller ones to be processed and in my case it is due to My hosting provider placing a 30 second timeout rule on script execution

So in the most simple form lets say our XML file is

<section1>
<bla1>bla</bla1>
<bla2>bla</bla2>
<bla3>bla</bla3>
<bla4>bla</bla4>
</section1>

<section2>
<bla1>bla</bla1>
<bla2>bla</bla2>
<bla3>bla</bla3>
<bla4>bla</bla4>
</section2>

And so on. Could someone please provide a solution in php that demonstrates how to split this into 2 seperate files whilst clearly adding comment lines explaining what exactly is going on?

So we want section 1 in a file and section 2 in another

I believe a clear solution to this will be very beneficial now and to future people searching for a solution to this common question

THIS QUESTION HAS BEEN ASKED BUT NOT FULLY CORRECTLY ANSWERED AS I STILL HAVE NO IDEA HOW TO DO IT

user1396585
  • 41
  • 1
  • 5
  • 2
    Think about using a streaming parser (SAX) instead of trying to split the XML file purely for performance reasons. Streaming parsers can be a lot faster with large files (and they conserve memory, too). Besides, "code that isn't commented" does not necessarily make a bad answer. – Tomalak Feb 14 '14 at 08:16
  • Thanks but this isn't an option I already have a system developed a website that parses XML files and processes them fine. The issue is the XML files imports have a 30 second timeout imposed by my host. So could you provide a well documented solution for everyone including me and for future reference. Help from anyone would be appreciated – user1396585 Feb 19 '14 at 09:39
  • *"could you provide a well-documented solution"* I probably could, but unfortunately the purpose of this website is not to find people who do your work for you, but to find people who can give you reasonable advice with programming problems you encounter. (And no, *"I need complex system X because I have no idea how to do it"* is *not* a programming problem.) The advice here was to try SAX. This advice is reasonable. *"Not an option because I already have something that works"* is not a useful response to that, because obviously you currently have something that doesn't work. – Tomalak Feb 19 '14 at 09:49
  • Don't get me wrong, we're still here to help. It just doesn't work the way you're currently trying it with. Here's an idea. Post the PHP code you currently have to a new question. Strip it down to the most basic version. Post a sample of an input XML file along with your code. Describe in detail what output you expect. Ask "this takes a long time to complete for large XML files, how can I make it faster?". Wait what people suggest, try their suggestions. Be prepared to throw away or re-write your existing code. – Tomalak Feb 19 '14 at 09:54

0 Answers0