<?php
    include_once 'opendb.php';
    $xml          = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
    $root_element = "Subs"; //fruits
    $xml         .= "<".$root_element.">";
    $filter="";
    $Option="";
    $Qry="SELECT sub_code,latitude,longitude FROM `subsidiary`  ";
    $Qry.= " where  comp_id=".$_GET["comp_id"];
   

    $result = $conn->query($Qry) or die(mysqli_error($conn));
   header("Content-Type: application/xml");
   echo sqlToXml($result, "Subs", "Rows");
   $conn->close(); 
  
function sqlToXml($queryResult, $rootElementName, $childElementName)
{ 
    $xmlData = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>\n"; 
    $xmlData .= "<" . $rootElementName . ">";
     while ($row = mysqli_fetch_assoc($queryResult))
    {
            $xmlData .= "<" . $childElementName . ">";
            foreach( $row as $field => $value) {            
                 $xmlData .= "<{$field}>{$value}</{$field}>";
            }
            $xmlData .= "</" . $childElementName . ">"; 
    }
    $xmlData .= "</" . $rootElementName . ">"; 
    return $xmlData; 
}  
    
?>