Tags:
php
Hej... har ikke fået svar endnu på dette, så spørger igen. Det er på engelsk, for har skrevet i andre fora også.
hey everyone
I'm making a file, that can write news text into an xml-file. All my text for my page is in the xml-file, and the structure kind of looks like this:
<site>
<news>
</news>
<pictures>
</pictures>
<biography>
</biography>
</site>
I have a piece of code (using the dom-functions) and I can easily create new tags within the root-tag. The problem is, that I want to put it inside the news-tag, so I can organize it. I've tried looking around in php.net/dom, but can't really fiure it out. Should be easy anyway. Here is my code:
$file_name="text.xml";
$dom = new DomDocument();
$dom->load($file_name);
$item = $dom->createElement("item");
$overskrift = $dom->createElement("overskrift", "I am a headline");
$tekst = $dom->createElement("tekst", "I am a text");
$linebreak = $dom->createTextNode(chr(10));
$item->appendChild($overskrift);
$item->appendChild($tekst);
$item->appendChild($linebreak);
$dom->documentElement->appendChild($item);
$dom->save($file_name);
What I want to do is sort of like $dom->documentElement->news->append....
But that doesn't work. Can you help me?
- Rune