Skip to content

Doc with OLEObject leads to "Undefined namespace prefix" #2140

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
maks-rafalko opened this issue Sep 14, 2021 · 0 comments
Open

Doc with OLEObject leads to "Undefined namespace prefix" #2140

maks-rafalko opened this issue Sep 14, 2021 · 0 comments

Comments

@maks-rafalko
Copy link

maks-rafalko commented Sep 14, 2021

Describe the Bug

When the doc has an image as OLEObject, opening such document with phpword leads to warning:

Warning: DOMXPapth::query(): Undefined namespace prefix

It fails here:

return $this->xpath->query($path, $contextNode);

and this function is called from:

$rId = $xmlReader->getAttribute('r:id', $node, 'o:OLEObject');

Steps to Reproduce

<?php
require __DIR__ . '/vendor/autoload.php';

$filePath = __DIR__ . '/broken.docx'`; // see attached document

\PhpOffice\PhpWord\IOFactory::load($filePath, 'Word2007');

broken.docx

Expected Behavior

No errors are thrown.

Current Behavior

Currently, warning produces an exception and script fails during loading the file by phpword.

I tried to analyze what is going on, if this helps, this is an XML (simplified, full is inside attached docx) that is being processed during the failure:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
    <w:body>
        <w:p>
            <w:r>
                <w:object w:dxaOrig="8640" w:dyaOrig="5760">
                    <v:rect id="rectole0000000000" style="width:432.000000pt;height:288.000000pt" o:preferrelative="t"
                            o:ole="" xmlns:o="urn:schemas-microsoft-com:office:office"
                            xmlns:v="urn:schemas-microsoft-com:vml">
                        <o:lock v:ext="edit"/>
                        <v:imagedata r:id="docRId1" o:title=""
                                     xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"/>
                    </v:rect>
                    <o:OLEObject Type="Embed" ProgID="StaticMetafile" DrawAspect="Content" ObjectID="0000000000"
                                 ShapeID="rectole0000000000" r:id="docRId0"
                                 xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"
                                 xmlns:o="urn:schemas-microsoft-com:office:office"/>
                </w:object>
            </w:r>
        </w:p>

    </w:body>
</w:document>

When phpword tries to get o:OLEObject inside w:object tag, it fails with the warning Warning: DOMXPapth::query(): Undefined namespace prefix

Context

@Progi1984 Progi1984 added this to the 1.3.0 milestone Aug 22, 2024
@Progi1984 Progi1984 modified the milestones: 1.3.0, 1.3.1 Sep 1, 2024
@Progi1984 Progi1984 modified the milestones: 1.4.0, 1.5.0 Jun 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants