Inspect xml or html special char production on command line

This is part of the Semicolon&Sons Code Diary - consisting of lessons learned on the job. You're in the workflows category.

Last Updated: 2024-04-25

My XML validation test was failing for a component that wrapped every string in CDATA. The code was:

<?php
  $jobNode = $xml->addChild('title', '<![CDATA[actual title]]>');

The confusing part was that it displayed exactly like that in the browser.

I inspected it on the command line with CURL and sure enough the entities had auto-escaping fromthe XML library.

<title>&lt;![CDATA[Standard full-time bookkeeper]]&gt;</title>

I needed to use special tools to skip the auto-escaping for inspection:

<?php
  $node->appendChild($no->createCDATASection($value));

Lesson

When generating output that uses special characters, inspect in a command line program instead of in the browser, since the browser will transform some entities and fool you.