提取出xml数据包中的加密消息

@param string $xmltext 待提取的xml字符串

@return string 提取出的加密消息字符串
485392
public function extract($xmltext)
    {
        try {
            $object     = simplexml_load_string($xmltext, 'SimpleXMLElement', LIBXML_NOCDATA);
            $encrypt    = $object->Encrypt;
            $tousername = $object->ToUserName;

            return [0, $encrypt, $tousername];
        } catch (Exception $e) {
            //print $e . "\n";
            return [ErrorCode::$ParseXmlError, null, null];
        }
    }
1046213
function xmlString( )
    {
        $doc = new DOMDocument( '1.0', 'utf-8' );

        $root = $doc->createElement( "ezoption" );
        $doc->appendChild( $root );

        $name = $doc->createElement( "name" );
        $name->appendChild( $doc->createCDATASection( $this->Name ) );
        $root->appendChild( $name );

        $options = $doc->createElement( "options" );
        $root->appendChild( $options );

        foreach ( $this->Options as $option )
        {
            $optionNode = $doc->createElement( "option" );
            $optionNode->appendChild( $doc->createCDATASection( $option["value"] ) );
            $optionNode->setAttribute( "id", $option['id'] );
            $optionNode->setAttribute( 'additional_price', $option['additional_price'] );
            $options->appendChild( $optionNode );
        }

        $xml = $doc->saveXML();

        return $xml;
    }
605218
public static function format($xml) {
        $domtree = new DOMDocument('1.0', 'UTF-8');
        $domtree->loadXML($xml);
        $domtree->preserveWhiteSpace = false;
        $domtree->formatOutput = true;
        $domtree->setIndent = (1);
        return $domtree->saveXML();
    }
991533
function &outputText()
    {
        if ( !$this->XMLData )
        {
            $output = '';
            return $output;
        }

        $this->Tpl = eZTemplate::factory();
        $this->Res = eZTemplateDesignResource::instance();
        if ( $this->ContentObjectAttribute )
        {
            $this->Res->setKeys( array( array( 'attribute_identifier', $this->ContentObjectAttribute->attribute( 'contentclass_attribute_identifier' ) ) ) );
        }

        $this->Document = new DOMDocument( '1.0', 'utf-8' );
        $success = $this->Document->loadXML( $this->XMLData );

        if ( !$success )
        {
            $this->Output = '';
            return $this->Output;
        }

        $this->prefetch();

        $this->XMLSchema = eZXMLSchema::instance();

        // Add missing elements to the OutputTags array
        foreach( $this->XMLSchema->availableElements() as $element )
        {
            if ( !isset( $this->OutputTags[$element] ) )
            {
                 $this->OutputTags[$element] = array();
             }
        }

        $this->NestingLevel = 0;
        $params = array();

        $output = $this->outputTag( $this->Document->documentElement, $params );
        $this->Output = $output[1];

        unset( $this->Document );

        $this->Res->removeKey( 'attribute_identifier' );
        return $this->Output;
    }
728398
protected function loadXMLString($xmlString)
    {
        $document = new DOMDocument();

        libxml_use_internal_errors(true);
        libxml_clear_errors();

        // Options:
        // - substitute entities
        // - disable network access
        // - relax parser limits for document size/complexity
        $success = $document->loadXML($xmlString, LIBXML_NOENT | LIBXML_NONET | LIBXML_PARSEHUGE);

        if (!$success) {
            $messages = array();

            foreach (libxml_get_errors() as $error) {
                $messages[] = trim($error->message);
            }

            throw new InvalidArgumentException(
                '$inputValue',
                'Could not create XML document: ' . implode("\n", $messages)
            );
        }

        return $document;
    }
127674
private function restoreValueFromXmlString($xmlString)
    {
        $dom = new DOMDocument('1.0', 'utf-8');
        $authors = array();

        if ($dom->loadXML($xmlString) === true) {
            foreach ($dom->getElementsByTagName('author') as $author) {
                $authors[] = array(
                    'id' => $author->getAttribute('id'),
                    'name' => $author->getAttribute('name'),
                    'email' => $author->getAttribute('email'),
                );
            }
        }

        return $authors;
    }
976180
function formatXml(SimpleXMLElement $simpleXMLElement)
    {
        $xmlDocument = new DOMDocument('1.0');
        $xmlDocument->preserveWhiteSpace = false;
        $xmlDocument->formatOutput = true;
        $xmlDocument->loadXML($simpleXMLElement->asXML());

        return $xmlDocument->saveXML();
    }
