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


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

SimpleXMLElement::addChild(): unterminated entity reference

Started bysap <sap@nospam.no>
First post2018-12-13 16:59 +0100
Last post2018-12-13 16:59 +0100
Articles 1 — 1 participant

Back to article view | Back to it.comp.www.php


Contents

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

#22425 — SimpleXMLElement::addChild(): unterminated entity reference

Fromsap <sap@nospam.no>
Date2018-12-13 16:59 +0100
SubjectSimpleXMLElement::addChild(): unterminated entity reference
Message-ID<putvkr$2ld$1@gioia.aioe.org>
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?

[toc] | [standalone]


Back to top | Article view | it.comp.www.php


csiph-web