Code:
<entry>
        <id>6</id>
		<title>faqir colony</title>
		<imageUrl>http://i.imgur.com/XWKqac3.jpg</imageUrl>
        <imageThumbUrl>http://i.imgur.com/qNYr4bz.jpg</imageThumbUrl>
        <price>15,000</price>
        <address>Faqir Colony Rd Karachi, Pakistan</address>
        <reviews>no comments.</reviews>
        <latitude>24.923799</latitude>
		<longitude>66.971998</longitude>
        <featured>1</featured>
        <telNo>+923336699887</telNo>
        <checkInTime>Today 3:00 am - 5:00 pm</checkInTime>
        <date>January 22, 2014</date>
        <categoryId></categoryId>
        <zipCode>75760</zipCode>
        <noOfRooms>3</noOfRooms>
        <bathrooms>2</bathrooms>
        <apartmentType>Sale</apartmentType>
        <rating>1</rating>
    </entry>
I have this xml.
I want to add new element.
I am trying this.
Code:
$xml = simplexml_load_file("apartments.xml");
	$maxid = max(array_map('intval',$xml->xpath("//id"))); //this helps to find the last ID entered
	$entry = $xml->entries->addchild('entry');
	$entry->addChild('id',$maxid + 1);
	$entry->addChild('title',$title);
	$entry->addChild('imageUrl',$imageUrl);
	$entry->addChild('imageThumbUrl',$imageThumbUrl);
	$entry->addChild('price',$price);
	$entry->addChild('reviews',$reviews);
	$entry->addChild('latitude',$latitude);
	$entry->addChild('longitude',$longitude);
	$entry->addChild('featured',$featured);
	$entry->addChild('checkInTime',$checkInTime);
	$entry->addChild('categoryId',$categoryId);
	$entry->addChild('zipCode',$zipCode);
	$entry->addChild('noOfRooms',$noOfRooms);
	$entry->addChild('bathrooms',$bathrooms);
	$entry->addChild('apartmentType',$apartmentType);
	$entry->addChild('rating',$rating);
I am getting this error.
Warning: SimpleXMLElement::addChild(): Cannot add child. Parent is not a permanent member of the XML tree in C:\xampp\htdocs\web\added.php on line 59

Fatal error: Call to a member function addChild() on a non-object in C:\xampp\htdocs\web\added.php on line 60