• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
XML issue

#1
[eluser]pmonty[/eluser]
I am generating a specific xml stream with a helper function I wrote to feed an html page. The xml being returned by CI includes some whitespace at the beginning of the stream which is fouling up the use of the xml stream by my javascript grid object. If I write the string to a file and load the xml file, it works fine, but when I try to load from the stream, it coughs and gives me an error. Email support from the grid code provider (dxhtmlgrid) told me to be sure there is no whitespace before the <?xml header in the stream. The generated file does not have it and loads fine but when I call the makexml script directly, I can see the whitespace at the top of the stream. It seems to me that somewhere in the CI output stream this is being generated and I can't seem to get rid of it. Any ideas?

I have even tried echoing a trimmed string but the white spaces are still there. Here is what I have tried.

Code:
// make the xmlstring from the query results using our home grown xmlmaker
   $lcxmlstr = ltrim(xmlmakefile($query2->result_array(),$fldlist));
// write the string to a file to see if has spaces before the <?xml characters
   $fh = fopen("testxml2.xml","wt");
   fwrite($fh,$lcxmlstr);
   fclose($fh); // results in no whitespace at the top of the file
// echo the string to a stream with everything before the <?xml markup cut off    
   echo strstr($lcxmlstr,"<?xml"); //results in stream still includes whitespace

Paul

#2
[eluser]kgill[/eluser]
Just a quick thought, have you checked the files themselves for whitespace? It seems to me that if you're trimming the string then echoing it and you still see the problem, then the problem isn't the string.

e.g.

Code:
--- start of file ---

<?php // that blank line above will be part of your output
// code here
?>
--- end of file ---

- K

#3
[eluser]pmonty[/eluser]
K,

Yup, did that. No whitespace in my php files themselves, unless there is some in some of the CI files. I'll check those too.

Paul

Checked all those that I can see are involved and cannot find any whitespace there. Still a mystery.

#4
[eluser]OwanH[/eluser]
[quote author="pmonty" date="1183833418"]Yup, did that. No whitespace in my php files themselves, unless there is some in some of the CI files.[/quote]

None of the CI source files have any whitespace before the opening <?php tag nor after the closing ?> tag (yes I actually looked through all the CI source files, had some time on my hands that day Smile), so that couldn't be the reason unless you edited any of the files.

Here's a question, what kind of whitespace is being output in the stream. Is it space, newline, tab, what exactly? I suspect that your xmlmakefile function is generating the whitespace before the <?xml tag as a newline or tab.

#5
[eluser]pmonty[/eluser]
Owan,

I did the same thing. I looked through all the CI files to be certain there wasn't any whitespace before the PHP opening tag. I concur that none could be found. That led me to my own files and one by one I went through them and found no whitespace before the PHP tag but still I got the error.

I finally solved this one, and I don't know what the problem actually was, but I shut down my text editor (SciTE) not just the files that were opened in it and reloaded the editor and the file that was being called in my html script. That worked. Something in memory was dirty or corrupted or....I don't know. But somehow in a manner that was not visible on the screen in the editor, there was whitespace (Big shrug of shoulders here...big pile of hair on the desk...bunch of lost time in the slop bucket and note to self to try this earlier in the process next time).

Thanks for your suggestions and your search of the CI files. At least it is good to know that there is nothing in the framework that would create that issue.

Paul

#6
[eluser]OwanH[/eluser]
Glad to know you got it solved Paul, sorry to hear about the loss of time and hair though. Hope you lose less of both next time Smile.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.