当前位置: 首页>>代码示例>>PHP>>正文


PHP XML2Array类代码示例

本文整理汇总了PHP中XML2Array的典型用法代码示例。如果您正苦于以下问题:PHP XML2Array类的具体用法?PHP XML2Array怎么用?PHP XML2Array使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了XML2Array类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: __construct

 /**
  * @param string $xml - XML de resposta do Webservice
  */
 function __construct($xml)
 {
     $array = XML2Array::createArray($xml);
     foreach ($array as $indice => $valor) {
         $this->array = $valor;
         switch ($indice) {
             case 'AUTHORIZATION':
                 //GetAuthorized
                 $this->retornoAutorizacao();
                 break;
             case 'CONFIRMATION':
                 //vários casos
                 $this->retornoConfirmacao();
                 break;
             case 'COUNCIL':
                 //CouncilReport
                 $this->retornoVendas();
                 break;
             case 'REPORT':
                 //SalesSumm
                 $this->retornoRelatorio();
                 break;
             case 'ROOT':
                 //Erro no CouncilReport ou SalesSumm
                 $this->retornoErro();
                 break;
             default:
                 throw new \UnexpectedValueException('Retorno inesperado.');
         }
     }
     unset($this->array);
     //o atributo não será mais utilizado
 }
开发者ID:jonathanweb,项目名称:KomerciAPI,代码行数:36,代码来源:Response.php

示例2: getParamsFromRequest

 /**
  * Parse params from request.
  * @return array
  */
 public function getParamsFromRequest()
 {
     $requestMethod = strtolower($_SERVER['REQUEST_METHOD']);
     switch ($requestMethod) {
         case 'get':
             $params = $_GET;
             break;
         case 'post':
             $params = $_POST;
             $xml = @simplexml_load_string($params['data']);
             if (false !== $xml && null !== $xml) {
                 $params = XML2Array::createArray($params['data']);
             }
             break;
         case 'put':
             parse_str(file_get_contents('php://input'), $params);
             $xml = @simplexml_load_string($params['data']);
             if (false !== $xml && null !== $xml) {
                 $params = XML2Array::createArray($params['data']);
             }
             $params['id'] = $_GET['id'];
             break;
         case 'delete':
             $params['id'] = $_GET['id'];
             break;
     }
     return $params;
 }
开发者ID:maruthisivaprasad,项目名称:zurmo,代码行数:32,代码来源:ApiRestRequest.php

示例3: _xml2array

 private static function _xml2array($xml)
 {
     if (!$xml || $xml == "") {
         return array();
     }
     require_once dirname(__FILE__) . "/xml2array.lib.class.php";
     return XML2Array::createArray($xml);
 }
开发者ID:huqq1987,项目名称:clone-lemon,代码行数:8,代码来源:mqs.sdk.class.php

示例4: transform

 /**
  * Transforms the API response into a PHP array
  *
  * @static
  * @param $response
  * @param $format
  * @return array|mixed|DOMDocument
  */
 public static function transform($response, $format)
 {
     if ($format == "json") {
         return json_decode($response);
     } elseif ($format == "xml") {
         return XML2Array::createArray($response);
     } else {
         throw new \Exception("{$format} transformer is not implemented yet");
     }
 }
开发者ID:nass600,项目名称:CosmBundle,代码行数:18,代码来源:ResponseToArrayTransformer.php

示例5: login

 protected function login($username = 'super', $password = 'super', $type = 'json')
 {
     $headers = array('Accept: application/' . $type, 'ZURMO_AUTH_USERNAME: ' . $username, 'ZURMO_AUTH_PASSWORD: ' . $password, 'ZURMO_API_REQUEST_TYPE: REST');
     $response = ApiRestTestHelper::createApiCall($this->serverUrl . '/test.php/zurmo/api/login', 'POST', $headers);
     if ($type == 'json') {
         $response = json_decode($response, true);
     } elseif ($type == 'xml') {
         $response = XML2Array::createArray($response);
     }
     if ($response['status'] == ApiResponse::STATUS_SUCCESS) {
         return $response['data'];
     } else {
         return false;
     }
 }
开发者ID:youprofit,项目名称:Zurmo,代码行数:15,代码来源:ApiRestTest.php

