I am selecting the data from the oracle database into an array and I want this array to be converted into XML.
For example, I am getting the user data from users table "select userName, userPassword from users", the result will be stored in the $results array. I want this array to be converted as follows
<users
<record username="xyz" userPassword="abc123"/>
<record username="abc" userPassword="ytr123"/>
<record username="mno" userPassword="mno123"/>
/>
I tried with following code, I am not getting as above
Code: Select all
$doc = new DomDocument("1.0");
$root = $doc->createElement("user");
$root = $doc->appendChild($root);
foreach($results as $key => $value){
$body = $doc->createElement("record");
$body = $root->appendChild($body);
if (!is_array($value)) {
$body->setAttribute($key, $value);
}
else {
foreach($value as $data1){
$body->setAttribute($key, $data1);
}
}
}
print $doc->saveXML();Thanks in advance
Regards
Raja
Burrito: Please use
Code: Select all
tags when [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting PHP Code In The Forums[/url][/size]