/**
  * The main function for converting to an Domdocument.
  * Pass in a BaseObject (from kaltura) and returns that object serialized as a DomDocument
  *
  * @param KalturaUnitTestDataObject $data
  * @param string $rootNodeName - what you want the root node to be - defaultsto data.
  * @return DomDocument XML
  */
 public static function toXml(KalturaUnitTestDataObject $data, $rootNodeName = 'data')
 {
     $xml = new DOMDocument(1.0);
     $rootNode = $xml->createElement($rootNodeName);
     $xml->appendChild($rootNode);
     foreach ($data->additionalData as $key => $value) {
         $rootNode->setAttribute($key, $value);
     }
     //we need to check if this is a propel object
     if (is_object($data->dataObject)) {
         if ($data->dataObject instanceof BaseObject) {
             //Gets the data peer of the object (used to geting all the obejct feilds)
             $dataPeer = $data->dataObject->getPeer();
             //Gets all object fields
             $fields = call_user_func(array($dataPeer, "getFieldNames"), BasePeer::TYPE_PHPNAME);
             //Create the xml elements by all fields and their values
             foreach ($fields as $field) {
                 $value = $data->dataObject->getByName($field);
                 $comment = null;
                 if (isset($data->comments[$field])) {
                     $comment = $data->comments[$field];
                 }
                 KalturaUnitTestDataObject::createFieldElement($xml, $rootNode, $value, $field, null, $comment);
             }
         } else {
             $reflector = new ReflectionClass($data->dataObject);
             $properties = $reflector->getProperties(ReflectionProperty::IS_PUBLIC);
             foreach ($properties as $property) {
                 $value = $property->getValue($data->dataObject);
                 $propertyName = $property->getName();
                 $propertyValueType = gettype($value);
                 KalturaUnitTestDataObject::createFieldElement($xml, $rootNode, $value, $propertyName, $propertyValueType, $data->comments[$propertyName]);
             }
         }
     } else {
         //Value types will be written in the same line as their type
     }
     // pass back DomElement object
     return $xml;
 }