示例6: Exception

    /**
     * Convert an XML to Array
     * @param string $node_name - name of the root node to be converted
     * @param array $arr - aray to be converterd
     * @return DOMDocument
     */
    public static function &createArray($input_xml) {
        $xml = self::getXMLRoot();
		if(is_string($input_xml)) {
			$parsed = $xml->loadXML($input_xml);
			if(!$parsed) {
				throw new Exception('[XML2Array] Error parsing the XML string.');
			}
		} else {
			if(get_class($input_xml) != 'DOMDocument') {
				throw new Exception('[XML2Array] The input XML object should be of type: DOMDocument.');
			}
			$xml = self::$xml = $input_xml;
		}
		$array[$xml->documentElement->tagName] = self::convert($xml->documentElement);
        self::$xml = null;    // clear the xml node in the class for 2nd time use.
        return $array;
    }
开发者ID:JeffreyMartinezEiso,项目名称:lrv,代码行数:23,代码来源:XML2Array.php

示例7: getBookJSONFromXMLNode2

 /**
  * Obtiene y limpia el JSON final para insertar el ebook como documento
  * Limpia y agrega los campos de _id y lastUpdate
  */
 public static function getBookJSONFromXMLNode2($node)
 {
     //Funcion de procesamiento del XMl a la cadena JSON
     $arr = XML2Array::createArray($node);
     //Agrega last update y limpia el inicio y fin para simplificar la jerarquia
     //De esta forma no funciona al pasar a json se pierde
     //$arr['book']['lastUpdate'] = new MongoDate();
     $date = new MongoDate();
     $arr['book']['lastUpdate'] = array('$date' => $date->sec * 1000 + $date->usec / 1000);
     $mongo_id = str_replace('-', '', $arr['book']['@attributes']['id']);
     $arr['book']['_id'] = $mongo_id;
     //concvert to json
     $jsonContents = json_encode($arr);
     //Eliminación de datos innecesarios en la cadena JSON
     $json_string = Utils::cleanJSON($jsonContents);
     return $json_string;
 }
开发者ID:carlosmirandadiaz,项目名称:LectoGeeks,代码行数:21,代码来源:Utils.php

示例8: getResponse

 /**
  * getResponse function
  * This will get a detailed description from MedlinePlus Connect
  * @param $coding
  * @param $code
  * @return \Array
  */
 function getResponse($coding, $code)
 {
     if ($coding == 'ICD9') {
         $this->codingSystem = 'mainSearchCriteria.v.cs=2.16.840.1.113883.6.103';
     }
     if ($coding == 'SNOMED') {
         $this->codingSystem = 'mainSearchCriteria.v.cs=2.16.840.1.113883.6.96';
     }
     if ($coding == 'RXCUI') {
         $this->codingSystem = 'mainSearchCriteria.v.cs=2.16.840.1.113883.6.88';
     }
     if ($coding == 'NDC') {
         $this->codingSystem = 'mainSearchCriteria.v.cs=2.16.840.1.113883.6.69';
     }
     if ($coding == 'LOINC') {
         $this->codingSystem = 'mainSearchCriteria.v.cs=2.16.840.1.113883.6.1';
     }
     $urlBuilder = $this->medlineUrl . $this->codingSystem . '&mainSearchCriteria.v.c=' . $code;
     $xmlData = simplexml_load_file($urlBuilder);
     return \XML2Array::createArray($xmlData);
 }
开发者ID:igez,项目名称:gaiaehr,代码行数:28,代码来源:MedlinePlus.php

示例9: preg_replace

 /**
  * Convert an XML to Array
  * @param $input_xml
  * @return DOMDocument
  * @throws Exception
  * @internal param string $node_name - name of the root node to be converted
  * @internal param array $arr - aray to be converterd
  */
 public static function &createArray($input_xml)
 {
     // clean xml comments
     $input_xml = preg_replace('/<!--[\\s\\S\\W\\D]*?-->/', '', $input_xml);
     $input_xml = str_replace(['&', '<br/>', '<br />'], ['&amp;', ' ', ' '], $input_xml);
     $xml = self::getXMLRoot();
     if (is_string($input_xml)) {
         $parsed = $xml->loadXML($input_xml);
         if (!$parsed) {
             throw new Exception('[XML2Array] Error parsing the XML string.');
         }
     } else {
         if (get_class($input_xml) != 'DOMDocument') {
             throw new Exception('[XML2Array] The input XML object should be of type: DOMDocument.');
         }
         $xml = self::$xml = $input_xml;
     }
     $array[$xml->documentElement->tagName] = self::convert($xml->documentElement);
     self::$xml = null;
     // clear the xml node in the class for 2nd time use.
     return $array;
 }
