I use the following code to write values to an xml file in php.
if(isset($_POST['title']) && isset($_POST['content'])){
$news = new DOMDocument();
$news->load('../files/news.xml');
$parentNode = $news->getElementById('newsContainer');
$newsNodes = $news->getElementsByTagName('News');
echo $_POST['content'];
if($newsNodes->length > 0){
$newsItem = $news->createElement('News');
$newsItemTitle = $news->createElement('Title');
$newsItemTitle->nodeValue = $_POST['title'];
$newsItemContent = $news->createElement('Content');
$newsItemContent->nodeValue = $_POST['content']; //The value I assign here gets cut out
$newsItem->appendChild($newsItemTitle);
$newsItem->appendChild($newsItemContent);
$news->documentElement->appendChild($newsItem);
$result = $news->save('../files/news.xml');
if($result == FALSE){
echo 'false';
}else{
echo 'true';
}
}else{
$newNewsContentNode = new DOMDocument();
$newsContainer = $newNewsContentNode->createElement('NewsContainer');
$newsItem = $newNewsContentNode->createElement('News');
$newsItemTitle = $newNewsContentNode->createElement('Title');
$newsItemTitle->nodeValue = $_POST['title'];
$newsItemContent = $newNewsContentNode->createElement('Content');
$newsItemContent->nodeValue = $_POST['content']; //The value I assign here gets cut out
$newsItem->appendChild($newsItemTitle);
$newsItem->appendChild($newsItemContent);
$newsContainer->appendChild($newsItem);
$newNewsContentNode->appendChild($newsContainer);
$result = $newNewsContentNode->save('../files/news.xml');
if($result == FALSE){
echo 'false';
}else{
echo 'true';
}
}
}
I save a string with 1065 characters in it but when I check the xml file the node contains only a part of the given string. I looked at the string which comes through the POST and it comes fine. What am I doing wrong here?