i have PHP code like this:
public function get_xml_product($serviceName) {
$product = Array();
$idx = $idx2 = 0;
$explodeResult=explode(", ",$serviceName);
foreach($explodeResult as $value)
{
$sql = "SELECT id,parent,code,name,xs1 as DOWNLOAD, xs2 as UPLOAD
FROM sc_params
WHERE rfen = 'SERVICE_REQUESTED'
AND code = '".$value."'
OR code IN
(
SELECT code
FROM sc_params
WHERE rfen = 'SERVICE_REQUESTED'
AND id = (
SELECT parent
FROM sc_params
WHERE rfen = 'SERVICE_REQUESTED'
AND code = '".$value."' )
)
";
$stmt = oci_parse($this->_conn,$sql);
$rs = oci_execute($stmt);
if (!$rs) {
$error = oci_error();
$this->_err = $error;
return false;
}
while ($data = oci_fetch_array($stmt, OCI_BOTH)) {
if($data['PARENT'] == 0) {
$idx++;
$product[$idx]['id'] = $data['ID'];
$product[$idx]['name'] = $data['NAME'];
}
else {
foreach($product as $product2)
{
$product[$idx]['download'][$idx2]['name'] = 'DOWNLOAD';
$product[$idx]['download'][$idx2]['value'] = $data['DOWNLOAD'];
$product[$idx]['upload'][$idx2]['name'] = 'UPLOAD';
$product[$idx]['upload'][$idx2]['value'] = $data['UPLOAD'];
$idx2++;
}
}
}
}
print_r($product);
......
the result show:
Array
(
[1] => Array
(
[id] => 1
[name] => INTERNET
[download] => Array
(
[0] => Array
(
[name] => DOWNLOAD
[value] => 1024
)
)
[upload] => Array
(
[0] => Array
(
[name] => UPLOAD
[value] => 256
)
)
)
and i want to make it into xml like this one:
<xml version="1.0"?>
<services>
<service>
<id>1</id>
<name>INTERNET</name>
<attribute>
<name>DOWNLOAD</name>
<value>1024</value>
</attribute>
<attribute>
<name>UPLOAD</name>
<value>512</value>
</attribute>
</service>
</services>
UPDATED: my php file has condition for xml format... i tried:
$xml = new SimpleXMLElement("<services/>");
foreach($product as $key => $value) {
if (is_array($value)) {
$subnode = $xml->addChild("service");
$this->array_to_xml($value, $subnode);
}
else
{
$xml->addChild(htmlspecialchars("$key"),htmlspecialchars("$value"));
}
}
$string = $xml->asXML();
$result = htmlentities($string);
and it call array_to_xml, here it is:
public function array_to_xml($product, &$xml) {
foreach($product as $key => $value) {
if (is_array($value)) {
$subnode = $xml->addChild("service");
array_to_xml($value, $subnode);
} else {
$xml->addChild(htmlspecialchars("$key"),htmlspecialchars("$value"));
}
}
return $xml;
}
it gave error 500 Internal Server Error
, but if i remove condition in php it run.
Please Help me....