Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > it.comp.www.php > #22425

SimpleXMLElement::addChild(): unterminated entity reference

From sap <sap@nospam.no>
Newsgroups it.comp.www.php
Subject SimpleXMLElement::addChild(): unterminated entity reference
Date 2018-12-13 16:59 +0100
Organization Aioe.org NNTP Server
Message-ID <putvkr$2ld$1@gioia.aioe.org> (permalink)

Show all headers | View raw


Ciao a tutti,
sto costruendo un XML.

Inserendo alcuni nodi nel seguente modo:

$xml = new SimpleXMLElement('<urlset/>');
foreach ($val as $link) {
	$url = $xml->addChild('url');
	$url->addChild('loc', $link);
}


mi esce l'errore in oggetto se la variabile $link contiene, ad esempio 
il carattere "&".

Lo script procede ma crea un XML "rotto" di questo tipo:
<url>
     <loc/>
</url>

anzichè

<url>
    <loc>contenuto variabie</loc>
</url>


Non posso HTMLSPECIALCHARS per tutta una serie di motivi (altrimenti 
avrei risolto con htmlspecialchars($link))

Come posso fare per evitare che venga creato un XML "rotto" come sopra?

Back to it.comp.www.php | Previous | Next | Find similar | Unroll thread


Thread

SimpleXMLElement::addChild(): unterminated entity reference sap <sap@nospam.no> - 2018-12-13 16:59 +0100

csiph-web