Parse a Phrasea XML to find status tag

@param  \SimpleXMLElement $sxcaption The SimpleXML related to the XML
@return string
482984
protected function parseStatusBit($sxcaption)
    {
        if (!$sxcaption instanceof \SimpleXMLElement) {
            return null;
        }

        if ('' !== $inStatus = (string) $sxcaption->status) {
            return $inStatus;
        }

        return null;
    }
221910
function parse(\SimpleXMLElement $data)
  {
      $project = new DrupalProject();
      $project->setApiVersion((string) $data->api_version);
      $project->setTitle((string) $data->title);
      $project->setShortName((string) $data->short_name);
      $project->setRecommendedMajor((int) $data->recommended_major);
      $project->setProjectStatus((string) $data->project_status);
      $project->setLink((string) $data->link);
      $terms = array();
      foreach ($data->terms[0]->term as $term) {
          $terms[(string) $term->name] = (string) $term->value;
      }
      $project->setTerms($terms);

      $releases = array();
      $currentRelease = FALSE;
      foreach ($data->releases->release as $release) {
          $releaseArr = array(
              'version' => (string) $release->version,
              'major' => (string) $release->version_major,
              'patch' => (string) $release->version_patch,
              'extra' => (string) $release->version_extra,
              'status' => (string) $release->status,
          );
          $currentRelease = $this->compareRelease($releaseArr, $currentRelease);
          $releases[$releaseArr['version']] = $releaseArr;
      }
      $project->setReleases($releases);
      if ($currentRelease) {
        $project->setCurrentRelease($currentRelease);
      }
      return $project;
  }
1350615
public function getLastResponseXML()
    {
        $response = null;
        if (isset($this->_lastResponse)) {
            if (is_string($this->_lastResponse)) {
                $response = $this->_lastResponse;
            } else {
                $response = $this->_lastResponse->saveXML();
            }
        }
        
        return $response;
    }
219310
private function parseSimpleXMLMessage( SimpleXMLElement $message )
    {
        $status = ezcTranslationData::TRANSLATED;
        if ( $message->translation['type'] == 'unfinished' )
        {
            $status = ezcTranslationData::UNFINISHED;
        }
        else if ( $message->translation['type'] == 'obsolete' )
        {
            if ( $this->options->keepObsolete )
            {
                $status = ezcTranslationData::OBSOLETE;
            }
            else
            {
                return null;
            }
        }

        $source = trim( (string) $message->source );
        $translation = trim( (string) $message->translation );
        $comment = trim( (string) $message->comment );

        $source = strlen( $source ) ? $source : false;
        $translation = strlen( $translation ) ? $translation : false;
        $comment = strlen( $comment ) ? $comment : false;

        $location = $message->location;
        $file = $line = false;
        if ( $location )
        {
            $file = trim( (string) $location['filename'] );
            $line = trim( (string) $location['line'] );
        }

        return new ezcTranslationData( $source, $translation, $comment, $status, $file, $line );
    }
52138
public function parseXml($xmlString)
    {
        $sourceXml = new \SimpleXMLElement($xmlString);
        $sourceArray = (array) $sourceXml;

        if (array_key_exists(Resources::AUTHOR, $sourceArray)) {
            $this->author = $this->processAuthorNode($sourceArray);
        }

        if (array_key_exists(Resources::CATEGORY, $sourceArray)) {
            $this->category = $this->processCategoryNode($sourceArray);
        }

        if (array_key_exists(Resources::CONTRIBUTOR, $sourceArray)) {
            $this->contributor = $this->processContributorNode($sourceArray);
        }

        if (array_key_exists('generator', $sourceArray)) {
            $generator = new Generator();
            $generator->setText((string) $sourceArray['generator']->asXML());
            $this->generator = $generator;
        }

        if (array_key_exists('icon', $sourceArray)) {
            $this->icon = (string) $sourceArray['icon'];
        }

        if (array_key_exists('id', $sourceArray)) {
            $this->id = (string) $sourceArray['id'];
        }

        if (array_key_exists(Resources::LINK, $sourceArray)) {
            $this->link = $this->processLinkNode($sourceArray);
        }

        if (array_key_exists('logo', $sourceArray)) {
            $this->logo = (string) $sourceArray['logo'];
        }

        if (array_key_exists('rights', $sourceArray)) {
            $this->rights = (string) $sourceArray['rights'];
        }

        if (array_key_exists('subtitle', $sourceArray)) {
            $this->subtitle = (string) $sourceArray['subtitle'];
        }

        if (array_key_exists('title', $sourceArray)) {
            $this->title = (string) $sourceArray['title'];
        }

        if (array_key_exists('updated', $sourceArray)) {
            $this->updated = \DateTime::createFromFormat(
                \DateTime::ATOM,
                (string) $sourceArray['updated']
            );
        }
    }
1123779
protected function getLocalizedTagContent(\SimpleXMLElement $element, $locale = null)
    {
        if (0 === $element->count()) {
            return '';
        }

        if (null === $locale) {
            return $this->multilineRemoveIndent((string)$element, 'true' === (string)$element->attributes()['removeIndent']);
        }

        foreach ($element as $node) {
            if ($locale == (string)$node->attributes()['locale']) {
                return $this->multilineRemoveIndent((string)$node, 'true' === (string)$node->attributes()['removeIndent']);
            }
        }

        $message = sprintf('Locale "%s" not available in node "%s".', $locale, $element->getName());
        throw new \Exception($message);
    }
1344012
function parseXML($source) {
             
            // Clear any content that this object might have
            // Call: $this->removeNode()
             
            // Get xml declration from document and set in object
            if (preg_match("/<?xml\ (.*?)\?>/i", $source, $matches)) {
                $this->xmlDecl = "<?xml ".$matches[1]."?>";
                 
                // Get version
                if (preg_match("/version=\"(.*?)\"/i", $matches[1], $versionInfo)) {
                    $this->version = $versionInfo[1];
                }
                 
                // Get encoding
                if (preg_match("/encoding=\"(.*?)\"/i", $matches[1], $encodingInfo)) {
                    $this->encoding = $encodingInfo[1];
                }
                 
            }
             
            // Get document type decleration from document and set in object
            if (preg_match("/<!doctype\ (.*?)>/i", $source, $matches)) {
                $this->docTypeDecl = "<!DOCTYPE ".$matches[1].">";
            }
             
            // Strip white space between tags - not _in_ tags
            $source = preg_replace("/>\s+</i", "><", $source);

            $params = array();
            $level = array();

            // Parse the xml document to an array structure
            $parser = xml_parser_create($this->encoding);
            xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
            if(xml_parse_into_struct($parser, $source, $vals, $index) == 0)
            {
                $this->error = "XML Parser error : ".xml_error_string(xml_get_error_code($parser));
                return $params;
            }
            xml_parser_free($parser);

            $isExist = false;
            $counterOfNodes = 0;
            $lastNode = null;
            $lastNodeArray = null;
                        
            foreach ($vals as $xml_elem) {
                if ($xml_elem['type'] == 'open') {
                    if (array_key_exists('attributes', $xml_elem)) {
                        list($level[$xml_elem['level']], $extra) = array_values($xml_elem['attributes']);
                    } 
                    else {
                        
                        if ($lastNode != null && $lastNode['tag'] != $xml_elem['tag']) {
                            $counterOfNodes = 0; 
                        }
                                                
                        if (array_key_exists($xml_elem['level'], $level) && $level[$xml_elem['level']] == $xml_elem['tag']) {   
                            $isExist = true;
                            $counterOfNodes++;
                        }
                        
                        $level[$xml_elem['level']] = $xml_elem['tag']; 
                    }
                }
                else if ($xml_elem['type'] == 'complete') {
                    $start_level = 1;
                    $php_stmt = '$params';
                    while ($start_level < $xml_elem['level']) {
                        $php_stmt .= '[$level['.$start_level.']]';
                        $start_level++;
                    }
                    if($isExist) {
                        if($counterOfNodes == 1) {
                            $php_stmt_2 = $php_stmt;
                            $php_stmt_2 = 'unset('.$php_stmt_2.');';
                            eval($php_stmt_2); 
                        
                            $php_stmt_2 = $php_stmt;
                            $php_stmt_2 .= '[\'arraysize\'] = 1;';
                            eval($php_stmt_2); 
                            
                            $php_stmt_2 = $php_stmt;
                            $php_stmt_2 .= '[1]=$lastNodeArray;';
                            $counterOfNodes++;
                            eval($php_stmt_2);
                        }
                        $php_stmt_2 = $php_stmt;
                        $php_stmt_2 .= '[\'arraysize\'] = $counterOfNodes;';
                        eval($php_stmt_2); 
                        
                        $php_stmt .= '[$counterOfNodes]';
                    }
                    if(array_key_exists("value", $xml_elem)) {
                        $php_stmt .= '[$xml_elem[\'tag\']] = $xml_elem[\'value\'];';
                    }
                    else {
                        $php_stmt .= '[$xml_elem[\'tag\']] = "";';
                    }
                    eval($php_stmt);
                }
                else if ($xml_elem['type'] == 'close') {    
                    $lastNode = $xml_elem;
                    $isExist = false;
                    $start_level = 1;
                    $php_stmt = '$lastNodeArray=$params';
                    while ($start_level <= $xml_elem['level']) {
                        $php_stmt .= '[$level['.$start_level.']]';
                        $start_level++;
                    }
                    $php_stmt .= ';'; 
                    eval($php_stmt);
                }
            }
            return $params;
             
            // parse the structure and create this object...
            /*
             if (!empty($vals)) {
             $root = XMLNode::createElement($vals[0]['tag']);
             $root->attributes = isset($vals[0]['attributes'])?$vals[0]['attributes']:null;
             $root->childNodes = $root->_xml_get_children($vals, $i = 0);
             $this->appendChild($root);
             }
             */
        }
813909
protected function getTitle()
	{
		$title = '';

		if ($this->hidden)
		{
			return $title;
		}

		// Get the label text from the XML element, defaulting to the element name.
		$title = $this->element['label'] ? (string) $this->element['label'] : (string) $this->element['name'];
		$title = $this->translateLabel ? $this->getText()->translate($title) : $title;

		return $title;
	}
64252
public function parse(
        string $xml,
        string $className = null,
        int $options = null,
        string $ns = null,
        bool $isPrefix = null
    ): \SimpleXMLElement {
        list($content, $error) = $this->softParse($xml, $className, $options, $ns, $isPrefix);
        if ($error !== null) {
            throw $error;
        }
        return $content;
    }
357346
protected function parseXML($xml) {
        if (!$xml){
            return false;
        }
        if (!$xml->FulfillmentOrder){
            return false;
        }
        if (!$xml->FulfillmentOrderItem){
            return false;
        }
        if (!$xml->FulfillmentShipment){
            return false;
        }
        //Section 1: ShipmentOrder
        $d = $xml->FulfillmentOrder;
        $this->order['Details']['SellerFulfillmentOrderId'] = (string)$d->SellerFulfillmentOrderId;
        $this->order['Details']['MarketplaceId'] = (string)$d->MarketplaceId;
        $this->order['Details']['DisplayableOrderId'] = (string)$d->DisplayableOrderId;
        $this->order['Details']['DisplayableOrderDateTime'] = (string)$d->DisplayableOrderDateTime;
        $this->order['Details']['DisplayableOrderComment'] = (string)$d->DisplayableOrderComment;
        $this->order['Details']['ShippingSpeedCategory'] = (string)$d->ShippingSpeedCategory;
        if (isset($d->DeliveryWindow)) {
            $this->order['Details']['DeliveryWindow']['StartDateTime'] = (string)$d->DeliveryWindow->StartDateTime;
            $this->order['Details']['DeliveryWindow']['EndDateTime'] = (string)$d->DeliveryWindow->EndDateTime;
        }
        $this->order['Details']['DestinationAddress'] = $this->parseAddress($d->DestinationAddress);
        if (isset($d->FulfillmentAction)){
            $this->order['Details']['FulfillmentAction'] = (string)$d->FulfillmentAction;
        }
        if (isset($d->FulfillmentPolicy)){
            $this->order['Details']['FulfillmentPolicy'] = (string)$d->FulfillmentPolicy;
        }
        if (isset($d->FulfillmentMethod)){
            //deprecated
            $this->order['Details']['FulfillmentMethod'] = (string)$d->FulfillmentMethod;
        }
        $this->order['Details']['ReceivedDateTime'] = (string)$d->ReceivedDateTime;
        $this->order['Details']['FulfillmentOrderStatus'] = (string)$d->FulfillmentOrderStatus;
        $this->order['Details']['StatusUpdatedDateTime'] = (string)$d->StatusUpdatedDateTime;
        if (isset($d->NotificationEmailList)){
            $i = 0;
            foreach($d->NotificationEmailList->children() as $x){
                $this->order['Details']['NotificationEmailList'][$i++] = (string)$x;
            }
        }
        if (isset($d->CODSettings->IsCODRequired)){
            $this->order['Details']['CODSettings']['IsCODRequired'] = (string)$d->CODSettings->IsCODRequired;
        }
        if (isset($d->CODSettings->CODCharge)){
            $this->order['Details']['CODSettings']['CODCharge']['CurrencyCode'] = (string)$d->CODSettings->CODCharge->CurrencyCode;
            $this->order['Details']['CODSettings']['CODCharge']['Value'] = (string)$d->CODSettings->CODCharge->Value;
        }
        if (isset($d->CODSettings->CODChargeTax)){
            $this->order['Details']['CODSettings']['CODChargeTax']['CurrencyCode'] = (string)$d->CODSettings->CODChargeTax->CurrencyCode;
            $this->order['Details']['CODSettings']['CODChargeTax']['Value'] = (string)$d->CODSettings->CODChargeTax->Value;
        }
        if (isset($d->CODSettings->ShippingCharge)){
            $this->order['Details']['CODSettings']['ShippingCharge']['CurrencyCode'] = (string)$d->CODSettings->ShippingCharge->CurrencyCode;
            $this->order['Details']['CODSettings']['ShippingCharge']['Value'] = (string)$d->CODSettings->ShippingCharge->Value;
        }
        if (isset($d->CODSettings->ShippingChargeTax)){
            $this->order['Details']['CODSettings']['ShippingChargeTax']['CurrencyCode'] = (string)$d->CODSettings->ShippingChargeTax->CurrencyCode;
            $this->order['Details']['CODSettings']['ShippingChargeTax']['Value'] = (string)$d->CODSettings->ShippingChargeTax->Value;
        }
        
        //Section 2: Order Items
        $i = 0;
        foreach($xml->FulfillmentOrderItem->children() as $x){
            $this->order['Items'][$i]['SellerSKU'] = (string)$x->SellerSKU;
            $this->order['Items'][$i]['SellerFulfillmentOrderItemId'] = (string)$x->SellerFulfillmentOrderItemId;
            $this->order['Items'][$i]['Quantity'] = (string)$x->Quantity;
            if (isset($x->GiftMessage)){
                $this->order['Items'][$i]['GiftMessage'] = (string)$x->GiftMessage;
            }
            if (isset($x->DisplayableComment)){
                $this->order['Items'][$i]['DisplayableComment'] = (string)$x->DisplayableComment;
            }
            if (isset($x->FulfillmentNetworkSKU)){
                $this->order['Items'][$i]['FulfillmentNetworkSKU'] = (string)$x->FulfillmentNetworkSKU;
            }
            if (isset($x->OrderItemDisposition)){
                $this->order['Items'][$i]['OrderItemDisposition'] = (string)$x->OrderItemDisposition;
            }
            $this->order['Items'][$i]['CancelledQuantity'] = (string)$x->CancelledQuantity;
            $this->order['Items'][$i]['UnfulfillableQuantity'] = (string)$x->UnfulfillableQuantity;
            if (isset($x->EstimatedShipDateTime)){
                $this->order['Items'][$i]['EstimatedShipDateTime'] = (string)$x->EstimatedShipDateTime;
            }
            if (isset($x->EstimatedArrivalDateTime)){
                $this->order['Items'][$i]['EstimatedArrivalDateTime'] = (string)$x->EstimatedArrivalDateTime;
            }
            if (isset($x->PerUnitDeclaredValue)){
                $this->order['Items'][$i]['PerUnitDeclaredValue']['CurrencyCode'] = (string)$x->PerUnitDeclaredValue->CurrencyCode;
                $this->order['Items'][$i]['PerUnitDeclaredValue']['Value'] = (string)$x->PerUnitDeclaredValue->Value;
            }
            if (isset($x->PerUnitPrice)){
                $this->order['Items'][$i]['PerUnitPrice']['CurrencyCode'] = (string)$x->PerUnitPrice->CurrencyCode;
                $this->order['Items'][$i]['PerUnitPrice']['Value'] = (string)$x->PerUnitPrice->Value;
            }
            if (isset($x->PerUnitTax)){
                $this->order['Items'][$i]['PerUnitTax']['CurrencyCode'] = (string)$x->PerUnitTax->CurrencyCode;
                $this->order['Items'][$i]['PerUnitTax']['Value'] = (string)$x->PerUnitTax->Value;
            }
            $i++;
        }
        
        //Section 3: Order Shipments
        $i = 0;
        foreach($xml->FulfillmentShipment->children() as $x){
            $this->order['Shipments'][$i]['AmazonShipmentId'] = (string)$x->AmazonShipmentId;
            $this->order['Shipments'][$i]['FulfillmentCenterId'] = (string)$x->FulfillmentCenterId;
            $this->order['Shipments'][$i]['FulfillmentShipmentStatus'] = (string)$x->FulfillmentShipmentStatus;
            if (isset($x->ShippingDateTime)){
                $this->order['Shipments'][$i]['ShippingDateTime'] = (string)$x->ShippingDateTime;
            }
            if (isset($x->EstimatedArrivalDateTime)){
                $this->order['Shipments'][$i]['EstimatedArrivalDateTime'] = (string)$x->EstimatedArrivalDateTime;
            }
            //FulfillmentShipmentItem
            $j = 0;
            foreach ($x->FulfillmentShipmentItem->children() as $y){
                if (isset($y->SellerSKU)){
                    $this->order['Shipments'][$i]['FulfillmentShipmentItem'][$j]['SellerSKU'] = (string)$y->SellerSKU;
                }
                $this->order['Shipments'][$i]['FulfillmentShipmentItem'][$j]['SellerFulfillmentOrderItemId'] = (string)$y->SellerFulfillmentOrderItemId;
                $this->order['Shipments'][$i]['FulfillmentShipmentItem'][$j]['Quantity'] = (string)$y->Quantity;
                if (isset($y->PackageNumber)){
                    $this->order['Shipments'][$i]['FulfillmentShipmentItem'][$j]['PackageNumber'] = (string)$y->PackageNumber;
                }
                $j++;
            }
            if (isset($x->FulfillmentShipmentPackage)){
                $j = 0;
                foreach ($x->FulfillmentShipmentPackage->children() as $y){
                    $this->order['Shipments'][$i]['FulfillmentShipmentPackage'][$j]['PackageNumber'] = (string)$y->PackageNumber;
                    $this->order['Shipments'][$i]['FulfillmentShipmentPackage'][$j]['CarrierCode'] = (string)$y->CarrierCode;
                    if (isset($y->TrackingNumber)){
                        $this->order['Shipments'][$i]['FulfillmentShipmentPackage'][$j]['TrackingNumber'] = (string)$y->TrackingNumber;
                    }
                    if (isset($y->EstimatedArrivalDateTime)){
                        $this->order['Shipments'][$i]['FulfillmentShipmentPackage'][$j]['EstimatedArrivalDateTime'] = (string)$y->EstimatedArrivalDateTime;
                    }
                    $j++;
                }
            }
            
            $i++;
        }

        //Section 4: Return Items
        if (isset($xml->ReturnItemList)) {
            foreach ($xml->ReturnItemList->children() as $x) {
                $temp = array();
                $temp['SellerReturnItemId'] = (string)$x->SellerReturnItemId;
                $temp['SellerFulfillmentOrderItemId'] = (string)$x->SellerFulfillmentOrderItemId;
                $temp['AmazonShipmentId'] = (string)$x->AmazonShipmentId;
                $temp['SellerReturnReasonCode'] = (string)$x->SellerReturnReasonCode;
                if (isset($x->ReturnComment)) {
                    $temp['ReturnComment'] = (string)$x->ReturnComment;
                }
                if (isset($x->AmazonReturnReasonCode)) {
                    $temp['AmazonReturnReasonCode'] = (string)$x->AmazonReturnReasonCode;
                }
                $temp['Status'] = (string)$x->Status;
                $temp['StatusChangedDate'] = (string)$x->StatusChangedDate;
                if (isset($x->ReturnAuthorizationId)) {
                    $temp['ReturnAuthorizationId'] = (string)$x->ReturnAuthorizationId;
                }
                if (isset($x->ReturnReceivedCondition)) {
                    $temp['ReturnReceivedCondition'] = (string)$x->ReturnReceivedCondition;
                }
                if (isset($x->FulfillmentCenterId)) {
                    $temp['FulfillmentCenterId'] = (string)$x->FulfillmentCenterId;
                }
                $this->order['ReturnItems'][] = $temp;
            }
        }

        //Section 5: Return Authorizations
        if (isset($xml->ReturnAuthorizationList)) {
            foreach ($xml->ReturnAuthorizationList->children() as $x) {
                $temp = array();
                $temp['ReturnAuthorizationId'] = (string)$x->ReturnAuthorizationId;
                $temp['FulfillmentCenterId'] = (string)$x->FulfillmentCenterId;
                $temp['ReturnToAddress'] = $this->parseAddress($x->ReturnToAddress);
                $temp['AmazonRmaId'] = (string)$x->AmazonRmaId;
                $temp['RmaPageURL'] = (string)$x->RmaPageURL;
                $this->order['ReturnAuthorizations'][] = $temp;
            }
        }
    }
1213329
private function parseXML($xml) {
		$simpleXml = simplexml_load_string($xml, null, LIBXML_NOCDATA);
		$json = json_encode($simpleXml);

		return json_decode($json, true);
	}
614122
private function getNextTag(&$s, $i, &$position)
    {
        $j = mb_strpos($s, '[', $i);
        $k = mb_strpos($s, ']', $j + 1);

        if ($j === false || $k === false) {
            $position = false;
            return null;
        }

        $t = mb_substr($s, $j + 1, $k - ($j + 1));
        $l = mb_strrpos($t, '[');

        if ($l !== false) {
            $j += $l + 1;
        }

        $position = $j;

        $tagString = mb_substr($s, $j, $k - $j + 1);

        return new Tag($tagString, $this->getHandlers());
    }
308076
protected function xmlElementToClassname(SimpleXMLElement $xmlElement)
    {
        $xpath = $xmlElement->getName();
        $parent = $xmlElement;
        while ($parent = current($parent->xpath('parent::*'))) {
            $xpath = $parent->getName() . '/' . $xpath;
        }

        foreach ($this->objectMapper as $key => $classname) {
            if (false !== strpos($xpath, $key) && $this->strEndsWith($xpath, $key)) {
                return $classname;
            }
        }
        return null;
    }
752337
public static function parse($xml, $section = null)
  {
    $parser = new XMLParser($xml);
    if (is_string($section) && !empty($section)) {
      return $parser->getXml()->get($section, true);
    }
    return $parser->getXml();
  }
1349990
public static function parseExpressionXml(SimpleXMLElement $xml){
        $returnValue = self::parseElementXml($xml);
        $value = trim($xml);
        $expressions = array();
        foreach($xml->children() as $child){
            $expressions[] = self::parseExpressionXml($child);
        }
        if(count($expressions)){
            $returnValue['expressions'] = $expressions;
        }
        if(strlen($value)){
            $returnValue['value'] = $value;
        }
        return $returnValue;
    }
895811
public function getStatus()
    {
        /** @var $result CallResult */
        $result = $this->getSvn()->{'status'}($this->getRepositoryPath(), array(
            '--xml'
        ));
        $result->assertSuccess(
            sprintf('Cannot retrieve status from "%s"', $this->getRepositoryPath())
        );

        $xml    = simplexml_load_string($result->getStdOut());
        if (!$xml) {
            throw new \RuntimeException(sprintf('Cannot read status XML for "%s"', $this->getRepositoryPath()));
        }

        $status = array();
        foreach ($xml->xpath('/status/target/entry') as $entry) {
            $status[]   = array(
                'file'      => (string)$entry['path'],
                'status'    => (string)$entry->{'wc-status'}['item']
            );
        }
        return $status;
    }
724582
private function formatString($s)
    {
        static $last_tag = null;

        if ($this->m_stack->count() > 0
            && $this->m_stack->top()->isOfType(self::TAG_PRE)
        ) {
            // Do not format text inside of TAG_PRE tags

            return $s;
        }

        /*
         * TODO Replace double-quotes alternately with nice left and right
         * quotes
         */

        if ($last_tag !== null) {
            #echo $last_tag->getName();
        }

        #echo '|' . $s . '|';

        // opening quote
        if ($last_tag !== null && $last_tag->isOfType(self::TAG_INLINE)) {
            $s = preg_replace('/([\s])&quot;/', '\1&raquo;', $s);

            #echo 'without';
        } else {
            $s = preg_replace('/([\s]|^)&quot;/', '\1&raquo;', $s);
        }

        // [X][X] will always be rendered as [S][S], not as [S][E]
        $s = preg_replace('/(&raquo;)&quot;/', '\1&raquo;', $s);

        #echo '<br />';

        // everything else is closing quote
        $s = str_replace('&quot;', '&laquo;', $s);

        $s = str_replace('--', '&ndash;', $s);

        if ($this->m_stack->count() > 0) {
            $last_tag = $this->m_stack->top();
        } else {
            $last_tag = null;
        }

        $e = function ($s) { return htmlspecialchars($s, ENT_QUOTES, 'UTF-8'); };

        return $e($s);
    }