Forum


Replies: 3   Views: 4876
"domdocument::loadxml(): empty string supplied as input" after create document from template
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by david.costa@swyftfilings.com  · 31-07-2018 - 06:39

Hi, I am creating a document from template, but it throws:

"message": "DOMDocument::loadXML(): Empty string supplied as input",
    "exception": "ErrorException",
    "file": "/var/app/current/packages/corp/phpdocx/src/Classes/Phpdocx/Transform/TransformDocAdvHTML.php",
    "line": 877,
    "trace": [
        {
            "function": "handleError",
            "class": "Illuminate\\Foundation\\Bootstrap\\HandleExceptions",
            "type": "->"
        },
        {
            "file": "/var/app/current/packages/corp/phpdocx/src/Classes/Phpdocx/Transform/TransformDocAdvHTML.php",
            "line": 877,
            "function": "loadXML",
            "class": "DOMDocument",
            "type": "->"
        },
        {
            "file": "/var/app/current/packages/corp/phpdocx/src/Classes/Phpdocx/Transform/TransformDocAdvHTML.php",
            "line": 249,
            "function": "getMetaValues",
            "class": "Phpdocx\\Transform\\TransformDocAdvHTML",
            "type": "->"
        },
        {
            "file": "/var/app/current/packages/corp/document/src/Models/Entities/DocumentOrder.php",
            "line": 109,
            "function": "transform",
            "class": "Phpdocx\\Transform\\TransformDocAdvHTML",
            "type": "->"
        },

 

I double checked the files folder and the both docx files (template and document are there)

I ran check.php and everything is ok

PHP_VERSION: 7.0.25
PHP_OS: Linux
PHP_UNAME: Linux ip-172-31-30-207 4.9.76-3.78.amzn1.x86_64 #1 SMP Fri Jan 12 19:51:35 UTC 2018 x86_64
SERVER_NAME: 
SERVER_SOFTWARE: 
SERVER_ADDR: 
SERVER_PROTOCOL: 
HTTP_HOST: 
HTTP_X_FORWARDED_FOR: 
PHP_SELF: check.php
ZipArchive: 1
DomDocument: 1
SimpleXMLElement: 1
Tidy: 1
mbstring: 1
 

Posted by admin  · 31-07-2018 - 08:22

Hello,

That line (877), includes the following lines:

$documentCoreContent = $this->docxStructure->getContent('docProps/core.xml');

$tags = '';

$xmlCoreContent = new \DOMDocument();
$xmlCoreContent->loadXML($documentCoreContent);

It gets the docProps/core.xml file, that is a required file for a DOCX document.  Maybe your DOCX doesn't include that file?

What program did you use to generate the DOCX you are trying to transform?

Please also try to run the included samples in the examples folder.

If your DOCX doesn't include that file (although it should), please edit the TransformDocAdvHTML.php to check if the content exists:

protected function getMetaValues()
{
    $documentCoreContent = $this->docxStructure->getContent('docProps/core.xml');

    $tags = '';

    if ($documentCoreContent) {
        $xmlCoreContent = new \DOMDocument();
        $xmlCoreContent->loadXML($documentCoreContent);
        foreach ($xmlCoreContent->childNodes->item(0)->childNodes as $prop) {
            switch ($prop->tagName) {
                case 'dc:title':
                    $tags .= '<title>' . $prop->nodeValue . '</title>';
                    break;
                case 'dc:creator':
                    $tags .= '<meta name="author" content="' . $prop->nodeValue . '">';
                    break;
                case 'cp:keywords':
                    $tags .= '<meta name="keywords" content="' . $prop->nodeValue . '">';
                    break;
                case 'dc:description':
                    $tags .= '<meta name="description" content="' . $prop->nodeValue . '">';
                    break;
                default:
                    break;
            }
        }
    }

    return $tags;
}

We move your issue to the dev team to test if this check need to be added to the stable package.

Regards.

Posted by david.costa@swyftfilings.com  · 31-07-2018 - 18:32

The DOCX file was generated by createdDocx function, from a DOCX template exported from Google Docx. I tried to use different files from same source, and result is the same.

 

Posted by admin  · 31-07-2018 - 20:08

Hello,

Did you apply the patch? If you applied it the same empty string warning can't keep happening.

Please do the following tests:

· Try to run the included samples of the method in the examples folder.

· Resave one your DOCX template using MS Word and try again.

· Send one of your DOCX to contact[at]phpdocx.com

If Google Docs doesn't include some important files, additional checks could be needed to use the native HTML to DOCX transformation with that files.

Regards.