How to create sub nodes in xml with the help of php
Posted: Sat Feb 07, 2009 8:07 am
<?php
$dom = new DomDocument();
$dom->load("listings.xml");
$agents = $dom->documentElement;
$id=$_REQUEST['listid'];
$listheading=$_REQUEST['listheading'];
$postcode=$_REQUEST['postcode'];
$suburb=$_REQUEST['suburb'];
$city=$_REQUEST['city'];
$state=$_REQUEST['state'];
$propertytype=$_REQUEST['propertytype'];
$agents = $dom->documentElement;
$newagent = $agents->appendChild(new domElement('list'));
$newagent->appendChild(new domElement('listid', $id));
$newagent->appendChild(new domElement('listheading', $listheading));
$newagent->appendChild(new domElement('postcode', $postcode));
$newagent->appendChild(new domElement('suburb', $suburb));
$newagent->appendChild(new domElement('city', $city));
$newagent->appendChild(new domElement('state', $state));
$newagent->appendChild(new domElement('propertytype', $propertytype));
$res= $dom->saveXML();
$default_dir="";
$default_dir .= "listings.xml";
$fp = fopen($default_dir,'w');
$write = fwrite($fp,$res);
$result="ok";
if($result=="ok")
{
?>
<script>
location.href="view.php";
</script>
<?php
}
?>
with the help of this file i can create
xml like following xml file
listings.xml
========
<?xml version="1.0"?>
<listings>
<list>
<listid>list001</listid>
<listheading>rajesh</listheading>
<postcode>500505</postcode>
<suburb>muncipal </suburb>
<city>tanuku</city>
<state>lasgdf</state>
<propertytype>asgdf</propertytype>
</list>
but i cant create sub nodes for <suburd> nod...
i want sub nodes in <suburb>...like following
<suburb>
<suburb1>xyz</suburb1>
<suburb2>xyz</suburb2>
</suburb>
totally i want following format
<?xml version="1.0"?>
<listings>
<list>
<listid>list001</listid>
<listheading>rajesh</listheading>
<postcode>500505</postcode>
<suburb>
<suburb1>xyz</suburb1>
<suburb2>xyz</suburb2>
</suburb>
<city>tanuku</city>
<state>lasgdf</state>
<propertytype>asgdf</propertytype>
</list>
anybody help me...
im in very bad situation for this problem.....
please...
$dom = new DomDocument();
$dom->load("listings.xml");
$agents = $dom->documentElement;
$id=$_REQUEST['listid'];
$listheading=$_REQUEST['listheading'];
$postcode=$_REQUEST['postcode'];
$suburb=$_REQUEST['suburb'];
$city=$_REQUEST['city'];
$state=$_REQUEST['state'];
$propertytype=$_REQUEST['propertytype'];
$agents = $dom->documentElement;
$newagent = $agents->appendChild(new domElement('list'));
$newagent->appendChild(new domElement('listid', $id));
$newagent->appendChild(new domElement('listheading', $listheading));
$newagent->appendChild(new domElement('postcode', $postcode));
$newagent->appendChild(new domElement('suburb', $suburb));
$newagent->appendChild(new domElement('city', $city));
$newagent->appendChild(new domElement('state', $state));
$newagent->appendChild(new domElement('propertytype', $propertytype));
$res= $dom->saveXML();
$default_dir="";
$default_dir .= "listings.xml";
$fp = fopen($default_dir,'w');
$write = fwrite($fp,$res);
$result="ok";
if($result=="ok")
{
?>
<script>
location.href="view.php";
</script>
<?php
}
?>
with the help of this file i can create
xml like following xml file
listings.xml
========
<?xml version="1.0"?>
<listings>
<list>
<listid>list001</listid>
<listheading>rajesh</listheading>
<postcode>500505</postcode>
<suburb>muncipal </suburb>
<city>tanuku</city>
<state>lasgdf</state>
<propertytype>asgdf</propertytype>
</list>
but i cant create sub nodes for <suburd> nod...
i want sub nodes in <suburb>...like following
<suburb>
<suburb1>xyz</suburb1>
<suburb2>xyz</suburb2>
</suburb>
totally i want following format
<?xml version="1.0"?>
<listings>
<list>
<listid>list001</listid>
<listheading>rajesh</listheading>
<postcode>500505</postcode>
<suburb>
<suburb1>xyz</suburb1>
<suburb2>xyz</suburb2>
</suburb>
<city>tanuku</city>
<state>lasgdf</state>
<propertytype>asgdf</propertytype>
</list>
anybody help me...
im in very bad situation for this problem.....
please...