I need to be able to parse out data fields from Open Office documents on the fly. I'm using tbsooo_class.php and I have a number of files with variable fields embedded. The code I have, derived from TBS (tiny but strong) parses out only the text. I need the entire XML document:

$handle = @fopen("OOFiles/tmp/content.xml", "r");
if ($handle) {
        $fs = @filesize($handle);
        if ($fs==false) {
                while (!feof($handle)) $buffer .= fread($handle,4096);
        } else {
                if ($fs>0) $buffer = fread($handle,$fs);
echo $buffer;

The content.xml file is actually a part of the Open Office document. It is a XML 1.0 document text.
I need to know how to read this file into a string so I can parse out the information I need. That information does not appear in $buffer.


8 Years
Discussion Span
Last Post by scottholmes

My bad. I'm a victim of my own unclear thinking. echo $buffer was doing just what it's supposed to, display the displayable part of an XML file. I was trying that just to see if the entire file was actually in $buffer and it was. What I needed to do was this:

$totlen = strlen($buffer);
for ($i=0; $i<$totlen; $i++) {
        if (substr($buffer,$i, 1)=="[") {
                while (substr($buffer, $i, 1) != "]") {
                        $fldStr = $fldStr.substr($buffer,$i,1);
                $fldStr = $fldStr.substr($buffer,$i,1);
                echo $fldStr."<br>";
                $fldStr = "";

The tbsooo.php class uses merge fields put directly in an Open Office document in the form of [var.someVarName] It then merges the value of a variable of the same name with the Open Office template .

Just though I'd let you know...

This question has already been answered. Start a new discussion instead.
Please be thoughtful and detailed and be sure to adhere to our posting rules.