/*!
Will decode an xml string and initialize the eZ option object
764911
function decodeXML( $xmlString )
    {
        if ( $xmlString != "" )
        {
            $dom = new DOMDocument( '1.0', 'utf-8' );
            $success = $dom->loadXML( $xmlString );

            // set the name of the node
            $nameNode = $dom->getElementsByTagName( "name" )->item( 0 );
            $this->setName( $nameNode->textContent );

            $optionNodes = $dom->getElementsByTagName( "option" );
            $this->OptionCount = 0;

            foreach ( $optionNodes as $optionNode )
            {
                $this->addOption( array( 'value' => $optionNode->textContent,
                                         'additional_price' => $optionNode->getAttribute( 'additional_price' ) ) );
            }
        }
        else
        {
            $this->addOption( "" );
            $this->addOption( "" );
        }
    }
226922
function xmlString()
    {
        $doc = new DOMDocument( '1.0', 'utf-8' );
        $root = $doc->createElement( "ezmultioption2" );
        $doc->appendChild( $root );


        $this->createDomElementForGroup( $doc, $root );

        $rulesNode = $doc->createElement( "rules" );

        foreach ( $this->Rules as $ruleFor => $rule )
        {
            unset( $ruleNode );
            $ruleNode = $doc->createElement( "rule" );
            $ruleNode->setAttribute( "option_id", $ruleFor );
            foreach ( $rule as $multioptionID => $ruleData )
            {
                unset( $ruleDataNode );
                $ruleDataNode = $doc->createElement( "rule_data" );
                $ruleDataNode->setAttribute( "multioption_id", $multioptionID );
                foreach ( $ruleData as $optionID )
                {
                    unset( $includeNode );
                    $includeNode = $doc->createElement( "option_id", $optionID );
                    $ruleDataNode->appendChild( $includeNode );
                }
                $ruleNode->appendChild( $ruleDataNode );
            }
            $rulesNode->appendChild( $ruleNode );
        }
        $root->appendChild( $rulesNode );

        $xml = $doc->saveXML();
        return $xml;
    }
769626
function(str, opt_xml) {

      str = String(str);

      // This quick test helps in the case when there are no chars to replace,
      // in the worst case this makes barely a difference to the time taken.
      if (!goog.string.NEWLINE_TO_BR_RE_.test(str)) {
        return str;
      }

      return str.replace(/(\r\n|\r|\n)/g, opt_xml ? '<br />' : '<br>');
    }
1273839
function _strrep( $string ) {
    switch( $this->format ) {
      case 'xcal':
        $string = str_replace( '\n',  $this->nl, $string);
        $string = htmlspecialchars( strip_tags( stripslashes( urldecode ( $string ))));
        break;
      default:
        $pos = 0;
        while( $pos <= strlen( $string )) {
          $pos = strpos( $string, "\\", $pos );
          if( FALSE === $pos )
            break;
          if( !in_array( $string{($pos + 1)}, array( 'n', 'N', 'r', ',', ';' ))) {
            $string = substr( $string, 0, $pos )."\\".substr( $string, ( $pos + 1 ));
            $pos += 1;
          }
          $pos += 1;
        }
        if( FALSE !== strpos( $string, '"' ))
          $string = str_replace('"',   "'",       $string);
        if( FALSE !== strpos( $string, ',' ))
          $string = str_replace(',',   '\,',      $string);
        if( FALSE !== strpos( $string, ';' ))
          $string = str_replace(';',   '\;',      $string);
        if( FALSE !== strpos( $string, "\r\n" ))
          $string = str_replace( "\r\n", '\n',    $string);
        elseif( FALSE !== strpos( $string, "\r" ))
          $string = str_replace( "\r", '\n',      $string);
        if( FALSE !== strpos( $string, '\N' ))
          $string = str_replace( '\N', '\n',      $string);
//        if( FALSE !== strpos( $string, $this->nl ))
          $string = str_replace( $this->nl, '\n', $string);
        break;
    }
    return $string;
  }
260344
function to_xml_start(){
		if ($this->skip) return "";
		
		$str1="<item id='".$this->xmlentities($this->get_id())."' text='".$this->xmlentities($this->data[$this->config->text[0]["name"]])."' ";
		if ($this->has_kids()==true) $str1.="child='".$this->has_kids()."' ";
		if ($this->im0) $str1.="im0='".$this->im0."' ";
		if ($this->im1) $str1.="im1='".$this->im1."' ";
		if ($this->im2) $str1.="im2='".$this->im2."' ";
		if ($this->check) $str1.="checked='".$this->check."' ";
		foreach ($this->attrs as $key => $value)
			$str1.=$key."='".$this->xmlentities($value)."' ";
		$str1.=">";
		if ($this->userdata !== false)
			foreach ($this->userdata as $key => $value)
				$str1.="<userdata name='".$key."'><![CDATA[".$value."]]></userdata>";
			
		return $str1;
	}
232619
function unserializeContentObjectAttribute( $package, $objectAttribute, $attributeNode )
    {
        /* For all links found in the XML, do the following:
         * Search for url specified in 'href' link attribute (in ezurl table).
         * If the url not found then create a new one.
         * Then associate the found (or created) URL with the object attribute by creating new url-object link.
         * After that, remove "href" attribute, add new "id" attribute.
         * This new 'id' will always refer to the existing url object.
         */
        $linkNodes = $attributeNode->getElementsByTagName( 'link' );

        foreach ( $linkNodes as $linkNode )
        {
            $href = $linkNode->getAttribute( 'href' );
            if ( !$href )
                continue;
            $urlObj = eZURL::urlByURL( $href );

            if ( !$urlObj )
            {
                $urlObj = eZURL::create( $href );
                $urlObj->store();
            }

            $linkNode->removeAttribute( 'href' );
            $linkNode->setAttribute( 'url_id', $urlObj->attribute( 'id' ) );
            $urlObjectLink = eZURLObjectLink::create( $urlObj->attribute( 'id' ),
                                                      $objectAttribute->attribute( 'id' ),
                                                      $objectAttribute->attribute( 'version' ) );
            $urlObjectLink->store();
        }

        foreach ( $attributeNode->childNodes as $childNode )
        {
            if ( $childNode->nodeType == XML_ELEMENT_NODE )
            {
                $xmlString = $childNode->ownerDocument->saveXML( $childNode );
                $objectAttribute->setAttribute( 'data_text', $xmlString );
                break;
            }
        }
    }
1139193
function xmlString()
    {
        $doc = new DOMDocument( '1.0', 'utf-8' );
        $root = $doc->createElement( "ezmatrix" );
        $doc->appendChild( $root );

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

        $columnsNode = $doc->createElement( "columns" );

        $sequentalColumns = $this->Matrix['columns']['sequential'];
        $columnAmount = $this->NumColumns;
        $columnsNode->setAttribute( 'number', $columnAmount );
        $root->appendChild( $columnsNode );

        if ( $sequentalColumns != null )
        {
            for( $i = 0; $i < $columnAmount; $i++ )
            {
                $column = $sequentalColumns[$i];
                if ( $column != null && $column['identifier'] != 'col_' . ($i+1) )
                {
                    unset( $columnNode );
                    $columnNode = $doc->createElement( 'column' );
                    $columnNode->appendChild( $doc->createTextNode( $column['name'] ) );
                    $columnNode->setAttribute( 'num', $i );
                    $columnNode->setAttribute( 'id', $column['identifier'] );

                    $columnsNode->appendChild( $columnNode );
                }
            }

        }

        $rowsNode =  $doc->createElement( "rows" );
        $rowAmount = $this->NumRows;

        $rowsNode->setAttribute( 'number', $rowAmount );

        $root->appendChild( $rowsNode );

        foreach ( $this->Cells as $cell )
        {
            unset( $cellNode );
            $cellNode = $doc->createElement( 'c' );
            $cellNode->appendChild( $doc->createTextNode( $cell ) );

            $root->appendChild( $cellNode );
        }

        return $this->domString( $doc );
    }
1287014
static function rawXMLText( $contentObjectAttribute )
    {
        $text = $contentObjectAttribute->attribute( 'data_text' );
        $timestamp = $contentObjectAttribute->attribute( 'data_int' );
        if ( $timestamp < self::VERSION_30_TIMESTAMP )
        {
            $charset = 'UTF-8';
            $codec = eZTextCodec::instance( false, $charset );
            $text = $codec->convertString( $text );
            $timestamp = self::VERSION_30_TIMESTAMP;
        }
        return $text;
    }
904259
def xml_decode(string):
    
    string = string.replace("&amp;", "&")
    string = string.replace("&lt;",  "<")
    string = string.replace("&gt;",  ">")
    string = string.replace("&quot;","\"")
    string = string.replace("/", SLASH)
    return string
980089
function parseTag() {
    static $a_ord, $z_ord, $special_ords;
    if (!isset($a_ord)) {
      $a_ord = ord('a');
      $z_ord = ord('z');
      $special_ords = array(
        ord(':'), // for xml:lang
        ord('-'), // for http-equiv
      );
    }

    $tagName = '';

    $pos = 1;
    $isStartTag = $this->html[$pos] != '/';
    if (!$isStartTag) {
      $pos++;
    }
    # get tagName
    while (isset($this->html[$pos])) {
      $pos_ord = ord(strtolower($this->html[$pos]));
      if (($pos_ord >= $a_ord && $pos_ord <= $z_ord) || (!empty($tagName) && is_numeric($this->html[$pos]))) {
        $tagName .= $this->html[$pos];
        $pos++;
      } else {
        $pos--;
        break;
      }
    }

    $tagName = strtolower($tagName);
    if (empty($tagName) || !isset($this->blockElements[$tagName])) {
      # something went wrong => invalid tag
      $this->invalidTag();
      return false;
    }
    if ($this->noTagsInCode && end($this->openTags) == 'code' && !($tagName == 'code' && !$isStartTag)) {
      # we supress all HTML tags inside code tags
      $this->invalidTag();
      return false;
    }

    # get tag attributes
    /** TODO: in html 4 attributes do not need to be quoted **/
    $isEmptyTag = false;
    $attributes = array();
    $currAttrib = '';
    while (isset($this->html[$pos+1])) {
      $pos++;
      # close tag
      if ($this->html[$pos] == '>' || $this->html[$pos].$this->html[$pos+1] == '/>') {
        if ($this->html[$pos] == '/') {
          $isEmptyTag = true;
          $pos++;
        }
        break;
      }

      $pos_ord = ord(strtolower($this->html[$pos]));
      if ( ($pos_ord >= $a_ord && $pos_ord <= $z_ord) || in_array($pos_ord, $special_ords)) {
        # attribute name
        $currAttrib .= $this->html[$pos];
      } elseif (in_array($this->html[$pos], array(' ', "\t", "\n"))) {
        # drop whitespace
      } elseif (in_array($this->html[$pos].$this->html[$pos+1], array('="', "='"))) {
        # get attribute value
        $pos++;
        $await = $this->html[$pos]; # single or double quote
        $pos++;
        $value = '';
        while (isset($this->html[$pos]) && $this->html[$pos] != $await) {
          $value .= $this->html[$pos];
          $pos++;
        }
        $attributes[$currAttrib] = $value;
        $currAttrib = '';
      } else {
        $this->invalidTag();
        return false;
      }
    }
    if ($this->html[$pos] != '>') {
      $this->invalidTag();
      return false;
    }

    if (!empty($currAttrib)) {
      # html 4 allows something like <option selected> instead of <option selected="selected">
      $attributes[$currAttrib] = $currAttrib;
    }
    if (!$isStartTag) {
      if (!empty($attributes) || $tagName != end($this->openTags)) {
        # end tags must not contain any attributes
        # or maybe we did not expect a different tag to be closed
        $this->invalidTag();
        return false;
      }
      array_pop($this->openTags);
      if (in_array($tagName, $this->preformattedTags)) {
        $this->keepWhitespace--;
      }
    }
    $pos++;
    $this->node = substr($this->html, 0, $pos);
    $this->html = substr($this->html, $pos);
    $this->tagName = $tagName;
    $this->tagAttributes = $attributes;
    $this->isStartTag = $isStartTag;
    $this->isEmptyTag = $isEmptyTag || in_array($tagName, $this->emptyTags);
    if ($this->isEmptyTag) {
      # might be not well formed
      $this->node = preg_replace('# */? *>$#', ' />', $this->node);
    }
    $this->nodeType = 'tag';
    $this->isBlockElement = $this->blockElements[$tagName];
    return true;
  }
100082
static function processNodeTransformationRoot( $useComments, $php, $tpl, &$node, &$resourceData )
    {
        $nodeType = $node[0];
        if ( $nodeType == eZTemplate::NODE_ROOT )
        {
            $children = $node[1];
            $newNode = array( $nodeType,
                              false );
            if ( $children )
            {
                $newChildren = array();
                foreach ( $children as $childNode )
                {
                    $newChildNode = eZTemplateCompiler::processNodeTransformationChild( $useComments, $php, $tpl, $childNode, $resourceData );
                    if ( !$newChildNode )
                        $newChildren[] = $childNode;
                    else
                        $newChildren = array_merge( $newChildren, $newChildNode );
                }
                if ( count( $newChildren ) > 0 )
                    $newNode[1] = $newChildren;
            }
            return $newNode;
        }
        else
            $tpl->error( 'processNodeTransformation', "Unknown root type $nodeType, should be " . eZTemplate::NODE_ROOT );
        return false;
    }
440858
function serialize($charset_encoding='')
		{
			// add check? slower, but helps to avoid recursion in serializing broken xmlrpcvals...
			//if (is_object($o) && (get_class($o) == 'xmlrpcval' || is_subclass_of($o, 'xmlrpcval')))
			//{
				reset($this->me);
				list($typ, $val) = each($this->me);
				return '<value>' . $this->serializedata($typ, $val, $charset_encoding) . "</value>\n";
			//}
		}
121668
function decodeXML($xmlstg)
	{
		preg_match_all ("/<(.*?)>(.*?)\</", $xmlstg, $out, PREG_SET_ORDER);

		$n = 0;
		while (isset($out[$n]))
		{
			$retarr[$out[$n][1]] = strip_tags($out[$n][0]);
			$n++;
		}

		return $retarr;
	}
747476
function inputXML( )
    {
        $node = null;
        $dom = new DOMDocument( '1.0', 'utf-8' );
        $success = false;
        if ( $this->XMLData )
        {
            $success = $dom->loadXML( $this->XMLData );
        }

        eZDebugSetting::writeDebug( 'kernel-datatype-ezxmltext',
                                    $this->XMLData,
                                    __METHOD__ . ' xml string stored in database' );

        $output = '';
        $browserEngineName = self::browserSupportsDHTMLType();

        if ( $success )
        {
            $rootSectionNode = $dom->documentElement;
            $output .= $this->inputSectionXML( $rootSectionNode, 0 );
        }

        if ( $browserEngineName === 'Trident' )
        {
            $output = str_replace( '<p></p>', '<p>&nbsp;</p>', $output );
        }
        else /* if ( $browserEngineName !== 'Presto' ) */
        {
            $output = str_replace( '<p></p>', '<p><br /></p>', $output );
        }

        $output = str_replace( array( "\n", "\xC2\xA0" ), array( '', '&nbsp;' ), $output );

        if ( $output )
        {
            if ( $browserEngineName === 'Trident' )
            {
                $output .= '<p>&nbsp;</p>';
            }
            else
            {
                $output .= '<p><br /></p>';
            }
        }

        eZDebugSetting::writeDebug( 'kernel-datatype-ezxmltext',
                                    $output,
                                    __METHOD__ . ' xml output to return' );

        $output = htmlspecialchars( $output, ENT_COMPAT, 'UTF-8' );

        return $output;
    }
269100
static function objectToOO( $nodeID )
    {
        $node = eZContentObjectTreeNode::fetch( $nodeID );

        if ( !is_object( $node ) )
        {
            return false;
        }

        $ooGenerator = new eZOOGenerator();

        $object = $node->attribute( 'object' );
        $attributes = $object->contentObjectAttributes();

        $supportedDatatypes = array( 'ezstring', 'eztext', 'ezxmltext', 'ezimage', 'ezdate', 'ezdatetime', 'ezmatrix' );

        $odfINI = eZINI::instance( 'odf.ini' );
        $ClassMappingToHeader = ( $odfINI->variable( 'ODFExport', 'ClassAttributeMappingToHeader' ) == 'enabled' ) ? true : false;

        // @bf 2008-08-21: Fetch the current class identifier and the .ini settings for the enabled attributes for this
        $classIdentifier = $object->contentClassIdentifier();
        $enabledClassAttributes = $odfINI->hasVariable( $classIdentifier, 'Attribute' ) ? $odfINI->variable( $classIdentifier, 'Attribute' ) : array();

        foreach ( $attributes as $attribute )
        {
            $datatype = $attribute->attribute( 'data_type_string' );
            $identifier = $attribute->attribute( "contentclass_attribute_identifier" );

            if ( !in_array( $datatype, $supportedDatatypes ) )
            {
                eZDebug::writeError( "Attribute '$identifier' with unsupported datatype '$datatype' for OO conversion" );
                continue;
            }

            // @bf 2008-08-21: Only export attribute if it is enabled
            if ( !array_key_exists( $identifier, $enabledClassAttributes ) )
            {
                continue;
            }

            if( !$ClassMappingToHeader )
            {
                $ooGenerator->startSection( $identifier );
            }
            else
            {
                $ooGenerator->startClassMapHeader( $identifier );
            }

            switch ( $datatype )
            {
                case "ezstring":
                {
                    $text = trim( $attribute->content() );
                    if ( $text != "" )
                    {
                        $ooGenerator->addHeader( $text );
                    }
                } break;

                case "eztext":
                {
                    $ooGenerator->addParagraph( $attribute->content() );

                } break;

                case "ezxmltext":
                {
                    $xmlData = $attribute->attribute( 'data_text' );
                    $dom = new DOMDocument( '1.0', 'UTF-8' );
                    $dom->preserveWhiteSpace = false;
                    $success = $dom->loadXML( $xmlData );
                    if ( $success )
                    {
                        $root = $dom->documentElement;
                        foreach ( $root->childNodes as $node )
                        {
                            self::handleNode( $node, $ooGenerator );
                        }
                    }
                    else
                    {
                        eZDebug::writeError( "Unable to load XML data for attribute '$identifier'" );
                    }
                } break;

                case "ezimage":
                {
                    $originalImage = $attribute->content()->attribute( 'original' );

                    $fileHandler = eZClusterFileHandler::instance( $originalImage['url'] );
                    $uniqueFile = $fileHandler->fetchUnique();

                    $imageArray = array( "FileName" => $uniqueFile,
                                         "Alignment" => "center",
                                         "DisplayWidth" => $originalImage['width'],
                                         "DisplayHeight" => $originalImage['height'] );

                    $ooGenerator->addImage( $imageArray );
                } break;

                case "ezdate":
                {
                    $date = $attribute->content();
                    $ooGenerator->addParagraph( $date->attribute( "day" ) . "/" . $date->attribute( "month" ) . "/" . $date->attribute( "year" ) );
                } break;

                case "ezdatetime":
                {
                    $date = $attribute->content();
                    $ooGenerator->addParagraph( $date->attribute( "day" ) . "/" . $date->attribute( "month" ) . "/" . $date->attribute( "year" ) . " " . $date->attribute( "hour" )  . ":" . $date->attribute( "minute" )  );
                } break;

                case "ezmatrix":
                {
                    $matrix = $attribute->content();
                    $columns = $matrix->attribute( "columns" );

                    $ooGenerator->startTable();

                    foreach ( $columns['sequential'] as $column )
                    {
                        $ooGenerator->addParagraph( $column['name'] );
                        $ooGenerator->nextCell();
                    }

                    $ooGenerator->nextRow( "defaultstyle" );

                    $rows = $matrix->attribute( "rows" );

                    foreach ( $rows['sequential'] as $row )
                    {
                        foreach ( $row['columns'] as $cell )
                        {
                            $ooGenerator->addParagraph( $cell );
                            $ooGenerator->nextCell();
                        }
                        $ooGenerator->nextRow( "defaultstyle" );
                    }

                    $ooGenerator->endTable();
                } break;
            }

            if( !$ClassMappingToHeader )
            {
                $ooGenerator->endSection();
            }
        }

        return $ooGenerator->writeDocument();
    }
792826
public static function decode($xml)
	{
		$p = xml_parser_create();

		xml_parser_set_option($p, self::XML_OPTION_CASE_FOLDING, 0);
		xml_parser_set_option($p, self::XML_OPTION_SKIP_WHITE, 1);
		xml_parse_into_struct($p, $xml, $vals, $index);
		xml_parser_free($p);

		$count = count($vals);

		$stack = array();

		$obj = null;

		for ($i = 0; $i < $count; $i++)
		{
			$v = $vals[$i];

			if ($v['type'] == 'open')
			{
				if ($v['attributes']['type'] == 'object')
				{
					if (is_null($obj))
					{
						array_push($stack, array(null,$obj));
					}
					else if (is_array($obj) || is_object($obj))
					{
						array_push($stack, array($v['tag'],$obj));
					}
					else
					{
						if ($fatal)
						{
							die('invalid container');
						}
						else
						{
							return false;
						}
					}

					$obj = new \stdClass();
				}
				else if ($v['attributes']['type'] == 'array')
				{
					if (is_null($obj))
					{
						array_push($stack, array(null,$obj));
					}
					else if (is_array($obj) || is_object($obj))
					{
						array_push($stack, array($v['tag'],$obj));
					}
					else
					{
						die('invalid container');
					}

					$obj = array();
				}
				else
				{
					die('invalid element');
				}
			}
			else if ($v['type'] == 'complete')
			{
				if ($v['attributes']['type'] == 'string')
				{
					$value = $v['value'];
				}
				else if ($v['attributes']['type'] == 'boolean')
				{
					$value = $v['value'] == 'true';
				}
				else if ($v['attributes']['type'] == 'number')
				{
					$value = $v['value'];

					if (!is_numeric($value))
					{
						die('invalid numeric value');
					}

					$value = $value + 0; // converts to type int or float as required
				}
				else if ($v['attributes']['type'] == 'null')
				{
					$value = null;
				}
				else if ($v['attributes']['type'] == 'array')
				{
					$value = array();
				}
				else if ($v['attributes']['type'] == 'object')
				{
					$value = new \stdClass();
				}
				else
				{
					die('invalid value type');
				}

				if (is_null($obj))
				{
					$obj = $value;
				}
				else if (is_array($obj))
				{
					$obj[] = $value;
				}
				else if (is_object($obj))
				{
					if (isset($v['attributes']['item']))
					{
						$obj->{$v['attributes']['item']} = $value;
					}
					else
					{
						$obj->{$v['tag']} = $value;
					}
				}
				else
				{
					die('invalid container 2');
				}
			}
			else if ($v['type'] == 'close')
			{
				$prev = array_pop($stack);

				if (is_object($prev[1]))
				{
					$prev[1]->{$prev[0]} = $obj;
				}
				else if (is_array($prev[1]))
				{
					$prev[1][$prev[0]] = $obj;
				}
				else if (is_null($prev[1]))
				{
					break;
				}
				else
				{
					die('invalid container in stack');
				}

				$obj = $prev[1];
			}
			else
			{
				die('unknown parse part');
			}

		}

		self::last_error(self::XML_ERROR_NONE);

		return $obj;
	}
273295
function parse(str, options) {
  var doc = options.document || 'xml'
    , pretty = options.pretty || false
    , js = str;
  
  return ''
    + 'var ' + doc + ' = factory();\n'
    + (options.self
      ? 'var self = locals || {};\n' + js
      : 'with (locals || {}) {\n' + js + '\n}\n')
    + 'return ' + doc + '.toString({ pretty: ' + pretty + ' })';
}