开发者ID:igez,项目名称:gaiaehr,代码行数:30,代码来源:XML2Array.php

示例10: markers_deployable

function markers_deployable($res, $world)
{
    $markers = array();
    $xml = file_get_contents('vehicles.xml', true);
    require_once 'modules/lib/class.xml2array.php';
    $vehicles_xml = XML2Array::createArray($xml);
    while ($row = mysql_fetch_array($res)) {
        $Worldspace = str_replace("[", "", $row['Worldspace']);
        $Worldspace = str_replace("]", "", $Worldspace);
        $Worldspace = explode(",", $Worldspace);
        $x = 0;
        if (array_key_exists(1, $Worldspace)) {
            $x = $Worldspace[1];
        }
        $y = 0;
        if (array_key_exists(2, $Worldspace)) {
            $y = $Worldspace[2];
        }
        $type = $row['Classname'];
        $ltype = strtolower($type);
        if (array_key_exists('s' . $ltype, $vehicles_xml['vehicles'])) {
            $class = $vehicles_xml['vehicles']['s' . $ltype]['Type'];
        } else {
            $class = "Car";
        }
        require_once 'modules/calc.php';
        $description = '<h2><a href="index.php?view=info&show=5&id=' . $row['ObjectID'] . '">' . $type . '</a></h2><table><tr><td><img src="images/vehicles/' . $ltype . '.png" alt="" style="width: 100px;" /></td><td>&nbsp;&nbsp;&nbsp;</td><td style="vertical-align: top;"><h2>Position:</h2>Left: ' . round(world_x($x, $world)) . '<br />Top: ' . round(world_y($y, $world)) . '</td></tr></table>';
        $tmp = array();
        $tmp["lat"] = world_y($y, $world) / 10;
        $tmp["lng"] = world_x($x, $world) / 10;
        $tmp["icon"] = $class;
        $tmp["title"] = $type . " (" . $row['ObjectID'] . ")";
        $tmp["description"] = $description;
        $markers[] = $tmp;
    }
    return $markers;
}
开发者ID:Reema49,项目名称:dayz,代码行数:37,代码来源:markers.php

示例11: Exception

 /**
  * Convert an XML to Array
  * @param string $node_name - name of the root node to be converted
  * @param array $arr - aray to be converterd
  * @return DOMDocument
  */
 public static function &createArray($input_xml)
 {
     $xml = self::getXMLRoot();
     if (is_string($input_xml)) {
         $parsed = $xml->loadXML($input_xml);
         if (!$parsed) {
             echo "XML String = {$input_xml}\n";
             throw new Exception('[XML2Array] Error parsing the XML string.');
         }
     } else {
         if (get_class($input_xml) != 'DOMDocument') {
             $fhe = fopen("exception.log", "w+");
             # throw new Exception('[XML2Array] The input XML object should be of type: DOMDocument.');
             $errmsg = "throw new Exception('[XML2Array] The input XML object should be of type: DOMDocument.')\n";
             fwrite($fhe, $errmsg);
             fclose($fhe);
         }
         $xml = self::$xml = $input_xml;
     }
     $array[$xml->documentElement->tagName] = self::convert($xml->documentElement);
     self::$xml = null;
     // clear the xml node in the class for 2nd time use.
     return $array;
 }
开发者ID:nightbeacons,项目名称:translate,代码行数:30,代码来源:xml2array.php

