phpxmlmongodbwikipedia

How to import Wikipedia XML dump into MongoDB?


I used this PHP code:

https://github.com/kodekrash/wikipedia.org-xmldump-mongodb

get the dataset by:

wget -c http://wikipedia.c3sl.ufpr.br/enwiki/20150901/enwiki-20150901-pages-articles.xml.bz2

It is quite large, at 12GB.

I changed the corresponding configuration:

$dsname = 'mongodb://wiki:wiki@localhost:27017/wikipedia';
$file = '../data/enwiki-20150901-pages-articles.xml.bz2';
$logpath = './';

and run from the command line:

php wikipedia.org-xmldump-mongodb.php

I get this error:

    PHP Warning:  simplexml_load_string(): Entity: line 37: parser error : expected '>' in /home/username/wiki-project/wikipedia.org-xmldump-mongodb/wikipedia.org-xmldump-mongodb.php on line 73
PHP Warning:  simplexml_load_string(): </namespaces> in /home/username/wiki-project/wikipedia.org-xmldump-mongodb/wikipedia.org-xmldump-mongodb.php on line 73
PHP Warning:  simplexml_load_string():            ^ in /home/username/wiki-project/wikipedia.org-xmldump-mongodb/wikipedia.org-xmldump-mongodb.php on line 73
PHP Warning:  simplexml_load_string(): Entity: line 38: parser error : Premature end of data in tag namespace line 34 in /home/username/wiki-project/wikipedia.org-xmldump-mongodb/wikipedia.org-xmldump-mongodb.php on line 73
PHP Warning:  simplexml_load_string():  in /home/username/wiki-project/wikipedia.org-xmldump-mongodb/wikipedia.org-xmldump-mongodb.php on line 73
PHP Warning:  simplexml_load_string(): ^ in /home/username/wiki-project/wikipedia.org-xmldump-mongodb/wikipedia.org-xmldump-mongodb.php on line 73
PHP Warning:  simplexml_load_string(): Entity: line 38: parser error : Premature end of data in tag namespaces line 1 in /home/username/wiki-project/wikipedia.org-xmldump-mongodb/wikipedia.org-xmldump-mongodb.php on line 73
PHP Warning:  simplexml_load_string():  in /home/username/wiki-project/wikipedia.org-xmldump-mongodb/wikipedia.org-xmldump-mongodb.php on line 73
PHP Warning:  simplexml_load_string(): ^ in /home/username/wiki-project/wikipedia.org-xmldump-mongodb/wikipedia.org-xmldump-mongodb.php on line 73
Aborting. Unable to parse namespaces.

I have installed

php, mbstring, simpleXML, mongodb extensions and mongodb 2.69

output of

php -m

is

[PHP Modules]
bcmath
bz2
calendar
Core
ctype
date
dba
dom
ereg
exif
fileinfo
filter
ftp
gettext
hash
iconv
json
libxml
mbstring
mhash
mongo
openssl
pcntl
pcre
PDO
Phar
posix
Reflection
session
shmop
SimpleXML
soap
sockets
SPL
standard
sysvmsg
sysvsem
sysvshm
tokenizer
wddx
xml
xmlreader
xmlwriter
zip
zlib

[Zend Modules]

How can I investigate this error?


Solution

  • You have to escape the > character. In the script file, on line 72 replace this line:

    $chunk = str_replace( [ 'letter">', '</namespace>' ], [ 'letter" name="', '" />' ], $chunk );
    

    With:

    $chunk = str_replace( [ 'letter"\>', '</namespace\>' ], [ 'letter" name="', '" /\>' ], $chunk );
    

    That made it work for me!