Jump to content

PHP XML large file parser - special character errors XMLReader expand()


sergiu

Recommended Posts

Hi guys, I did read allot of documentation on the internet about reading/writing/parsing an XML file. I ended up using the following code, because I really have large files (some about 200MB) and regular dom does not work:

 

	while ($xml->read()) {
	switch ($xml->nodeType) {
		case (XMLReader::ELEMENT):
		if ($xml->localName == "job") {
			$node = $xml->expand();
			$dom = new DomDocument();
			$n = $dom->importNode($node,true);
			$dom->appendChild($n);
			$job = simplexml_import_dom($n);

 

The problem I have is a special character error in the xml file, error returned on this line: "$node = $xml->expand();"

 

I am literally banging my head to the wall to find a simple solution to this. I already have a cleaning function, but that can be applied only after the code above. As the file is large, to clean it, I would have to use the same code above to work on partial content at once, so I would have the same special character problem when I would try to read and split the file.

 

I bet I am not the first one to be in this situation, but after about 5 hours of searching on the internet, I cannot do it no more. And I am not a php expert to come up with a new idea.

 

One other thing to do probably would be to split the file into multiple files, and read them after that, without using the XMLReader. But this would ask for a different application.

 

If, for example, on a file where I have an error, I do the reading with simplexml, without using the XMLReader, I don't get the error. But I cannot use simplexml on the files, since file size is variable. I have to use a reliable method that works for all situations.

 

Hopefully someone has an idea to this STUPID situation!

 

Thanks.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.