You are here: Re: >> Very Simple PHP DOM Question..Please help! « PHP Programming Language « IT news, forums, messages
Re: >> Very Simple PHP DOM Question..Please help!

Posted by Azeus on 11/13/48 11:20

Try this:

<?php
$dom = new DOMDocument("1.0","iso-8859-1");

/* Create all elements */
$comment = $dom->createElement("comment"); //root element
$user = $dom->createElement("user", "Carl");
$date = $dom->createElement("date", "1-1-2005");

/* Now place them in the correct place in the tree */

$comment->appendChild($user); // User is a child of Comment
$comment->appendChild($date); // Date is a child of comment
$dom->appendChild($comment); // Comment is a child of rootdoc

echo $dom->saveXML();
?>

It outputs :
<?xml version="1.0" encoding="iso-8859-1"?>
<comment>
<user>Carl</user>
<date>1-1-2005</date>
</comment>


Make sure you append children according to their place in the hierarchy.


gene.ellis@gmail.com wrote:
> Actually I just erased it. But it was basically using these functions:
>
> DOMDocument->createElement()
> DOMNode->appendChild()
>
> My resulting file ends up resembling this:
> <comment><user>john<date>some date</user></date></comment>
>
> So I understand how to do everything except for getting these tags to
> close in the right place. any idea what I could be doing wrong? How
> could I use those two functions to create a node tree that looks like:
> <comment><user>john</user><date>some date</date></comment>
>
> Thanks a lot for your help. I have been racking my brains on this for a
> long time
>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация