Serialize the boolean value as an xml element with the given node name.

@param  string
@param  mixed
@return string
508235
protected function _serializeBooleanNode($nodeName, $value)
	{
		if(!$this->_helper->convertStringToBoolean($value))
		{
			return sprintf('<%s>0</%1$s>', $nodeName);
		} else {
			return sprintf('<%s>%s</%1$s>', $nodeName, $this->_helper->convertStringToBoolean($value));
		}
	}
1363763
private function _XMLFault2String($xml)
    {
        $dom = new DOMDocument();
        $dom->loadXML($xml);
        return $dom->getElementsByTagName('faultstring')->item(0)->nodeValue;
    }
1033898
private static function convert($nodeName, $data)
    {
        //print_arr($nodeName);
        $xml = self::getXMLRoot();
        $node = $xml->createElement($nodeName);

        if (is_array($data)) {
            // get the attributes first.;
            if (array_key_exists(self::$prefixAttributes . 'attributes', $data)) {
                foreach ($data[self::$prefixAttributes . 'attributes'] as $key => $value) {
                    self::validateTagName($key, $nodeName, 'attribute');
                    $node->setAttribute($key, self::bool2str($value));
                }
                unset($data[self::$prefixAttributes . 'attributes']); //remove the key from the array once done.
            }

            // check if it has a value stored in @value, if yes store the value and return
            // else check if its directly stored as string
            if (array_key_exists(self::$prefixAttributes . 'value', $data)) {
                $node->appendChild($xml->createTextNode(self::bool2str($data[self::$prefixAttributes . 'value'])));
                unset($data[self::$prefixAttributes . 'value']);    //remove the key from the array once done.
                //return from recursion, as a note with value cannot have child nodes.
                return $node;
            } else {
                if (array_key_exists(self::$prefixAttributes . 'cdata', $data)) {
                    $node->appendChild($xml->createCDATASection(self::bool2str($data[self::$prefixAttributes . 'cdata'])));
                    unset($data[self::$prefixAttributes . 'cdata']);    //remove the key from the array once done.
                    //return from recursion, as a note with cdata cannot have child nodes.
                    return $node;
                }
            }
        }

        //create sub-nodes using recursion
        if (is_array($data)) {
            // recurse to get the node for that key
            foreach ($data as $key => $value) {
                self::validateTagName($key, $nodeName, 'tag');

                if (is_array($value) && reset($value) && is_numeric(key($value))) {
                    // MORE THAN ONE NODE OF ITS KIND;
                    // if the new array is numeric index, means it is array of nodes of the same kind
                    // it should follow the parent key name
                    foreach ($value as $k => $v) {
                        $node->appendChild(self::convert($key, $v));
                    }
                } else {
                    // ONLY ONE NODE OF ITS KIND
                    $node->appendChild(self::convert($key, $value));
                }
                unset($data[$key]); //remove the key from the array once done.
            }
        }

        // after we are done with all the keys in the array (if it is one)
        // we check if it has any text value, if yes, append it.
        if (!is_array($data)) {
            $node->appendChild($xml->createTextNode(self::bool2str($data)));
        }

        return $node;
    }
1239061
private function serializeDataToXml($data)
    {
        if ($data instanceof \SimpleXMLElement) {
            return $data->asXML();
        }
        
        if (($data instanceof \DOMNode && isset($data->ownerDocument)) || $data instanceof \DOMDocument) {
            $dom = $data instanceof \DOMDocument ? $data : $data->ownerDocument;
            return $dom->saveXML($data);
        }
        
        $type = (is_object($data) ? get_class($data) . ' ' : '') . gettype($data);
        throw new \UnexpectedValueException("Unable to serialize $type to XML");
    }
1043168
public static function getFormatedXml($_string,$_asDomDocument = false)
    {
        if(!empty($_string) && class_exists('DOMDocument'))
        {
            $dom = new DOMDocument('1.0','UTF-8');
            $dom->formatOutput = true;
            $dom->preserveWhiteSpace = false;
            $dom->resolveExternals = false;
            $dom->substituteEntities = false;
            $dom->validateOnParse = false;
            if($dom->loadXML($_string))
                return $_asDomDocument?$dom:$dom->saveXML();
        }
        return $_asDomDocument?null:$_string;
    }
350336
public static function xmlToObject($xml_string)
    {
        if (empty($xml_string)) {
            return null;
        }

        libxml_use_internal_errors(true);
        try {
            if (false === $xml = simplexml_load_string($xml_string)) {
                throw new \Exception("Invalid XML Data: ");
            }
            // check for namespace
            $namespaces = $xml->getNamespaces();
            if (0 === $xml->count() && !empty($namespaces)) {
                $perNamespace = [];
                foreach ($namespaces as $prefix => $uri) {
                    if (false === $nsXml = simplexml_load_string($xml_string, null, 0, $prefix, true)) {
                        throw new \Exception("Invalid XML Namespace ($prefix) Data: ");
                    }
                    $perNamespace[$prefix] = $nsXml;
                }
                if (1 === count($perNamespace)) {
                    return current($perNamespace);
                }

                return $perNamespace;
            }

            return $xml;
        } catch (\Exception $ex) {
            $xmlstr = explode("\n", $xml_string);
            $errstr = "[INVALIDREQUEST]: Invalid XML Data: ";
            foreach (libxml_get_errors() as $error) {
                $errstr .= static::displayXmlError($error, $xmlstr) . "\n";
            }
            libxml_clear_errors();
            throw new \Exception($errstr);
        }
    }
480615
public static function create($boolean = FALSE) {
    $is_upper = FormatterFactory::getDefaultFormatter()->getConfig('boolean_null_upper');
    $node = new FalseNode();
    $node->addChild(NameNode::create($is_upper ? 'FALSE' : 'false'), 'constantName');
    return $node;
  }
897107
public function parse_xml( $data = null ) {

		if ( ! empty( $data ) ) {
			$this->input = $data;
		}

		$xml = new SimpleXMLElement( $this->input );

		if ( ! isset( $xml->items ) ) {
			return false;
		}

		$data = array(
			'columns' => array(),
			'items'   => array(),
		);

		/**
		 * @var $child      SimpleXMLElement
		 * @var $item_child SimpleXMLElement
		 * @var $data_child SimpleXMLElement
		 */

		if ( isset( $xml->columns ) ) {
			foreach ( $xml->columns->children() as $child ) {
				$sub = $child->getName();

				if ( empty( $sub ) || 'column' !== $sub ) {
					continue;
				}

				if ( isset( $child->name ) ) {
					if ( is_array( $child->name ) ) {
						$column = $child->name[0];
					} else {
						$column = $child->name;
					}

					$data['columns'][] = $column;
				}
			}
		}

		foreach ( $xml->items->children() as $child ) {
			$sub = $child->getName();

			if ( empty( $sub ) || 'item' !== $sub ) {
				continue;
			}

			$item = array();

			$attributes = $child->attributes();

			if ( ! empty( $attributes ) ) {
				foreach ( $attributes as $column => $value ) {
					if ( ! in_array( $column, $data['columns'], true ) ) {
						$data['columns'][] = $column;
					}

					$item[ $column ] = $value;
				}
			}

			$item_child = $child->children();

			if ( ! empty( $item_child ) ) {
				foreach ( $item_child->children() as $data_child ) {
					$column = $data_child->getName();

					if ( ! in_array( $column, $data['columns'], true ) ) {
						$data['columns'][] = $column;
					}

					$item[ $column ] = $item_child->$column;
				}
			}

			if ( ! empty( $item ) ) {
				$data['items'][] = $item;
			}
		}//end foreach

		$this->parsed = $data;

		return $this->parsed;
	}
1023403
static function encodeValue( $doc, $name, $value )
    {
        switch ( gettype( $value ) )
        {
            case "string" :
            {
                $node = $doc->createElement( $name );
                $node->appendChild( $doc->createTextNode( $value ) );
                $node->setAttribute( eZSOAPEnvelope::XSI_PREFIX . ':type',
                                     eZSOAPEnvelope::XSD_PREFIX . ':string' );
                return $node;
            } break;

            case "boolean" :
            {
                $node = $doc->createElement( $name );
                $node->appendChild( $doc->createTextNode( $value ? 'true' : 'false' ) );
                $node->setAttribute( eZSOAPEnvelope::XSI_PREFIX . ':type',
                                     eZSOAPEnvelope::XSD_PREFIX . ':boolean' );
                return $node;
            } break;

            case "integer" :
            {
                $node = $doc->createElement( $name );
                $node->appendChild( $doc->createTextNode( $value ) );
                $node->setAttribute( eZSOAPEnvelope::XSI_PREFIX . ':type',
                                     eZSOAPEnvelope::XSD_PREFIX . ':int' );
                return $node;
            } break;

            case "double" :
            {
                $node = $doc->createElement( $name );
                $node->appendChild( $doc->createTextNode( $value ) );
                $node->setAttribute( eZSOAPEnvelope::XSI_PREFIX . ':type',
                                     eZSOAPEnvelope::XSD_PREFIX . ':float' );
                return $node;
            } break;

            case "array" :
            {
                $arrayCount = count( $value );

                $isStruct = false;
                // Check for struct
                $i = 0;
                foreach( $value as $key => $val )
                {
                    if ( $i !== $key )
                    {
                        $isStruct = true;
                        break;
                    }
                    $i++;
                }

                if ( $isStruct == true )
                {
                    $node = $doc->createElement( $name );
                    $node->setAttribute( eZSOAPEnvelope::XSI_PREFIX . ':type',
                                         eZSOAPEnvelope::ENC_PREFIX . ':SOAPStruct' );

                    foreach( $value as $key => $val )
                    {
                        $subNode = eZSOAPCodec::encodeValue( $doc, (string)$key, $val );
                        $node->appendChild( $subNode );
                    }
                    return $node;
                }
                else
                {
                    $node = $doc->createElement( $name );
                    $node->setAttribute( eZSOAPEnvelope::XSI_PREFIX . ':type',
                                         eZSOAPEnvelope::ENC_PREFIX . ':Array' );
                    $node->setAttribute( eZSOAPEnvelope::ENC_PREFIX . ':arrayType',
                                         eZSOAPEnvelope::XSD_PREFIX . ":string[$arrayCount]" );

                    foreach ( $value as $arrayItem )
                    {
                        $subNode = eZSOAPCodec::encodeValue( $doc, "item", $arrayItem );
                        $node->appendChild( $subNode );
                    }

                    return  $node;
                }
            } break;
        }

        return false;
    }
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;
    }
1251295
private static function convert(XMLElement $root = null, DOMNode $node)
    {
        $el = new XMLElement($node->tagName);

        self::convertNode($el, $node);

        if (is_null($root)) {
            return $el;
        } else {
            $root->appendChild($el);
        }
    }
90521
static function encodeValue( $doc, $name, $value )
    {
        switch ( gettype( $value ) )
        {
            case "string" :
            {
                $node = $doc->createElement( $name, $value );
                $node->setAttribute( ggSOAPRequest::XSI_PREFIX . ':type',
                                     ggSOAPRequest::XSD_PREFIX . ':string' );
                return $node;
            } break;

            case "boolean" :
            {
                $node = $doc->createElement( $name, $value ? 'true' : 'false' );
                $node->setAttribute( ggSOAPRequest::XSI_PREFIX . ':type',
                                     ggSOAPRequest::XSD_PREFIX . ':boolean' );
                return $node;
            } break;

            case "integer" :
            {
                $node = $doc->createElement( $name, $value );
                $node->setAttribute( ggSOAPRequest::XSI_PREFIX . ':type',
                                     ggSOAPRequest::XSD_PREFIX . ':int' );
                return $node;
            } break;

            case "double" :
            {
                $node = $doc->createElement( $name, $value );
                $node->setAttribute( ggSOAPRequest::XSI_PREFIX . ':type',
                                     ggSOAPRequest::XSD_PREFIX . ':float' );
                return $node;
            } break;

            case "array" :
            {
                $arrayCount = count( $value );

                $isStruct = false;
                // Check for struct
                $i = 0;
                foreach( $value as $key => $val )
                {
                    if ( $i !== $key )
                    {
                        $isStruct = true;
                        break;
                    }
                    $i++;
                }

                if ( $isStruct == true )
                {
                    $node = $doc->createElement( $name );
                    $node->setAttribute( ggSOAPRequest::XSI_PREFIX . ':type',
                                         ggSOAPRequest::ENC_PREFIX . ':SOAPStruct' );

                    foreach( $value as $key => $val )
                    {
                        $subNode = ggSOAPRequest::encodeValue( $doc, (string)$key, $val );
                        $node->appendChild( $subNode );
                    }
                    return $node;
                }
                else
                {
                    $node = $doc->createElement( $name );
                    $node->setAttribute( ggSOAPRequest::XSI_PREFIX . ':type',
                                         ggSOAPRequest::ENC_PREFIX . ':Array' );
                    $node->setAttribute( ggSOAPRequest::ENC_PREFIX . ':arrayType',
                                         ggSOAPRequest::XSD_PREFIX . ":string[$arrayCount]" );

                    foreach ( $value as $arrayItem )
                    {
                        $subNode = ggSOAPRequest::encodeValue( $doc, "item", $arrayItem );
                        $node->appendChild( $subNode );
                    }

                    return  $node;
                }
            } break;
        }

        return false;
    }
