YAWIK
YAWIK copied to clipboard
Export is broken or contains empty fields (addChild does not escape & to &)
Currently the Exportview uses the addChild method and this breaks, if the text contains an ampersand &
e.g. in the title https://github.com/cross-solution/YAWIK/blob/develop/module/Jobs/view/jobs/export/feed.xml.phtml#L70
here the title is empty
<job id="5b3fc10b0acec3e060f8f502">
<title/>
expected value <title>Manager Sales & Customer Relations</title>
What works is
$job->addChild('title');
$job->title = $jobObject->getTitle();
yes, you're right. It makes a difference.
cbleek@xenon:~$ php -a
Interactive mode enabled
php > $xml = simplexml_load_string('<jobopening/>');
php > $xml->addChild('title','a & b');
PHP Warning: SimpleXMLElement::addChild(): unterminated entity reference b in php shell code on line 1
PHP Stack trace:
PHP 1. {main}() php shell code:0
PHP 2. {main}() php shell code:0
PHP 3. SimpleXMLElement->addChild() php shell code:1
php > $xml->title='a & b';
php > $xml->saveXml();
php > echo $xml;
php > echo $xml->saveXml();
<?xml version="1.0"?>
<jobopening><title>a & b</title></jobopening>
@TiSiE interessant. Scheint ein gewünschtes Feature zu sein. Wusstest du das?
https://stackoverflow.com/questions/552957/rationale-behind-simplexmlelements-handling-of-text-values-in-addchild-and-adda
Quick fix
replace all addChild('node', 'content')
calls with $job->node = 'content'
Pragmatic fix
Extend SimpleXmlElement and make the addChild
method behave like we want.
class MySimpleXmlElement extends \SimpleXmlElement
{
public function addChild($node, $content = null, $escape = true)
{
if ($escape) {
$this->$node = $content;
return $this->$node;
}
return parent::addChild($node, $content);
}
}
DRY and SOLID fix
Encapsulate the XML generation in a dedicated class. Maybe a job decorator similar to Jobs\Entity\Decorator\JsonLdProvider. Or a filter to convert a job entity into a XML representation.
+1 DRY and SOLID fix
@sergey-galenko That's one for you, I suppose :)
let's wait for @mbo-s opinion. They are the only ones currently using XML export.
@gastro24 I use the mentioned Quick Fix, so I do not need any change
Then we should set this onhold.