Ejemplo n.º 1
0
 function formatError($ex)
 {
     $xml = new XMLBuilder();
     $xml->element("result");
     $xml->forward();
     $xml->element("error", $ex->getMessage());
     $xml->attribute("type", $ex->getException());
     $xml->back();
     $xml->back();
     echo $xml->getXML();
 }
Ejemplo n.º 2
0
 public function testBasic()
 {
     $rb = new XMLBuilder(false);
     $rb->element("GeteBayOfficialTimeRequest")->attribute("xmlns", "urn:ebay:apis:eBLBaseComponents");
     $rb->forward();
     $rb->element("RequesterCredentials");
     $rb->forward();
     $rb->element("eBayAuthToken", "QWERTYUIOP");
     $requestXmlBody = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
     $requestXmlBody .= "<GeteBayOfficialTimeRequest xmlns=\"urn:ebay:apis:eBLBaseComponents\">";
     $requestXmlBody .= "<RequesterCredentials><eBayAuthToken>QWERTYUIOP</eBayAuthToken></RequesterCredentials>";
     $requestXmlBody .= "</GeteBayOfficialTimeRequest>\n";
     $this->assertEqual($rb->getXML(), $requestXmlBody, "L'xml generato non corrisponde! : " . $rb->getXML());
     //echo htmlentities($rb->getXML());
     //echo htmlentities($requestXmlBody);
 }
 public function export_data($table)
 {
     if (!$table) {
         throw new InvalidParameterException("Il nome della tabella è nullo!");
     }
     $table_desc = new __MysqlTableFieldsDescription($table);
     $all_fields = $table_desc->getAllFields();
     $ss = new __MysqlSelect($table);
     $all_rows = $ss->exec_fetch_assoc_all();
     $xml_builder = new XMLBuilder();
     $xml_builder->element("table");
     $xml_builder->attribute("name", $table);
     $xml_builder->forward();
     foreach ($all_rows as $row) {
         $xml_builder->element("row");
         $xml_builder->forward();
         foreach ($all_fields as $k => $v) {
             $xml_builder->element("field", $row[$k], true);
             $xml_builder->attribute("name", $k);
         }
         $xml_builder->back();
     }
     return $xml_builder->getXML();
 }
Ejemplo n.º 4
0
          </td>
          <td nowrap>
            &nbsp;
          </td>
        </tr>
      </table>
      
      <?php 
