[prev in list] [next in list] [prev in thread] [next in thread] 

List:       centos
Subject:    [CentOS] php DOMDocument and entities
From:       Alice Wonder <alice () domblogger ! net>
Date:       2015-09-24 20:21:08
Message-ID: 56045B34.9040005 () domblogger ! net
[Download RAW message or body]

This is not CentOS specific but I hope someone here knows so I do not 
have to subscribe to another list.

I'm using php DOMDocument to create an XSL that needs a non-breaking 
space between two values.

Basically:

$xslvalueof = $dom->createElement('xsl:value-of');
     $xslvalueof->setAttribute('select', '../@month');
     $caption->appendChild($xslvalueof);
$nbsp = $dom->createTextNode('&#160;');
     $caption->appendChild($nbsp);
$xslvalueof = $dom->createElement('xsl:value-of');
     $xslvalueof->setAttribute('select', '../@year');
     $caption->appendChild($xslvalueof);

That's what I am trying to do.

createTextNode() however tries to protect the users, and automatically 
turns any & into &amp;

So I tried

$nbsp = $dom->createEntityReference('#160');

That however gives a dom error, it seems createEntityReference only 
works with named entities.

$nbsp = $dom->createEntityReference('nbsp');

works, but then I would have to modify the DTD for both XSL and the 
target XML because neither have nbsp defined.

How can I create the literal string '&#160;' using DOMDocument as a text 
node between two other nodes?

This is driving me nuts.

I could I suppose put it inside a span

&nbsp = $dom->createElement('span', '&#160;');

That works but is hackish. It seems to work though by generating the 
actual UTF8 character itself.

I really wish the XML spec itself had named entities for the various 
whitespace characters that tend to get eaten by XML parsers if not done 
as a numbered entity. Ah well.

Using &#160; works just fine when the XSL is a text file. It is 
dynamically creating it via DOMDocument where I have a problem.

Thanks for any suggestions.

-- 
-=-
Sent my from my laptop, may not be able to respond timely
_______________________________________________
CentOS mailing list
CentOS@centos.org
https://lists.centos.org/mailman/listinfo/centos
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic