By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,172 Members | 1,751 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,172 IT Pros & Developers. It's quick & easy.

split large xml files

P: n/a
Hi all,

I've an XML file that takes more than the hosting time limit to be readed by
a PHP script.

What I'd like to do is split the large XML file (can be more than 30MB) in
little parts and keep the header for every file.

Here is the idea:

<total>
<head>
</head>
<info>
</info>
<info>
</info>
<info>
</info>
....
</total>

The only change is the amount of "info" available. What I'd like is to split
the file to create littles ones whit the same <head></headdatas but each
with less <infotags (say limited to 3 for every file).

It's there any simple way ? This will only be done if the file is bigger
than 1MB

Bob
Aug 10 '07 #1
Share this Question
Share on Google+
6 Replies


P: n/a
$xml = simplexml_load_file($xmlFile);
And take it from there. Have a quick read of the simplexml docs. You
should
have your solution in very little time.
Thanks for replying....
after a quick search, I've to say I'm still in PHP 4 !!! damn !!!
Aug 10 '07 #2

P: n/a
Hem, what to say more than thank you !!!

I'll implement it...thanks
Aug 10 '07 #3

P: n/a
On 10.08.2007 11:21 David Gillen wrote:
Bob Bedford said:
>Hi all,

I've an XML file that takes more than the hosting time limit to be readed by
a PHP script.

What I'd like to do is split the large XML file (can be more than 30MB) in
little parts and keep the header for every file.

Here is the idea:

<total>
<head>
</head>
<info>
</info>
<info>
</info>
<info>
</info>
...
</total>

The only change is the amount of "info" available. What I'd like is to split
the file to create littles ones whit the same <head></headdatas but each
with less <infotags (say limited to 3 for every file).

It's there any simple way ? This will only be done if the file is bigger
than 1MB
$xml = simplexml_load_file($xmlFile);
And take it from there. Have a quick read of the simplexml docs. You should
have your solution in very little time.

Didn't test it, but I doubt simplexml would be able to load a 30MB xml
file. I think OP's best option is to use the tool that can read and
parse in small chunks, like expat (see
http://www.php.net/manual/en/function.xml-parse.php)
--
gosha bine

makrell ~ http://www.tagarga.com/blok/makrell
php done right ;) http://code.google.com/p/pihipi
Aug 10 '07 #4

P: n/a
On Aug 10, 2:34 am, "Bob Bedford" <b...@bedford.comwrote:
$xml = simplexml_load_file($xmlFile);
And take it from there. Have a quick read of the simplexml docs. You
should
have your solution in very little time.

Thanks for replying....
after a quick search, I've to say I'm still in PHP 4 !!! damn !!!
If you have files that big, simple xml is not an option, because the
memory will run out, and simple xml reads the whole file in memory and
makes a copy of it. What you really want is xml parsing in "streaming"
or "pull parsing" mode. You can read about it here:

http://www.ibm.com/developerworks/xm...nxw06XMLReader

However, I guess this is also not very helpful since you're running
PHP 4 and XMLReader has been introduced in PHP5. I am fighting this at
this moment also (with no solution yet), as I have to parse huge ONIX
files from book publishers (some are 90 Mb!). Let me know if you get
lucky.

Aug 10 '07 #5

P: n/a
..oO(Pavel Lepin)
>And your point is..?
Exactly what I said. The posted code doesn't follow any coding
guidelines and is _very_ hard to read and understand.

Micha
Aug 14 '07 #6

P: n/a

Michael Fesser <ne*****@gmx.dewrote in
<45********************************@4ax.com>:
.oO(Pavel Lepin)
>>And your point is..?

Exactly what I said. The posted code doesn't follow any
coding guidelines
The code I posted follows the PHP coding style guidelines
(the variant for short code snippets in our dev dept's CMS)
of the organisation I'm working for. I don't think I should
snap out of my habits (that weren't all that easy to
develop to boot, since the coding style I personally prefer
uses *way* more whitespace that the snippet in my OP) just
for the sake of your ease of understanding. Not only you
aren't signing my paychecks, other people might actually
find the code easier to read in the style I used, so no
reason to give you any preference.
and is _very_ hard to read and understand.
I find the coding style promoted by Zend IDE ugly and hard
to parse even with syntax highlighting, let alone by naked
eye. It's a matter of perception, and if you believe
there's any sort of consensus on preferable coding style
even in PHP community alone, you're sadly mistaken.

--
"Patience is a minor form of despair, disguised as
virtue." -- Ambrose Bierce
Aug 14 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.