440307
public function encode($xml)
    {
        if (empty($xml)) {
            return '';
        }

        libxml_clear_errors();
        $reader = new XMLReader();
        $reader->xml($xml);

        $binary = '';
        while (@$reader->read()) {
            switch ($reader->nodeType) {
                case XMLReader::NONE:
                    break;

                case XMLReader::ELEMENT:
                    $index = $this->getDictionaryIndex($reader->localName);
                    if ($reader->prefix && $index !== false) {
                        $binary .= chr(Constants::RECORD_TYPE_DICTIONARY_ELEMENT);
                        $this->writeString($binary, $reader->prefix);
                        $this->writeDictionaryString($binary, $index);
                    } elseif ($reader->prefix) {
                        $binary .= chr(Constants::RECORD_TYPE_ELEMENT);
                        $this->writeString($binary, $reader->prefix);
                        $this->writeString($binary, $reader->localName);
                    } elseif ($index !== false) {
                        $binary .= chr(Constants::RECORD_TYPE_SHORT_DICTIONARY_ELEMENT);
                        $this->writeDictionaryString($binary, $index);
                    } else {
                        $binary .= chr(Constants::RECORD_TYPE_SHORT_ELEMENT);
                        $this->writeString($binary, $reader->localName);
                    }
                    $emptyElement = $reader->isEmptyElement;
                    $this->writeAttributes($binary, $reader);
                    if ($emptyElement) {
                        $binary .= chr(Constants::RECORD_TYPE_END_ELEMENT);
                    }
                    break;

                case XMLReader::TEXT:
                    $this->writeTextRecord($binary, $reader->value);
                    break;

                case XMLReader::COMMENT:
                    $binary .= chr(Constants::RECORD_TYPE_COMMENT);
                    $this->writeString($binary, $reader->value);
                    break;

                case XMLReader::WHITESPACE:
                    break;

                case XMLReader::SIGNIFICANT_WHITESPACE:
                    $this->writeTextRecord($binary, $reader->value);
                    break;

                case XMLReader::END_ELEMENT:
                    // TODO: Use *_WITH_END_ELEMENT if possible
                    $binary .= chr(Constants::RECORD_TYPE_END_ELEMENT);
                    break;

                case XMLReader::ATTRIBUTE:
                    throw new EncodingException('Invalid encoding state.');

                case XMLReader::DOC:
                case XMLReader::DOC_TYPE:
                case XMLReader::DOC_FRAGMENT:
                case XMLReader::NOTATION:
                case XMLReader::XML_DECLARATION:
                case XMLReader::CDATA:
                case XMLReader::ENTITY:
                case XMLReader::ENTITY_REF:
                case XMLReader::END_ENTITY:
                case XMLReader::PI:
                default:
                    throw new EncodingException(sprintf('Unsupported XML node type %d.', $reader->nodeType));
            }
        }

        $last_error = libxml_get_last_error();
        if ($last_error !== false) {
            throw new EncodingException(sprintf('XML Parsing Error "%s".', rtrim($last_error->message)));
        }

        return $binary;
    }
204894
public static function toXml($xml)
    {
        if ($xml instanceof XmlBuilder) {
            return $xml->getDom();
        }
        if ($xml instanceof \DOMDocument) {
            return $xml;
        }
        $dom = new \DOMDocument();
        $dom->preserveWhiteSpace = false;
        if ($xml instanceof \DOMNode) {
            $xml = $dom->importNode($xml, true);
            $dom->appendChild($xml);
            return $dom;
        }

        if (is_array($xml)) {
            return self::arrayToXml($dom, $dom, $xml);
        }
        if (!empty($xml)) {
            $dom->loadXML($xml);
        }
        return $dom;
    }
763064
public static function fromXml(\DOMDocument $xml)
    {
        $static = new static();

        $loans = $xml->getElementsByTagName('loan');
        $static->loans = LoanCollection::fromXml($loans);

        $loanHistory = $xml->getElementsByTagName('loanHistory');
        $static->loanHistory = LoanCollection::fromXml($loanHistory);

        $holds = $xml->getElementsByTagName('hold');
        $static->holds = HoldCollection::fromXml($holds);

        $expenses = $xml->getElementsByTagName('fine');
        $static->expenses = ExpenseCollection::fromXml($expenses);

        $totalFine = $xml->getElementsByTagName('totalFine');
        $static->totalFine = FloatLiteral::fromXml($totalFine);

        $totalCost = $xml->getElementsByTagName('totalCost');
        $static->totalCost = FloatLiteral::fromXml($totalCost);

        $message = $xml->getElementsByTagName('message');
        $static->message = StringLiteral::fromXml($message);

        $loanHistoryConfig = $xml->getElementsByTagName('loanHistoryConfigurable');
        $static->loanHistoryConfigurable = BoolLiteral::fromXml($loanHistoryConfig);

        return $static;
    }
1218908
protected function xmlentities($string) { 
   		return str_replace( array( '&', '"', "'", '<', '>', '’' ), array( '&amp;' , '&quot;', '&apos;' , '&lt;' , '&gt;', '&apos;' ), $string);
	}
549906
public function fromXmlString($xmlstring)
    {
        try {
            libxml_use_internal_errors(true);
            $xmlDoc = new SimpleXMLElement($xmlstring);
        } catch (\Exception $e) {
            throw new InvalidXmlException('XML string could not be parsed');
        }

        return $this->fromXml($xmlDoc);
    }
