Pretty print an XML string - if the HTML Display flag is passed it will be formatted for display on a web page
with special characters escaped.

@param string $xmlString
@param boolean $htmlDisplay

@return string
8304
public static function prettyPrint($xmlString, $htmlDisplay = false) {

        // Create a nicely formatted version
        $doc = new \DOMDocument();
        $doc->loadXML($xmlString);
        $doc->preserveWhiteSpace = false;
        $doc->formatOutput = true;

        $prettyXML = $doc->saveXML();

        if ($htmlDisplay) $prettyXML = str_replace(array("<", ">", "\n", " "), array("&lt;", "&gt;", "<br>", "&nbsp;"), $prettyXML);

        return $prettyXML;
    }
1241671
public static function escape($string)
    {
        Arguments::define(
            Boa::either(
                Boa::either(
                    Boa::instance(SafeHtmlWrapper::class),
                    Boa::instance(SafeHtmlProducerInterface::class)
                ),
                Boa::string()
            )
        )->check($string);

        if ($string instanceof SafeHtmlWrapper) {
            return $string;
        } elseif ($string instanceof SafeHtmlProducerInterface) {
            $result = $string->getSafeHtml();

            if ($result instanceof SafeHtmlWrapper) {
                return $result;
            } elseif ($result instanceof SafeHtmlProducerInterface) {
                return static::escape($result);
            }

            throw new CoreException(vsprintf(
                'Object of class %s implements SafeHtmlProducerInterface'
                . ' but it returned an unsafe type: %s',
                [get_class($string), TypeHound::fetch($result)]
            ));
        }

        return htmlspecialchars($string, ENT_QUOTES, 'UTF-8');
    }
745677
public static String serialize(String xmlString) {
        Writer sw = new StringBuilderWriter();
        serialize(asStreamSource(xmlString), sw);
        return sw.toString();
    }
1245568
protected function getEntryList($xmlString)
    {
        $xml = simplexml_load_string($xmlString);

        if ($xml->getName() == Resources::ENTRY) {
            $entry = new Entry();
            $entry->fromXml($xml);
            $entries = [$entry];
        } else {
            $feed = new Feed();
            $feed->parseXml($xmlString);
            $entries = $feed->getEntry();
        }

        $result = [];
        if (is_array($entries)) {
            foreach ($entries as $entry) {
                $properties = $this->getPropertiesFromAtomEntry($entry);
                if (!empty($properties)) {
                    $result[] = $properties;
                }
            }
        }

        return $result;
    }
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);
    }
1142842
public function trimXmlString($xmlString)
    {
        $xmlString = preg_replace('/[\r\n]+(?![^(]*\))/', '', $xmlString);
        $xmlString = preg_replace('/[\s]{2,}/', ' ', $xmlString);
        $xmlString = str_replace(["\r\n", "\n"], '', $xmlString);

        return trim($xmlString);
    }
105095
public function escapeForHtml() {
		$rawString = htmlspecialchars($this->rawString, ENT_QUOTES, $this->charset);

		return new static($rawString, $this->charset);
	}
746044
public static function innerXML(\DOMNode $node, $xmlstring)
    {
        $xmlstring = str_replace("<br>", "<br/>", $xmlstring);
        $len = strlen($xmlstring);
        $endText = "";
        $close = strrpos($xmlstring, '>');
        if ($close !== false && $close < $len - 1) {
            $endText = substr($xmlstring, $close + 1);
            $xmlstring = substr($xmlstring, 0, $close + 1);
        }
        $open = strpos($xmlstring, '<');
        if ($open === false) {
            $node->nodeValue .= $xmlstring;
        } else {
            if ($open > 0) {
                $text = substr($xmlstring, 0, $open);
                $xmlstring = substr($xmlstring, $open);
                $node->nodeValue .= $text;
            }
            $dom = XmlUtil::getOwnerDocument($node);
            $xmlstring = "<rootxml>$xmlstring</rootxml>";
            $sxe = @simplexml_load_string($xmlstring);
            if ($sxe === false) {
                throw new XmlUtilException("Cannot load XML string.", 252);
            }
            $domSimpleXml = dom_import_simplexml($sxe);
            if (!$domSimpleXml) {
                throw new XmlUtilException("XML Parsing error.", 253);
            }
            $domSimpleXml = $dom->importNode($domSimpleXml, true);
            $childs = $domSimpleXml->childNodes->length;
            for ($i = 0; $i < $childs; $i++) {
                $node->appendChild($domSimpleXml->childNodes->item($i)->cloneNode(true));
            }
        }
        if (!empty($endText) && $endText != "") {
            $textNode = $dom->createTextNode($endText);
            $node->appendChild($textNode);
        }
        return $node->firstChild;
    }
623053
static function xmlData($string, $cdata=false) {
        $string = str_replace("]]>", "]]]]><![CDATA[>", $string);
        if (!$cdata)
            $string = "<![CDATA[$string]]>";
        return $string;
    }
10440
public void printHtmlIcon(PrintWriter out, String strTag, String strParams, String strData)
    {
        String strIcon = "Menu";
        strIcon = HtmlConstants.HTML_ROOT + HtmlConstants.ICON_DIR + strIcon + ".gif";
        out.print(strIcon + "\n");
    }
1299985
protected function processReport($xmlString)
    {
        $xml = simplexml_load_string($xmlString);

        if ($xml === false) {
            $this->phpci->log($xmlString);
            throw new \Exception('Could not process PHPMD report XML.');
        }

        $warnings = 0;

        foreach ($xml->file as $file) {
            $fileName = (string)$file['name'];
            $fileName = str_replace($this->phpci->buildPath, '', $fileName);

            foreach ($file->violation as $violation) {
                $warnings++;

                $this->build->reportError(
                    $this->phpci,
                    'php_mess_detector',
                    (string)$violation,
                    PHPCI\Model\BuildError::SEVERITY_HIGH,
                    $fileName,
                    (int)$violation['beginline'],
                    (int)$violation['endline']
                );
            }
        }

        return $warnings;
    }
581943
public void printHtmlTrailer(PrintWriter out, ResourceBundle reg)
        throws DBException
    {
        char chMenubar = HBasePanel.getFirstToUpper(this.getProperty(DBParams.TRAILERS), 'H');
        if (chMenubar == 'H') if (((BasePanel)this.getScreenField()).isMainMenu())
            chMenubar = 'Y';
        if (chMenubar == 'Y')
        {
            String strNav = reg.getString("htmlTrailer");
            strNav = Utility.replaceResources(strNav, reg, null, null);
            String strScreen = ((BasePanel)this.getScreenField()).getScreenURL();
            strScreen = Utility.encodeXML(strScreen);
            strNav = Utility.replace(strNav, HtmlConstants.URL_TAG, strScreen);
            this.writeHtmlString(strNav, out);
        }
    }
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;
    }
85021
public function removeAnnouncement($xmlString)
    {
        $matches = [];

        preg_match('/<?xml version="(.*)" encoding="(.*)"?>(.*)$/isuU', $xmlString, $matches);

        return isset($matches[3]) ? $matches[3] : $xmlString;
    }
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());
        }
    }
856378
public function isXml($xmlString)
    {
        $previousValue = libxml_use_internal_errors(true);

        $simpleXml = simplexml_load_string($xmlString);

        libxml_use_internal_errors($previousValue);

        return false !== $simpleXml;
    }
66557
public function parseAddress($xmlString)
    {
        $previousValue = libxml_use_internal_errors(true);
        $xml = simplexml_load_string($xmlString);
        libxml_use_internal_errors($previousValue);

        if ($xml === false) {
            $message = $this->getXmlErrorMessage();
            throw new InvalidArgumentException('Failed to parse supplied XML string: ' . $message);
        }

        return $this->parseSubjectAddress($xml);
    }