本文整理汇总了PHP中XMLParser::setDocument方法的典型用法代码示例。如果您正苦于以下问题:PHP XMLParser::setDocument方法的具体用法?PHP XMLParser::setDocument怎么用?PHP XMLParser::setDocument使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XMLParser
的用法示例。
在下文中一共展示了XMLParser::setDocument方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _getRates
private function _getRates($response)
{
$doc = new \XMLDocument();
$xp = new \XMLParser();
$xp->setDocument($doc);
$xp->parse($response);
$doc = $xp->getDocument();
$rates = array();
$results = array();
if (is_object($doc->root)) {
$root = $doc->getRoot();
if ($root->getElementByName('ratesAndServicesResponse')) {
$service_rates = $root->getElementByName('ratesAndServicesResponse');
$shipment = $service_rates->getElementsByName('product');
$currencies = Registry::get('currencies');
if (!empty($currencies['CAD'])) {
for ($i = 0; $i < count($shipment); $i++) {
$id = $shipment[$i]->getAttribute("id");
if (!empty($id) && $id > 0) {
$rates[$id] = array('rate' => floatval($shipment[$i]->getValueByPath("rate")) * $currencies['CAD']['coefficient']);
if ($shipment[$i]->getValueByPath("deliveryDate") != '') {
$rates[$id]['delivery_time'] = $shipment[$i]->getValueByPath("deliveryDate");
}
unset($id);
}
}
$results['cost'] = $rates;
} else {
$results['error'] = __('canada_post_activation_error');
}
} elseif ($root->getElementByName('error')) {
$results['error'] = $root->getValueByPath('/error/statusMessage');
}
}
return $results;
}
示例2: fn_arb_get_error
function fn_arb_get_error($result, $request_type)
{
$doc = new XMLDocument();
$xp = new XMLParser();
$xp->setDocument($doc);
$xp->parse($result);
$doc = $xp->getDocument();
$return = array();
if (is_object($doc->root)) {
$root = $doc->getRoot();
$shipments = $root->getElementsByName($request_type);
if ($shipments) {
for ($k = 0; $k < count($shipments); $k++) {
$faults = $shipments[$k]->getElementByName("Faults");
if (!empty($faults)) {
$fault = $faults->getElementsByName("Fault");
for ($i = 0; $i < count($fault); $i++) {
$return[] = $fault[$i]->getValueByPath("/Desc") . ($fault[$i]->getElementByName("Context") ? ' (' . trim($fault[$i]->getValueByPath("/Context")) . ')' : '');
}
}
}
}
}
return implode(' / ', $return);
}
示例3: processErrors
/**
* Gets error message from shipping service server
*
* @param string $response Response from Shipping service server
* @return string Text of error or false if no errors
*/
public function processErrors($response)
{
$doc = new \XMLDocument();
$xp = new \XMLParser();
$xp->setDocument($doc);
$xp->parse($response);
$doc = $xp->getDocument();
$return = array();
if (is_object($doc->root)) {
$root = $doc->getRoot();
// distinguish error reports from not available services
if ($root->name == 'res:ErrorResponse') {
$path = array('Response', 'Status');
} else {
$path = array('GetQuoteResponse', 'Note');
}
foreach ($path as $node) {
$root = $root->getElementsByName($node);
if ($root) {
$root = $root[0];
} else {
break;
}
}
if ($root) {
$conditions = $root->getElementsByName('Condition');
foreach ($conditions as $condition) {
$error_code = trim($condition->getValueByPath('ConditionCode'));
$error_text = trim($condition->getValueByPath('ConditionData'));
$return[] = "({$error_code}) {$error_text}";
}
}
}
return implode(' / ', $return);
}
示例4: fn_ups_get_rates
function fn_ups_get_rates($result)
{
$doc = new XMLDocument();
$xp = new XMLParser();
$xp->setDocument($doc);
$xp->parse($result);
$doc = $xp->getDocument();
$return = array();
if (is_object($doc->root)) {
$responseStatusCode = $doc->getValueByPath('RatingServiceSelectionResponse/Response/ResponseStatusCode');
$root = $doc->getRoot();
$shipment = $root->getElementsByName("RatedShipment");
for ($i = 0; $i < count($shipment); $i++) {
$service_code = $shipment[$i]->getValueByPath("/Service/Code");
$total_charge = $shipment[$i]->getValueByPath("/TotalCharges/MonetaryValue");
if (!($service_code && $total_charge)) {
continue;
}
//$rated_packages = $shipment[$i]->getElementsByName("RatedPackage");
//$days_to_delivery = $shipment[$i]->getValueByPath("/GuaranteedDaysToDelivery");
//$delivery_time = $shipment[$i]->getValueByPath("/ScheduledDeliveryTime");
if (!empty($total_charge)) {
$return[$service_code] = $total_charge;
}
}
}
return $return;
}
示例5: fn_qb_get_xml_body
function fn_qb_get_xml_body($response)
{
$doc = new XMLDocument();
$xp = new XMLParser();
$xp->setDocument($doc);
$xp->parse($response);
$doc = $xp->getDocument();
$root = $doc->getRoot();
return $root;
}
示例6: fn_usps_get_rates
function fn_usps_get_rates($result, $is_domestic)
{
// Parse XML message returned by the UPS post server.
$doc = new XMLDocument();
$xp = new XMLParser();
$xp->setDocument($doc);
$xp->parse($result);
$doc = $xp->getDocument();
$return = array();
if (is_object($doc->root)) {
$root = $doc->getRoot();
if ($is_domestic == true) {
$shipment = $root->getElementsByName("Package");
} else {
$shipment = $root->getElementByName("Package");
if (!empty($shipment)) {
$shipment = $shipment->getElementsByName("Service");
} else {
return false;
}
}
for ($i = 0; $i < count($shipment); $i++) {
$service_name = '';
if ($is_domestic == true) {
if ($shipment[$i]->getElementByName("Postage")) {
$service_name = $shipment[$i]->getValueByPath("/Postage/MailService");
$rate = $shipment[$i]->getValueByPath("/Postage/Rate");
if (floatval($rate)) {
$is_machinable = $shipment[$i]->getValueByPath("/Machinable");
if ($service_name == 'Parcel Post') {
$service_name .= $is_machinable == 'TRUE' ? ' M' : ' N';
} elseif (strpos($service_name, 'Express Mail') !== false) {
$service_name = 'Express Mail';
} elseif (strpos($service_name, 'Priority Mail') !== false) {
$service_name = 'Priority Mail';
} elseif (strpos($service_name, 'First-Class Mail') !== false) {
$service_name = 'First-Class Mail';
}
}
}
} else {
if ($shipment[$i]->getElementByName("Postage")) {
$service_name = $shipment[$i]->getValueByPath("/SvcDescription");
$rate = $shipment[$i]->getValueByPath("/Postage");
}
}
if (empty($service_name)) {
continue;
}
$return[$service_name] = $rate;
}
return $return;
}
return false;
}
示例7: XMLDocument
//
// $Id: google_calculations.php 10329 2010-08-03 14:46:04Z klerik $
//
define('AREA', 'C');
define('AREA_NAME', 'customer');
define('SKIP_SESSION_VALIDATION', true);
require './../prepare.php';
require './../init.php';
include DIR_LIB . 'xmldocument/xmldocument.php';
// TODO:
// 1. Add coupons calculation (merchant-code-string)
// 2. Price-included taxes - how to display? Now displays as zero tax
$xml_response = $GLOBALS['HTTP_RAW_POST_DATA'];
$doc = new XMLDocument();
$xp = new XMLParser();
$xp->setDocument($doc);
$xp->parse($xml_response);
$doc = $xp->getDocument();
if (is_object($doc->root)) {
$root = $doc->getRoot();
$message_recognizer = $root->getName();
} else {
fn_google_xml_error('GCC: failed to parse incoming XML');
}
if ($message_recognizer != 'merchant-calculation-callback') {
fn_google_xml_error('GCC: incoming XML is not that we are expecting');
}
// Restart session
$google_sess_id = $root->getValueByPath('shopping-cart/merchant-private-data/additional_data/session_id');
if (empty($google_sess_id)) {
fn_google_xml_error('GCC: failed to get session ID from XML');
示例8: array
function _transitparseResult($xmlTransitResult)
{
$transitTime = array();
// Parse XML message returned by the UPS post server.
$doc = new XMLDocument();
$xp = new XMLParser();
$xp->setDocument($doc);
$xp->parse($xmlTransitResult);
$doc = $xp->getDocument();
// Get version. Must be xpci version 1.0001 or this might not work.
// 1.0001 and 1.0002 seem to be very similar, forget about this for the moment
/* $responseVersion = $doc->getValueByPath('TimeInTransitResponse/Response/TransactionReference/XpciVersion');
if ($this->transitxpci_version != $responseVersion) {
$message = MODULE_SHIPPING_UPSXML_RATES_TEXT_COMM_VERSION_ERROR;
return $message;
} */
// Get response code. 1 = SUCCESS, 0 = FAIL
$responseStatusCode = $doc->getValueByPath('TimeInTransitResponse/Response/ResponseStatusCode');
if ($responseStatusCode != '1') {
$errorMsg = $doc->getValueByPath('TimeInTransitResponse/Response/Error/ErrorCode');
$errorMsg .= ": ";
$errorMsg .= $doc->getValueByPath('TimeInTransitResponse/Response/Error/ErrorDescription');
// send email if enabled in the admin section
if ($this->email_errors) {
error_log("UPSXML TimeInTransit Error: " . $errorMsg . " experienced by customer with id " . $_SESSION['customer_id'] . " on " . date('Y-m-d H:i:s'), 1, STORE_OWNER_EMAIL_ADDRESS);
}
// log errors to file ups_error.log when set
if ($this->ups_error_file) {
error_log(date('Y-m-d H:i:s') . "\tTimeInTransit\t" . $errorMsg . "\t" . $_SESSION['customer_id'] . "\n", 3, $this->ups_error_file);
}
return $errorMsg;
}
$root = $doc->getRoot();
$rootChildren = $root->getChildren();
for ($r = 0; $r < count($rootChildren); $r++) {
$elementName = $rootChildren[$r]->getName();
if ($elementName == "TransitResponse") {
$transitResponse = $root->getElementsByName("TransitResponse");
$serviceSummary = $transitResponse['0']->getElementsByName("ServiceSummary");
$this->numberServices = count($serviceSummary);
for ($s = 0; $s < $this->numberServices; $s++) {
// index by Desc because that's all we can relate back to the service with
// (though it can probably return the code as well..)
$serviceDesc = $serviceSummary[$s]->getValueByPath("Service/Description");
$transitTime[$serviceDesc]["days"] = $serviceSummary[$s]->getValueByPath("EstimatedArrival/BusinessTransitDays");
$transitTime[$serviceDesc]["date"] = $serviceSummary[$s]->getValueByPath("EstimatedArrival/Date");
$transitTime[$serviceDesc]["guaranteed"] = $serviceSummary[$s]->getValueByPath("Guaranteed/Code");
}
}
}
if ($this->logfile) {
error_log("------------------------------------------\n", 3, $this->logfile);
foreach ($transitTime as $desc => $time) {
error_log("Business Transit: " . $desc . " = " . $time["date"] . "\n", 3, $this->logfile);
}
}
return $transitTime;
}