64464
public function parseXml($xmlString)
    {
        $this->_entry->parseXml($xmlString);
        $content = $this->_entry->getContent();
        if (is_null($content)) {
            $this->_topicDescription = null;
        } else {
            $this->_topicDescription = TopicDescription::create($content->getText());
        }
    }
555289
public function extract($xmltext) {
        libxml_disable_entity_loader(true);
        try {
            $xml = new DOMDocument();
            $xml->loadXML($xmltext);
            $array_e    = $xml->getElementsByTagName('Encrypt');
            $array_a    = $xml->getElementsByTagName('ToUserName');
            $encrypt    = $array_e->item(0)->nodeValue;
            $tousername = $array_a->item(0)->nodeValue;
            return array(0, $encrypt, $tousername);
        } catch (Exception $e) {
            print $e . "\n";
            //return array(ErrorCode::$ParseXmlError, null, null);
        }
    }
379080
public static function parse($text)
	{
		if (isset(static::$beforeParse))
		{
			$text = call_user_func(static::$beforeParse, $text);
		}

		$xml = static::getCachedParser()->parse($text);

		if (isset(static::$afterParse))
		{
			$xml = call_user_func(static::$afterParse, $xml);
		}

		return $xml;
	}
903507
function decodeXML( $xmlString )
    {
        $dom = new DOMDocument( '1.0', 'utf-8' );
        $success = $dom->loadXML( $xmlString );
        if ( $xmlString != "" )
        {
            // set the name of the node
            $nameArray = $dom->getElementsByTagName( "name" );
            $this->setName( $nameArray->item( 0 )->textContent );

            $columnsNode = $dom->getElementsByTagName( "columns" )->item( 0 );
            $numColumns = $columnsNode->getAttribute( 'number');

            $rowsNode = $dom->getElementsByTagName( "rows" )->item( 0 );
            $numRows = $rowsNode->getAttribute( 'number' );

            $namedColumns = $dom->getElementsByTagName( "column" );
            $namedColumnList = array();
            if ( $namedColumns->length > 0 )
            {
                foreach ( $namedColumns as $namedColumn )
                {
                    $columnName = $namedColumn->textContent;
                    $columnID = $namedColumn->getAttribute( 'id' );
                    $columnNumber = $namedColumn->getAttribute( 'num' );
                    $namedColumnList[$columnNumber] = array( 'name' => $columnName,
                                                             'column_number' => $columnNumber,
                                                             'column_id' => $columnID );
                }
            }
            $cellNodes = $dom->getElementsByTagName( "c" );
            $cellList = array();
            foreach ( $cellNodes as $cellNode )
            {
                $cellList[] = $cellNode->textContent;
            }

            $rows = array( 'sequential' => array() );
            $sequentialRows = array();

            for ( $i = 1; $i <= $numRows; $i++ )
            {
                $row = array( 'identifier' => 'row_' . $i ,
                              'name' => 'Row_' . $i );
                $rowColumns = array();
                for ( $j = 1; $j <= $numColumns; $j++ )
                {
                    $rowColumns[] = $cellList[ ($i-1) * $numColumns + $j-1];
                }
                $row['columns'] = $rowColumns;
                $sequentialRows[] = $row;
            }
            $rows['sequential'] = $sequentialRows;

            $columns = array( 'sequential' => array(),
                              'id' => array() );
            $sequentialColumns = array();
            $idColumns = array();

            for ( $i = 0; $i < $numColumns; $i++ )
            {
                if ( isset( $column ) )
                    unset( $column );
                $column = array();
                if ( isset( $namedColumnList[$i] ) && is_array( $namedColumnList[$i] ) )
                {
                    $column = array( 'identifier' => $namedColumnList[$i]['column_id'],
                                     'index' => $i,
                                     'name' => $namedColumnList[$i]['name'] );
                }
                else
                {
                    $column = array( 'identifier' => 'col_' . ($i + 1),
                                     'index' => $i,
                                     'name' => 'Col_' . ($i + 1) );

                }

                $columnRows = array();
                for( $j = 0; $j < $numRows; $j++ )
                {
                    $columnRows[] = $sequentialRows[$j]['columns'][$i];
                }
                $column['rows'] = $columnRows;
                $sequentialColumns[] = $column;
                $idColumns[$column['identifier']] = $column;
            }
            $columns['sequential'] = $sequentialColumns;
            $columns['id'] = $idColumns;

            $matrix = array( 'rows' => $rows,
                             'columns' => $columns,
                             'cells' => $cellList );

            $this->Matrix = $matrix;
            $this->NumRows = $numRows;
            $this->NumColumns = $numColumns;
            $this->Cells = $cellList;
        }
        else
        {
            $this->Cells = array();
            $this->Matrix = array();
        }
    }
623053
static function xmlData($string, $cdata=false) {
        $string = str_replace("]]>", "]]]]><![CDATA[>", $string);
        if (!$cdata)
            $string = "<![CDATA[$string]]>";
        return $string;
    }