Location: PHPKode > scripts > MsSql To XML > mssql-to-xml/sqlToXml.inc.php

class sqlToXml{
	private $query="";
	private $version="";
	private $rootNodeName="root";
	private $xml;
	private $xmlString;
	private $sql;
	public function __construct($myQuery,$version="1.0"){
		$this->sql = new MsSQL();
	public function setRootNodeName($name){
	private function setVersion($myVersion){
	private function setQuery($myQuery){
	public function createXml(){
		$this->xml = new DomDocument($this->version);//object referance for the new document 
		//Adding our root node
		$root = $this->xml->createElement($this->rootNodeName);
		$root = $this->xml->appendChild($root);
		//Querying the db
   		while ($object = mssql_fetch_object($sqlResult)){
   			//Add a node for each row
   			$nodeForEachRow = $this->xml->createElement("row");
  			$nodeForEachRow = $root->appendChild($nodeForEachRow);

   			foreach($object as $key => $fieldvalue) {
				//Add node for each column
   				$child = $this->xml->createElement($key);
    			$child = $nodeForEachRow->appendChild($child);
    			//Add values as a text node (inserting values!)
    			$value = $this->xml->createTextNode($fieldvalue);
    			$value = $child->appendChild($value);
   		$this->xmlString=$this->xml->saveXML();//returns the completed XML document as a string.
   	return $this->xmlString;
	public function __destruct(){
Return current item: MsSql To XML