示例12: file_get_contents

 } else {
     // xml file //
     $cu3er_pathDir = $baseurl . '/' . $rand;
     $dir = $basedir . '/' . $rand;
     $xmlName[0] = $testXmlFile;
 }
 if ($testXmlFile != '') {
     $xmlStr = file_get_contents($testXmlFile);
     if (!file_exists($dir . '/' . basename($xmlName[0]))) {
         touch($dir . '/' . basename($xmlName[0]));
         $handle = fopen($dir . '/' . basename($xmlName[0]), 'w+');
         fwrite($handle, $xmlStr);
         fclose($handle);
     }
     include_once "xml2array.php";
     $xml_debugger = new XML2Array();
     if ($xmlStr != '') {
         $xmlStr = preg_replace('/\\<transition(.*?)\\>/', '<transition empty="true"$1>', $xmlStr);
     }
     $arrXml = $xml_debugger->parse($xmlStr);
     if (!is_array($arrXml)) {
         $xmlStr = cu3er__our_fopen($testXmlFile);
         if ($xmlStr == false) {
             echo $cu3er_messages['missingXML'];
         } else {
             $xmlStr = preg_replace('/\\<transition(.*?)\\>/', '<transition empty="true"$1>', $xmlStr);
             $arrXml = $xml_debugger->parse($xmlStr);
         }
     }
     if (!is_array($arrXml)) {
         echo $cu3er_messages['notXML'];
开发者ID:shieldsdesignstudio,项目名称:forefield,代码行数:31,代码来源:ajaxReq.php

示例13: parse_response

 /**
  * 转换响应
  * @param $response
  * @return array
  * @throws Exception
  */
 public static function parse_response($response, $format = "array")
 {
     //如果启用响应结果转换,则进行转换,否则原样返回
     $body = $response->body;
     $headers = $response->header;
     switch (strtolower($format)) {
         case 'array':
             $body = empty($body) ? $body : XML2Array::createArray($body);
             break;
         case "json":
             $body = empty($body) ? $body : json_encode(XML2Array::createArray($body));
             break;
         default:
             break;
     }
     return array('success' => $response->isOk(), 'status' => $response->status, 'header' => $headers, 'body' => $body);
     return $response;
 }
开发者ID:283541486,项目名称:kaixinwa2.0,代码行数:24,代码来源:oss_util.class.php

示例14: translateOneNode

function translateOneNode($currentNodeID, $to_languages, $content_type)
{
    global $db, $XMLarray, $error_log;
    $separator = "7543545165934149";
    // Fetch a node from Drupal if a copy does not already exist in sources dir.
    //  $xml_MASTER is the original English-language version
    //  $xml is the copy that will be translated
    $fn = getcwd() . "/sources/SOURCE_" . $currentNodeID . ".XML";
    if (file_exists($fn)) {
        $xml_MASTER = file_get_contents($fn);
        if ($content_type == "page") {
            // Remove <teaser> from "page". The "teaser" is created by truncating the <body>, resulting in invalid XML
            $xml_MASTER = preg_replace("|<teaser>.*?</teaser>|us", "<teaser></teaser>", $xml_MASTER);
        }
    } else {
        $xml_MASTER = fetchOneNode($currentNodeID);
        if ($content_type == "page") {
            $xml_MASTER = preg_replace("|<teaser>.*?</teaser>|us", "<teaser></teaser>", $xml_MASTER);
        }
        $fh = fopen($fn, "w");
        fwrite($fh, $xml_MASTER);
        fclose($fh);
    }
    foreach ($to_languages as $to_language) {
        $query = "select drupal_code from sovee.languages where sovee_code = '" . $to_language . "'";
        $result = mysql_query($query, $db);
        while ($row = mysql_fetch_assoc($result)) {
            $drupalLanguageCode = $row['drupal_code'];
        }
        mysql_free_result($result);
        echo "\n=====================================================================================\n==========                                                                 ==========\n. . . Translating node {$currentNodeID} ({$content_type}) into {$to_language}  . . . \n";
        $error_IncompleteNodeFlag = 0;
        $xml = $xml_MASTER;
        // Create a copy of the master, to be translated
        // Convert XML to array
        $XMLarray = XML2Array::createArray($xml);
        // Get info about the node
        //      Requested info is placed in the $requestedTags array
        //      and returned in the assoc. array info()
        $requestedTags = array("type", "tnid");
        $info = getXMLinfo($xml, $requestedTags);
        $derivedContentType = $info['type'];
        // Build list of containers to parse for the given content_type.
        $query = "select DISTINCT sovee.node_fields.name from sovee.content_type \nLEFT JOIN sovee.field_map ON sovee.content_type.id = sovee.field_map.content_id\nLEFT JOIN sovee.node_fields ON sovee.node_fields.id = sovee.field_map.field_id\nWHERE sovee.content_type.name = '" . $derivedContentType . "'";
        $result = mysql_query($query, $db);
        while ($row = mysql_fetch_assoc($result)) {
            $containerArrayTemplate[] = $row['name'];
        }
        mysql_free_result($result);
        // Walk throught the array, extract the specified containers, translate
        // and replace in the array
        // All array elements are assumed to be in the [node_export][node] array
        //  $containerArrayTemplate = array("body", "title", "teaser", "field_product_subtitle|n*|value", "field_warranty|n*|value", "field_product_education|n*|value",
        // 		 	"field_prod_man_docs_link|n*|title",
        //                       "field_did_you_know|n*|value", "field_product_benefits|n*|value",  "nodewords|copyright|value", "nodewords|dcterms.contributor|value",
        //		        "nodewords|dcterms.title|value", "nodewords|description|value", "nodewords|keywords|value" );
        $containerArray = expandTemplate($containerArrayTemplate);
        $allContainers = "<div>{$separator}";
        foreach ($containerArray as $oneContainer) {
            echo "\nProcessing container {$oneContainer}\n";
            $parents = explode("|", $oneContainer);
            array_unshift($parents, "node_export", "node");
            #echo "Parents: ";
            #print_r($parents);
            $XMLfragment = drupal_array_get_nested_value($XMLarray, $parents);
            if (is_array($XMLfragment)) {
                $XMLfragment = "";
            }
            $translatedFragment = "";
            $patterns = array("|^<div>|us", "|</div>\$|us");
            // The "|u" flag enables multibyte support
            $replacements = array("", "");
            if (strlen(trim($XMLfragment)) > 0 and !is_array($XMLfragment)) {
                $XMLfragment = "<div>" . $XMLfragment . "</div>";
                // Encapsulate in dummy <div> to satisfy Sovee translator
                // echo "ORIGINAL Fragment = |$XMLfragment|\n";
            } else {
                echo "Original Fragment |{$XMLfragment}| is empty -- skipping.\n";
            }
            $allContainers .= $XMLfragment . $separator;
            // Add at the end of each container to faciliate preg_split
        }
        //   -------  End of foreach($containerArray as $oneContainer)
        $allContainers .= "</div>";
        // Translate the entire node if target language is not English
        echo "TO_LANGUAGE = {$to_language}\n";
        $xxx = substr($to_language, 0, 2);
        echo "SUBSTR = |{$xxx}|\n";
        $sovee_to_language = $to_language;
        if (substr($to_language, 0, 2) != "en") {
            if ($to_language == "es-419") {
                $sovee_to_language = "es-es";
            }
            // Use standard Spanish for Latin America
            echo "Sending strings to Sovee . . . \n";
            $translatedFragmentAry = translateFrag($allContainers, $currentNodeID, "FULL NODE", $to_language);
            // Perform the translation
            $translatedFragment = $translatedFragmentAry['content'];
            $translatedFragmentError = $translatedFragmentAry['error_count'];
            // Count of translation errors.  0 = success
//.........这里部分代码省略.........
开发者ID:nightbeacons,项目名称:translate,代码行数:101,代码来源:content.php

示例15: array_merge

    if ($in) {
        $prov['cfg_behavior'] = array_merge($prov['cfg_behavior'], XML2Array::createArray($in));
    }
    $in = '';
    if ($in) {
        $prov['cfg_base'] = XML2Array::createArray($in);
    }
    /* if you have more the 1 subselection add this seperatly */
    $in = '';
    if ($in) {
        $prov['cfg_base'] = array_merge($prov['cfg_base'], XML2Array::createArray($in));
    }
    $in = '';
    if ($in) {
        $prov['cfg_base'] = array_merge($prov['cfg_base'], XML2Array::createArray($in));
    }
    $in = '';
    if ($in) {
        $prov['cfg_tone'] = XML2Array::createArray($in);
    }
    $in = '';
    if ($in) {
        $prov['cfg_keys'] = XML2Array::createArray($in);
    }
    $prov['cfg_key'] = json_decode(plain2json($in, $del));
    $prov['pvt_generator'] = 'json2xml';
    $prov['pvt_counter'] = 1;
    $prov['pvt_type'] = 'provisioner';
    echo upload_phone_data($prov);
    unset($prov);
}
开发者ID:urueedi,项目名称:kazoo-provision,代码行数:31,代码来源:polycom_template_xml.php


注:本文中的XML2Array类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。