I am using simple PHP script which creates XML.
XML looks like:
<?xml version="1.0" encoding="UTF-8"?>
<article id="1"><published>05/01/2015 04:32:36</published><author position="writer">John Stewart</author>
Nothing special right? Yea and after that i write another PHP script which try to add second article to XML.
The code looks like:
$dom=new DOMDocument();
$dom->load("articles.xml");
$article=$dom->createElement("article");
$article->setAttribute("id", 2);
$published=$dom->CreateElement("published");
$publishedDate=$dom->createTextNode(date("d/m/Y h:i:s", strtotime("tomorrow")));
$published->appendChild($publishedDate);
$article->appendChild($published);
$author=$dom->createElement("author");
$author->setAttribute("position", "writer");
$authorName=$dom->createTextNode("Ivan Dimov");
$author->appendChild($authorName);
$article->appendChild($author);
$dom->documentElement->appendChild($article);
$dom->save("articles.xml");
I'm probably blind because this code looks good for me, but generate XML looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<article id="1"><published>05/01/2015 04:32:36</published><author position="writer">John Stewart</author>
<article id="2"><published>06/01/2015 12:00:00</published><author position="writer">Ivan Dimov</author></article></article>
So in general, it adds new <article> before it end old one , and now XML have twice end article tag at the end.
Can someone help me to find the correct way how to do that? If you find a bit time to explain me what was wrong it would be awesome.
Thank you all for reading
articleandarticleStags at the end. The second one has a trailings.