A primary function of this module is to produce XML. This is because Juicebox javascript library deals in XML, so behind the scenes this module's main job is to structure the right XML, based on Drupal image and conflagration data.
A fairly common problem in Drupal is that some poorly-coded modules inadvertently add whitespace to the start of all system page output, often because one of their include files contains whitespace before the <?php part. This is a problem, and it happens a lot, but it often goes unnoticed by people who use these modules because most browsers simply ignore whitespace at the beginning of a document when rendering normal HTML markup. XML is a different story. If a fully-structured XML document (with an <?xml definition, etc.) is returned to the browser with leading whitespace, the browser chokes. It often leads to an XML parsing error such that the XML content itself is not parsed at all.
Because the Juicebox module may be the first thing many users install that "deals" in XML, it may be the first thing that reveals this underlying whitespace issue (usually with a "Config XML file not found" error shown in place of the gallery). When this happens, the perception is that this module is broken, but that is not the case at all. The problem almost certainly related to 3rd party code that this module has no control over.
This has come up in this module's issue queues many times, here, here, here, here and here, among other places.
If you encounter this issue, and you know that it's because there is whitespace at the beginning of the Juicebox XML output, the best course of action is, without a doubt, to determine what's causing the whitespace and correct it. Unfortunately this process could prove tedious, and usually involves enabling/disabling modules one-by-one, for testing, etc. However, if you do this, not only will you have fixed your Juicebox problem, but you will have also saved yourself lots of headaches the next time you want to leverage a Drupal feature that also leverages XML. It's going to sting when you try to setup that views RSS feed (also XML) several months from now and find its broken too.
All that said, one purpose of this thread is to see if there is some workaround that should be implemented in this Juicebox module to bypass this problem. The problem does not lie in this module, but maybe it can be tweaked to still work even with the underlying whitespace issue exists. If a workaround is possible, should it even be implemented (as that will mask an important problem users should maybe be forced to deal with)?
Comments
Comment #1
rjacobs commentedComment #2
rjacobs commentedOk, so a suggestion on how to "workaround" this whitespace issue came up from a non-Drupal source. It was noted in the Juicebox library forum that
juicebox/includes/JuiceboxGallery.inccould be modified in such a way that things still work even if some other module injects whitespace to all Drupal output. The suggestion is to change the end of the renderXml() method on line ~182 from:return $dom->saveXML();to:
return $dom->saveXML($juicebox);Making this change means that the XML response produced by the module is no longer a proper XML document (i.e. it does not contain an
<?xmldeclaration), and so it is not formally validated by the browser as XML. This means that any whitespace is ignored and parsing errors don't come up if whitespace exists. Normally returning an incomplete XML document like this would not be an option, but is seems that the Juicebox javascript library still accepts this as input.Reasons why I don't like this option (and have not yet changed the module to use it):
Reasons why I like this option
If anyone implements this change to their local install, they will have to re-implement it each time the module is updated. Of course some discussion in this thread could also lead to the conclusion that this workaround should be committed directly to the module itself.... I'm not sure what makes the most sense, and currently lean towards leaving things as-is.
Comment #3
tamnv commentedHey Rjacobs,
I try replace from "return $dom->saveXML();" to "return $dom->saveXML($juicebox);" and worked.
Thanks.
Comment #4
System Lord commentedRjacobs, I'm "mark44345" from the JB thread. I completely agree with you. Although this "fix" has corrected my encounters with this issue I do not like the fact that I have files built incorrectly or at least not by standard practice. If you're saying that the issue is only white spaces preceding <?php I would think there could be a script that could be run against all module files to remove them. Mind you it's not something I have the skill to do, but I'm confident someone else does. In my case I could run a "script" to remove them in my current files then, since I'm now aware, I could manually check future updates of module files, and new ones as I as use them.
Comment #5
rjacobs commentedHi Mark, having a scripted way to isolate the issue would certainly be helpful. In fact I seem to recall seeing someone post some instructions on an ad hoc detection method somewhere else (in a different Drupal support thread). I'll see if I can find that.
Comment #6
rjacobs commentedHere's that method to detect what module may be causing the whitespace (from a general Drupal support thread):
https://www.drupal.org/node/175137#comment-1526410
There may also be some other suggestions and clarifications in that same thread.
I'm pretty sure the detection techniques discussed there will not help if it's your theme that's causing the whitespace. Fortunately it's also easy to check that by simply switching themes temporarily.
Comment #7
System Lord commentedI just noticed this in my logs. Just curious if it sounds related?
Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in update_parse_xml() (line 386 of /home/mysite/public_html/modules/update/update.fetch.inc).Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: <b>Warning</b>: Unknown column 'headers' in 'field list' in update_parse_xml() (line 386 of /home/mysite/public_html/modules/update/update.fetch.inc).Comment #8
rjacobs commentedI'm not really sure if that could be related to the whitespace problem on your instance, though I mostly doubt it. I think that error refers to a problem in some parsing logic of XML that's generated by a drupal server (available update data), and not XML that's generated by your site.
If you are able to track down and address your known whitespace issue you could then check if this same error persists to see if they are somehow related. As I said I doubt it, but I'm not personally that familiar with the core update module and what specific XML it sends/receives.
Comment #9
rjacobs commented@tamnv, please note that the main point of this thread is actually to encourage people to locate and fix the root cause of the whitespace (for their Drupal instance) as opposed to using the workaround you referenced in comment #3.
Comment #10
rjacobs commentedTweaked summary a bit for readability. I hope it can be a good ongoing reference.
Comment #11
jdrichmond commentedI ran into this as well. However, I couldn't find the juicebox/includes/JuiceboxGallery.inc file mentioned by rjacobs in #2. However, I did find return $dom->saveXML(); in the juicebox.module file on line 392. I replaced it with return $dom->saveXML($juicebox); and it worked. Just an update for those that are looking for a fix in JuiceboxGallery.inc. I think the module was updated recently and this file removed.
Comment #12
rjacobs commented@jdrichmond, you are probably using version 7.x-1.x of the module as opposed to 7.x-2.x. Anyway, I'd certainly encourage anyone reading this thread to always heed the note in the OP:
You'll be saving yourself trouble in the long-run if you are able to fix the root problem as opposed to hacking this module to work around it. The notes and link in comment #6 may also help.
Comment #13
jdrichmond commented@rjacobs, I did read that note. However, there are 61 modules enabled and I'm not sure how to track down this error other then disabling each module one at a time. If you have any suggestions please let me know. I would like to fix this by addressing the offending module, instead of hacking the Juicebox module.
Also, I checked and I was using version 1.2 of the module. Thought it would be helpful for future users to know where to find the fix in pervious versions of the software.
Comment #14
rjacobs commentedNo worries. It's certainly a tricky problem to troubleshoot. This is one of the reasons I started this thread as I wanted a central place to document the details.
Check out the link in comment #6, as it lists some quick "detection" methods to help track down the culprit file.
Comment #15
justkristin commentedSir, I tried the method you suggest to detect the module which contains the whitespace, but there were no modules listed on the second line - they were all on one line at the top of the page, separated by pipes.
Comment #16
rjacobs commented@justkristin (and others). In addition to the "scripted" module check referenced in comment #6, you should also consider checking your theme files (such as a custom template.php file) for opening/closing whitespace as they can also be the source of the problem.
Comment #17
josecarlosss commentedMy webpage dont sent any mesagges and module show xml not found, i changed in php.ini and .htaccess variable output_buffering to OFF , i havent msgs in apache logs or logs of drupal. Any solution?
Comment #18
rjacobs commented@elrokket, can you confirm if you tried the troubleshooting instructions linked from comment #6 as well as switching themes (for testing purposes)? Those steps should help isolate things. If you can provide a public URL to a page that demonstrates the issues that can also be useful in ensuring that your specific problem is in fact related to extra whitespace.
Comment #19
kamalMaroc commentedI get this error message : Juicebox Error: Config XML file not found.
i change file "juicebox/includes/JuiceboxGallery.inc", line 232;
From : return $prefix . $dom->saveXML() . $suffix;
To : return $dom->saveXML($juicebox);
But i get some error
Any idea ?
Comment #20
rjacobs commented@kamalMaroc, there are multiple reasons you may get an XML error. If you are sure you don't have the whitespace issue described in this thread, then it will be best to open-up a separate support request. Before doing that though you'll want to search the issue queues for that error message to see if there is already another thread that addresses your unique case.
Comment #21
gilles9999 commentedDear rjacobs,
I can confirm that I found:
$dom->saveXML()
in the line 232 of the file JuiceboxGallery.inc
and I replaced with:
$dom->saveXML($juicebox)
and it works!!!
I was becoming crazy!
Many many thanks
Comment #22
rjacobs commented@gilles9999, please see comment #9 and the issue description. I'd discourage you from using that code hack workaround if at all possible.
Comment #23
neslee canil pinto