The HTML document which I am parsing contains some ASCII control codes. I noticed that PHP’s DOMDocument parser truncates text nodes when it finds ASCII control characters within the node, such as
Device Control 0x13
End of Medium 0x19
File Separator 0x1C
Group Separator 0x1D
Is this a bug or a feature? Is there any way to have DOMDocument act otherwise? I resorted to remove this characters before DOM processing, but I wonder if that’s the right solution.
Probably both a bug and a feature.
XML 1.0 is very restrictive about the ASCII control characters that it will accept. So it seems like your DOMDocument is trying to protect you from yourself by truncating (although it should return some indication of a problem, so I’d call that a bug).
XML 1.1 is less restrictive; the only thing that it doesn’t allow is NUL. So, one possible solution is to configure your DOMDocument object so that it knows it should be managing 1.1.
Edit: it looks like you can pass the XML version number to the DOMDocument constructor (but I’m not a PHP programmer, so don’t know if I’m reading the docs correctly).
Edit 2: I just reread your question, and realized that your parsing, not constructing. If you prepend a valid 1.1 prologue to the input, that should be a workaround. Or perhaps by constructing the DOMDocument with the correct version number, it will parse correctly without that prologue.