Welcome Guest, Not a member yet? Register   Sign In
XML and simplexml_load_file
#1

[eluser]bapobap[/eluser]
Hi all,

Quick question, I'm importing an XML file and inserting the data in MySQL. The XML files contains this:

Code:
<Event Status>2</Event Status>

which simple_xml doesn't seem to like, I'm assuming because of the space between Event and Status.

Is there anyway to tell it to ignore this, as I'm not using the keys for anything, just the values.

The specific error message is:

Code:
parser error : Specification mandate value for attribute Status

Warning: simplexml_load_file() [function.simplexml-load-file]: events.xml:98: parser error : expected '>' in /home/import_events.php on line 28

Warning: simplexml_load_file() [function.simplexml-load-file]: <Event Status>3</Event Status> in /home/import_events.php on line 28
#2

[eluser]Negligence[/eluser]
Not sure what this has to do with CI, but XML elements are not to have spaces in their name. Fix your XML and you've fixed your problem.
#3

[eluser]bapobap[/eluser]
Nothing really to do with CI, this has to run via CRON so it's just feeding the MySQL db for the nice interface (which is built with CI).

Unfortunately I can't fix the XML file, it's provided by a company that has absolutely no interest in fixing any formatting problems in the XML file. I just have to work around it myself.
#4

[eluser]bapobap[/eluser]
Also, just to add, I thought about getting the contents of the file into a string, str_replacing these tags to remove the space then saving that as a file but the file is too big (90MB). I can change the settings on the development machine but not on the production server so I can't use that method.
#5

[eluser]Pygon[/eluser]
Yeah, simple xml only works with well formatted XML documents.

I see alot of manual processing in your future.
#6

[eluser]bapobap[/eluser]
Bummer, thanks!
#7

[eluser]nikefido[/eluser]
er..check out php.net/simplexml

It can deal with spaces and dashes and all that with little problem... http://us.php.net/simplexml

See example number 3




Theme © iAndrew 2016 - Forum software by © MyBB