Reputation: 31
Well here is the deal, i'm recovering data from my web page database and creating an xml with the only purpose of importing that data to my local database. i do this because the data in my local DB is pretty specific and i don't want to fill it with useless information, so what i do is this:
<?php
ini_set( 'default_charset', 'UTF-8' );
$ID = $_GET['ID'];
$personInfo = GetPersonSoftwareByID($ID); //this is a function that i created on my own
//xml section
$domTree = new DOMDocument('1.0', 'UTF-8');
$rootXML = $domTree->createElement( 'XML' );
$rootXML = $domTree->appendChild($rootXML);
$personalSoftware = $domTree->createElement( 'PERSON_SOFTWARE' );
$personalSoftware = $rootXML->appendChild($personalSoftware);
$soft = $domTree->createElement('SOFTWARE');
$level = $domTree->createElement('LEVEL');
$soft->nodeValue = $softwares[software];// here the value is = 'Plant&ID'
$level->nodeValue = $softwares[level];
$soft = $personalSoftware ->appendChild($soft);
$level = $personalSoftware ->appendChild($level);
header('Content-type: text/xml; charset=UTF-8');
header('Content-Disposition: attachment; filename="test.xml");
echo $domTree->saveXML();
?>
but when i try to create the xml this comes out: Warning: main() [function.main]: unterminated entity reference ID in line xx
i've tried with htmlentities and the xml is created but when i try to import with simplexml_load_string i get a whole bunch of alerts but not with & rather with other characters such as à and ³
is there a way to fix or saving in the xml as is in the DB? by the way the data stored in the web page DB and local DB are information in spanish
THANKS IN ADVANCE!
Upvotes: 2
Views: 1641
Reputation: 19512
This is a bug in PHP that affects DOMNode::$nodeValue
, DOMDocument::createElement()
and afaik even SimpleXML.
You can easily avoid it by creating a text node and appending it.
$dom = new \DOMDocument();
$dom
->appendChild($dom->createElement('company'))
->appendChild($dom->createTextNode('A & B & C'));
echo $dom->saveXml();
You can still set $nodeValue
to an empty string to delete the contents of a node, but I would not use it to set text values.
Upvotes: 5