947429
function serialize($charset_encoding='')
		{
			if ($charset_encoding != '')
				$this->content_type = 'text/xml; charset=' . $charset_encoding;
			else
				$this->content_type = 'text/xml';
			if ($GLOBALS['xmlrpc_null_apache_encoding'])
			{
				$result = "<methodResponse xmlns:ex=\"".$GLOBALS['xmlrpc_null_apache_encoding_ns']."\">\n";
			}
			else
			{
			$result = "<methodResponse>\n";
			}
			if($this->errno)
			{
				// G. Giunta 2005/2/13: let non-ASCII response messages be tolerated by clients
				// by xml-encoding non ascii chars
				$result .= "<fault>\n" .
"<value>\n<struct><member><name>faultCode</name>\n<value><int>" . $this->errno .
"</int></value>\n</member>\n<member>\n<name>faultString</name>\n<value><string>" .
xmlrpc_encode_entitites($this->errstr, $GLOBALS['xmlrpc_internalencoding'], $charset_encoding) . "</string></value>\n</member>\n" .
"</struct>\n</value>\n</fault>";
			}
			else
			{
				if(!is_object($this->val) || !is_a($this->val, 'xmlrpcval'))
				{
					if (is_string($this->val) && $this->valtyp == 'xml')
					{
						$result .= "<params>\n<param>\n" .
							$this->val .
							"</param>\n</params>";
					}
					else
					{
						/// @todo try to build something serializable?
						die('cannot serialize xmlrpcresp objects whose content is native php values');
					}
				}
				else
				{
					$result .= "<params>\n<param>\n" .
						$this->val->serialize($charset_encoding) .
						"</param>\n</params>";
				}
			}
			$result .= "\n</methodResponse>";
			$this->payload = $result;
			return $result;
		}
128593
public function serializeToXml()
    {
        $xml = new \SimpleXMLElement('<?xml version="1.0" encoding="utf-8"?><RefererConfiguration></RefererConfiguration>');
        if ($this->allowEmptyReferer) {
            $xml->addChild('AllowEmptyReferer', 'true');
        } else {
            $xml->addChild('AllowEmptyReferer', 'false');
        }
        $refererList = $xml->addChild('RefererList');
        foreach ($this->refererList as $referer) {
            $refererList->addChild('Referer', $referer);
        }
        return $xml->asXML();
    }
1362169
function xmlString( )
    {
        $doc = new DOMDocument( '1.0', 'utf-8' );

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

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

        $id = 0;
        foreach ( $this->Authors as $author )
        {
            unset( $authorNode );
            $authorNode = $doc->createElement( "author" );
            $authorNode->setAttribute( "id", $id++ );
            $authorNode->setAttribute( "name", $author["name"] );
            $authorNode->setAttribute( "email", $author["email"] );

            $authors->appendChild( $authorNode );
        }

        $xml = $doc->saveXML();

        return $xml;
    }
840087
public function dump_node($echo = true)
    {
        $string = $this->tag;
        if (count($this->attr) > 0) {
            $string .= '(';
            foreach ($this->attr as $k => $v) {
                $string .= "[$k]=>\"" . $this->$k . '", ';
            }
            $string .= ')';
        }
        if (count($this->_) > 0) {
            $string .= ' $_ (';
            foreach ($this->_ as $k => $v) {
                if (is_array($v)) {
                    $string .= "[$k]=>(";
                    foreach ($v as $k2 => $v2) {
                        $string .= "[$k2]=>\"" . $v2 . '", ';
                    }
                    $string .= ')';
                } else {
                    $string .= "[$k]=>\"" . $v . '", ';
                }
            }
            $string .= ')';
        }

        if (isset($this->text)) {
            $string .= ' text: (' . $this->text . ')';
        }

        $string .= " HDOM_INNER_INFO: '";
        if (isset($node->_[HDOM_INFO_INNER])) {
            $string .= $node->_[HDOM_INFO_INNER] . "'";
        } else {
            $string .= ' NULL ';
        }

        $string .= ' children: ' . count($this->children);
        $string .= ' nodes: ' . count($this->nodes);
        $string .= ' tag_start: ' . $this->tag_start;
        $string .= "\n";

        if ($echo) {
            echo $string;
            return;
        } else {
            return $string;
        }
    }
599204
public function stringNode($value = null, bool $allowSerializeEmpty = false): StringNode
    {
        return StringNode::create($value, $allowSerializeEmpty);
    }