// Check whether a file and a expression was given.
if (!empty($file) && !empty($expression)) {
    // Display a separator.
    echo "<br><hr><br>";
    // Include the <phpXML/> class.
    include "XMLBuilder.class.php";
    // Now create a new object for accessing the XML file.
    $xml = new XMLBuilder($file);
    // Evaluate the XPath expression.
    $results = $xml->evaluate($expression, $context);
    // Now check what action to perform.
    if ($action == "remove") {
        // Run through all nodes that were found.
        foreach ($results as $result) {
            // Remove the node.
            $xml->remove_node($result);
        }
        // Clear the results.
        $results = array();
    }
    // Now display the content of the XML file.
    echo "<pre>";
    echo $xml->get_file($results);
Ejemplo n.º 5
0
 /**
  * To create changeset body for an entity in ATOMPub format.
  *
  * @param ResourceBox $resourceBox
  * @param boolean $newline
  * @return string
  * @throws InvalidOperation, InternalError
  */
 protected function CreateChangeSetBodyForResource($resourceBox, $newline)
 {
     $syndicationUpdated = false;
     if (EntityStates::Deleted == $resourceBox->State) {
         return null;
     }
     if (EntityStates::Added != $resourceBox->State && EntityStates::Modified != $resourceBox->State) {
         throw new InternalError(Resource::UnexpectdEntityState);
     }
     $changesetBodyForResource = null;
     Utility::WriteLine($changesetBodyForResource, "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>");
     Utility::WriteLine($changesetBodyForResource, "<entry xmlns:d=\"http://schemas.microsoft.com/ado/2007/08/dataservices\" xmlns:m=\"http://schemas.microsoft.com/ado/2007/08/dataservices/metadata\" xmlns=\"http://www.w3.org/2005/Atom\">");
     $object = $resourceBox->getResource();
     $entityName = get_class($object);
     $type = ClientType::Create($entityName);
     $nullCFProperties = array();
     $CF_SyndicationXML = null;
     $CF_NonSyndicationXML = null;
     $this->HandleNCharProperties($type, $object);
     //Check this Client Type has Syndication or Custom Property mapping, if so
     //build the syndication XML/Custom XML.
     if ($type->hasEPM()) {
         $epmProperties = $type->getRawSortedEPMProperties();
         $FC_Synd_dom = new DOMDocument();
         $FC_NonSynd_dom = new DOMDocument();
         foreach ($epmProperties as $epmProperty) {
             $synd = false;
             if ($epmProperty->hasEPM($synd)) {
                 $propertyName = $epmProperty->getName();
                 $attributes = $epmProperty->getAttributes();
                 $refProperty = new ReflectionProperty($object, $propertyName);
                 $propertyValue = $refProperty->getValue($object);
                 if ($synd) {
                     if ($attributes['FC_TargetPath'] == 'SyndicationUpdated') {
                         $syndicationUpdated = true;
                         $propertyValue = Utility::TimeInISO8601();
                     }
                     if (is_null($propertyValue)) {
                         $nullCFProperties[] = $propertyName;
                     }
                     $path = SyndicationItemProperty::GetSyndicationItemPathNoNS($attributes['FC_TargetPath']);
                     XMLBuilder::BuildDOMFromPath($FC_Synd_dom, $path, $propertyValue, '', '', false);
                 } else {
                     if (is_null($propertyValue)) {
                         $nullCFProperties[] = $propertyName;
                     }
                     XMLBuilder::BuildDOMFromPath($FC_NonSynd_dom, $attributes['FC_TargetPath'], $propertyValue, $attributes['FC_NsPrefix'], $attributes['FC_NsUri'], true);
                 }
             }
         }
         $CF_SyndicationXML = trim(str_replace('<?xml version="1.0"?>', '', $FC_Synd_dom->SaveXML()));
         $CF_NonSyndicationXML = trim(str_replace('<?xml version="1.0"?>', '', $FC_NonSynd_dom->SaveXML()));
     }
     if (!empty($CF_SyndicationXML)) {
         Utility::WriteLine($changesetBodyForResource, $CF_SyndicationXML);
         if (!$syndicationUpdated) {
             Utility::WriteLine($changesetBodyForResource, '<updated>' . Utility::TimeInISO8601() . '</updated>');
         }
     } else {
         Utility::WriteLine($changesetBodyForResource, '<title />');
         Utility::WriteLine($changesetBodyForResource, '<author>');
         Utility::WriteLine($changesetBodyForResource, '<name />');
         Utility::WriteLine($changesetBodyForResource, '</author>');
         Utility::WriteLine($changesetBodyForResource, '<updated>' . Utility::TimeInISO8601() . '</updated>');
     }
     if (EntityStates::Modified == $resourceBox->State) {
         $editLinkUri = $resourceBox->Identity;
         Utility::WriteLine($changesetBodyForResource, '<id>' . $editLinkUri . '</id>');
         //While modifying, key properties cannot be null
         $keyPropertyNames = $type->geyKeyProperties();
         foreach ($keyPropertyNames as $keyPropertyName) {
             $prop = new ReflectionProperty($object, $keyPropertyName);
             $propertyValue = $prop->getValue($object);
             if (empty($propertyValue) && !$this->_processingMediaLinkEntry) {
                 throw new InvalidOperation(Resource::NullValueNotAllowedForKey . $keyPropertyName);
             }
         }
     } else {
         Utility::WriteLine($changesetBodyForResource, '<id />');
     }
     if (!$resourceBox->MediaLinkEntry) {
         Utility::WriteLine($changesetBodyForResource, "<content type=\"application/xml\">");
     }
     Utility::WriteLine($changesetBodyForResource, '<m:properties>');
     $nonEpmProperties = $type->getRawNonEPMProperties(true);
     foreach ($nonEpmProperties as $nonEpmProperty) {
         $propertyName = $nonEpmProperty->getName();
         $refProperty = new ReflectionProperty($object, $propertyName);
         $propertyValue = $refProperty->getValue($object);
         $body = $this->CheckAndCreateChangeSetBodyPartForComplexType($nonEpmProperty, $propertyValue);
         if ($body) {
             Utility::WriteLine($changesetBodyForResource, $body);
             continue;
         }
         $property = '';
         // determine if the property is null and should be output accordingly
         // for numeric types, utilize a numeric value
         if ($propertyValue) {
             Utility::GetPropertyType($refProperty, $notNullable);
             if (!$notNullable) {
                 $property = "<d:" . $propertyName . " " . "m:null=\"true\" />";
             } elseif (strpos($edmType, 'Edm.Decimal') === 0) {
                 $property = '<d:' . $propertyName . '>0.0M</d:' . $propertyName . '>';
             } elseif (strpos($edmType, 'Edm.Double') === 0) {
                 $property = '<d:' . $propertyName . '>0.0</d:' . $propertyName . '>';
             } elseif (strpos($edmType, 'Edm.Int') === 0) {
                 $property = '<d:' . $propertyName . '>0</d:' . $propertyName . '>';
             } elseif (strpos($edmType, 'Edm.Single') === 0) {
                 $property = '<d:' . $propertyName . '>0.0f</d:' . $propertyName . '>';
             } else {
                 /**
                  * The following comment is from the original authors and remains until
                  * further investigation can be made regarding proper behavior of
                  * non-nullable types.
                  */
                 //ex: In the case of OrderID, the ID is a autonumber, so user will not
                 //specify this value, since its a nonnullable value we cant set null=true
                 //property, in this case the correct property node should be
                 //<d:OrderID">0</d:OrderID">, but instead of this we can also achieve the
                 //same effect by not adding the property itself in xml
                 continue;
             }
         } else {
             $attributes = $nonEpmProperty->getAttributes();
             $edmType = '';
             if (isset($attributes['EdmType']) && $attributes['EdmType'] != 'Edm.String') {
                 $edmType = ' m:type="' . $attributes['EdmType'] . '"';
                 // wrap value in CDATA tag since strings may contain XML special characters
                 $propertyValue = "<![CDATA[" . $propertyValue . "]]>";
             }
             $property = '<d:' . $propertyName . $edmType . '>' . $propertyValue . '</d:' . $propertyName . '>';
         }
         Utility::WriteLine($changesetBodyForResource, $property);
     }
     //Check for CF properties for which user has set null value. In this
     //case these properties should be added in the content section.
     foreach ($nullCFProperties as $nullCFProperty) {
         $refProperty = new ReflectionProperty($object, $propertyName);
         $property = "<d:" . $nullCFProperty . " " . "m:null=\"true\" />";
         Utility::WriteLine($changesetBodyForResource, $property);
     }
     Utility::WriteLine($changesetBodyForResource, '</m:properties>');
     if (!$resourceBox->MediaLinkEntry) {
         Utility::WriteLine($changesetBodyForResource, '</content>');
     }
     //append CF Cutom XML
     if (!empty($CF_NonSyndicationXML)) {
         Utility::WriteLine($changesetBodyForResource, $CF_NonSyndicationXML);
     }
     Utility::WriteLine($changesetBodyForResource, '</entry>');
     if ($newline) {
         Utility::WriteLine($changesetBodyForResource, null);
     }
     return $changesetBodyForResource;
 }
Ejemplo n.º 6
0
/**
* This function is used for the in/output by zarafa.php to store the XML to disk
*/
function dump_xml($xml, $prefix)
{
    global $debug_xml_id;
    if (DEBUG_XMLOUT) {
        if (!isset($debug_xml_id) || empty($debug_xml_id)) {
            $debug_xml_id = strftime("%Y%m%d%H%M%S") . uniqid("_");
        }
        if (DEBUG_XMLOUT_FORMAT_INPUT && $prefix == "in") {
            $parser = new XMLParser();
            $data = $parser->getData($xml);
            $builder = new XMLBuilder();
            $xml = $builder->build($data);
        }
        if (is_dir(DEBUG_XMLOUT_DIR)) {
            $fh = fopen(DEBUG_XMLOUT_DIR . $prefix . "_" . $debug_xml_id . ".xml" . (DEBUG_XMLOUT_GZIP ? ".gz" : ""), "w");
            fwrite($fh, DEBUG_XMLOUT_GZIP ? gzencode($xml) : $xml);
            fclose($fh);
        }
    }
}
Ejemplo n.º 7
0
 public function getDetail($orderid)
 {
     $credentials = $this->__get_credentials();
     $username = $this->name;
     $password = $this->password;
     $clientid = $this->company;
     $document = new XMLBuilder();
     $elements = array("Name" => $username, "Password" => $password, "ClientId" => $clientid, "Mode" => "P", "OrderId" => $orderid);
     $domElements = $document->createElementsWithTextNodes($elements);
     $document->appendListOfElementsToElement($document->root(), $domElements);
     $element = $document->createElement("Extra");
     $statusElement = $document->createElementWithTextNode("ORDERSTATUS", "SOR");
     $element->appendChild($statusElement);
     $document->root()->appendChild($element);
     $documentString = $document->saveXML();
     $this->raw_request = $documentString;
     /* After the XML request has been created, we should now set the HTTP request using curl library..   */
     $url = $this->__connect() . $this->credentials["detailOrderURL"];
     $curl = curl_init();
     $postData = urlencode("DATA") . urlencode("=") . urlencode($documentString);
     // Set the url..
     curl_setopt($curl, CURLOPT_URL, $url);
     // Set the HTTP method to POST..
     curl_setopt($curl, CURLOPT_POST, 1);
     // Set the HTTP response header to False not to get the response header..
     curl_setopt($curl, CURLOPT_HEADER, FALSE);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
     // Add the HTTP POST body..
     curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
     // Set the HTTP request header..
     curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-type" => "application/x-www-form-urlencoded"));
     // Execute the request and save the response inside a variable called 'raw_response'..
     $this->raw_response = curl_exec($curl);
     // Close the connection..
     curl_close($curl);
     // After we got the response, we should now parse it using xml library..
     $responseDomObject = new DOMDocument();
     $responseDomObject->loadXML($this->raw_response);
     // The result to be returned will be an array containing the response details..
     $result = array();
     $transid = XMLBuilder::get_data($responseDomObject, "TransId");
     $return_code = XMLBuilder::get_data($responseDomObject, "ProcReturnCode");
     $err_msg = XMLBuilder::get_data($responseDomObject, "ErrMsg");
     $host_ref_num = XMLBuilder::get_data($responseDomObject, "HOST_REF_NUM");
     $auth_code = XMLBuilder::get_data($responseDomObject, "AUTH_CODE");
     $charge_type = XMLBuilder::get_data($responseDomObject, "CHARGE_TYPE_CD");
     $details = XMLBuilder::get_data($responseDomObject, "ORDERSTATUS");
     $capture_amount = XMLBuilder::get_data($responseDomObject, "CAPTURE_AMT");
     $trx_date = XMLBuilder::get_data($responseDomObject, "CAPTURE_DTTM");
     $result["transid"] = $transid;
     $result["orderid"] = $orderid;
     $result["return_code"] = $return_code;
     $result["host_ref_num"] = $host_ref_num;
     $result["error_msg"] = $err_msg;
     $result["charge_type"] = $charge_type;
     $result["auth_code"] = $auth_code;
     $result["amount"] = "";
     $result["transaction_time"] = "";
     if ($trx_date) {
         try {
             $trx_date = explode(".", $trx_date);
             $trx_date = $trx_date[0];
             $trx_date = strptime($trx_date, "%Y-%m-%d %H:%M:%S");
             $result["transaction_time"] = $trx_date;
         } catch (Exception $e) {
         }
     }
     if ($capture_amount) {
         try {
             $capture_amount = intval($capture_amount) / 100.0;
             $result["amount"] = $capture_amount;
         } catch (Exception $e) {
         }
     }
     return $result;
 }
Ejemplo n.º 8
0
      
      <br><br>
      
      <table width="100%" border="0" cellspacing="2" cellpadding="2" align="center">
        <tr>
          <td><span class="small"><b>Surname</b></span></td>
          <td><span class="small"><b>Prename</b></span></td>
          <td><span class="small"><b>Party</b></span></td>
          <td><span class="small"><b>Position</b></span></td>
        </tr>
        
        <?php 
// Include the <phpXML/> class.
include "XMLBuilder.class.php";
// Create an XML object for the XML file.
$xml = new XMLBuilder("government.xml");
// Check whether a search term was given.
if (!empty($term)) {
    // Only select those persons, in whose name or position
    // the search string is present.
    $government = $xml->evaluate("//person/*[contains(., {$term})]/..");
} else {
    // Select all members of the government.
    $government = $xml->evaluate("//person");
}
// Run through all members of the government.
foreach ($government as $person) {
    // Retrieve information about the person.
    $surname = $xml->get_content($person . "/surname[1]");
    $prename = $xml->get_content($person . "/prename[1]");
    $party = $xml->get_content($person . "/party[1]");