Phpword: XML Parsing error; Location: Part: /word/document.xml, Line:4, Column:2888

Created on 28 Oct 2016  Â·  11Comments  Â·  Source: PHPOffice/PHPWord

Hi everyone!

I am using this package to generate Word result documents from my Laravel application. But I keep getting a XML parsing error. For one page, where I want to generate 5 tables, all with three rows a document is generated, but when I open it, the error: XML Parsing error occurs; Location: Part: /word/document.xml, Line:4, Column:2888. For another page, it works but when I have more than 7 rows a document is generated, but when I open it, the error XML Parson error location /word/document.xml, Line:2, Column:14349 occurs.

Does someone know whether this is a problem on my part or words?

Most helpful comment

At the beginning of your script, you need to call the following so HTML entities get escaped

Settings::setOutputEscapingEnabled(true);

All 11 comments

Hi,
It comes from your data : you have a XML special character in it and when Word, parses your doc, it doesn't understand.
I solved this problem by using htmlspecialchars(). I'm not sure it is the best way but it works

How would you implement this in your code?

Hi,

The problem is that the xml generated by phpword is "corrupt" due to xml
characters inside user data.

Therefore by using htmlspecialchars(), it protects against xml characters
user data injection. The solution I found was to use htmlspecialchars()
before using phpword.

I hope it will help you.

ScoobyPorthos

Le 23 nov. 2016 08:31, "Anna Jeanine" [email protected] a écrit :

How would you implement this in your code?

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/PHPOffice/PHPWord/issues/923#issuecomment-262448903,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AGhBvYUU6Zp1Zu_cs86Rj_-CH-6UEXa5ks5rA-vKgaJpZM4KjNDg
.

Hi, thank you for this explaination but I meant more do you have an example code? I have tried

htmlspecialchars();
$phpWord = new \PhpOffice\PhpWord\PhpWord();

Which doesn't work and

$phpWord = new \PhpOffice\PhpWord\PhpWord();
$phpWord->htmlspecialchars();

Do you have an example for right syntaxing?

Hi,

Try this :
$section->addText(htmlspecialchars($yourData));

Le 24/11/2016 à 10:14, Anna Jeanine a écrit :
>

Hi, thank you for this explaination but I meant more do you have an
example code? I have tried

|htmlspecialchars(); $phpWord = new \PhpOffice\PhpWord\PhpWord(); |

Which doesn't work and

|$phpWord = new \PhpOffice\PhpWord\PhpWord();
$phpWord->htmlspecialchars(); |

Do you have an example for right syntaxing?

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/PHPOffice/PHPWord/issues/923#issuecomment-262726170,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AGhBvUyP9ouNUFbhgaltB59EamJc7ZMmks5rBVVfgaJpZM4KjNDg.

--

  *Samy Bertrand*

Doesn't work because my data is an object and not a string..

2016-11-25 0:03 GMT+01:00 Scooby Porthos notifications@github.com:

Hi,

Try this :
$section->addText(htmlspecialchars($yourData));

Le 24/11/2016 à 10:14, Anna Jeanine a écrit :
>

Hi, thank you for this explaination but I meant more do you have an
example code? I have tried

|htmlspecialchars(); $phpWord = new \PhpOffice\PhpWord\PhpWord(); |

Which doesn't work and

|$phpWord = new \PhpOffice\PhpWord\PhpWord();
$phpWord->htmlspecialchars(); |

Do you have an example for right syntaxing?

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/PHPOffice/PHPWord/issues/923#issuecomment-262726170,

or mute the thread
AGhBvUyP9ouNUFbhgaltB59EamJc7ZMmks5rBVVfgaJpZM4KjNDg>.

--

Samy Bertrand

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/PHPOffice/PHPWord/issues/923#issuecomment-262854083,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AQc9wSZChj6yGlykfDUO9QutKpQB2nO_ks5rBhe4gaJpZM4KjNDg
.

Hi,

Can you send me your code, so i could be able to help you more
effectively.

Le 25 nov. 2016 09:15, "Anna Jeanine" notifications@github.com a écrit :
>

Doesn't work because my data is an object and not a string..

2016-11-25 0:03 GMT+01:00 Scooby Porthos notifications@github.com:

Hi,

Try this :
$section->addText(htmlspecialchars($yourData));

Le 24/11/2016 à 10:14, Anna Jeanine a écrit :
>

Hi, thank you for this explaination but I meant more do you have an
example code? I have tried

|htmlspecialchars(); $phpWord = new \PhpOffice\PhpWord\PhpWord(); |

Which doesn't work and

|$phpWord = new \PhpOffice\PhpWord\PhpWord();
$phpWord->htmlspecialchars(); |

Do you have an example for right syntaxing?

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<
https://github.com/PHPOffice/PHPWord/issues/923#issuecomment-262726170>,

or mute the thread
AGhBvUyP9ouNUFbhgaltB59EamJc7ZMmks5rBVVfgaJpZM4KjNDg>.

--

Samy Bertrand

—
You are receiving this because you authored the thread.

Reply to this email directly, view it on GitHub
<https://github.com/PHPOffice/PHPWord/issues/923#issuecomment-262854083
,
or mute the thread
<
https://github.com/notifications/unsubscribe-auth/AQc9wSZChj6yGlykfDUO9QutKpQB2nO_ks5rBhe4gaJpZM4KjNDg

.

>

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.

At the beginning of your script, you need to call the following so HTML entities get escaped

Settings::setOutputEscapingEnabled(true);

Hi troosan,
I am facing same error "Document cannot open because problems with the content"
Location: Part: /word/document.xml line 2 column 2694.

I added Settings::setOutputEscapingEnabled(true); but stills same error.

Please help me

Hi troosan,
I am facing same error "Document cannot open because problems with the content"
Location: Part: /word/document.xml line 2 column 2694.

I added Settings::setOutputEscapingEnabled(true); but stills same error.

Please help me.
error

Hi troosan,
I am facing same error "Document cannot open because problems with the content"
Location: Part: /word/document.xml line 2 column 2694.

I added Settings::setOutputEscapingEnabled(true); but stills same error.

Please help me.
error

Try this :
htmlentities($cellValue, ENT_QUOTES, 'UTF-8');

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cyrillkalita picture cyrillkalita  Â·  6Comments

taophp picture taophp  Â·  3Comments

btry picture btry  Â·  4Comments

phuwin picture phuwin  Â·  3Comments

totpero picture totpero  Â·  6Comments