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.


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...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.