I'm reading the contents from 开发者_C百科an XML file to show the web pages contents, please see the code snippet to read the XML file,
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
<?php
$arg = $_GET['content'];
//echo $arg;
$doc = new DOMDocument();
$doc->load('History.XML');
$contents = $doc->getElementsByTagName($arg);
$content1 = $contents->item(0)->nodeValue;
$content2 = $contents->item(1)->nodeValue;
?>
<p>
<?php
echo <<<EOM
$content1
EOM;
?>
</p>
</body>
</html>
The XML file contents have some HTML formatting tags like <b>
<h3>
etc, but reading and showing those contents from XML , the HTML formatting are not happening.
Please clarify me if I did any mistake.
nodeValue
in your case is a concatenation of all text nodes.
Use string DOMDocument::saveXML ([ DOMNode $node [, int $options ]] ) instead.
self-contained example:
<?php
$arg = 'foo';
$doc = new DOMDocument();
$doc->loadxml('<x>
<foo><h1>lalala</h1><b>xyz</b></foo>
<foo>12345</foo>
</x>');
$contents = $doc->getElementsByTagName($arg);
$content1 = $contents->item(0);
$content2 = $contents->item(1);
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
<p><?php echo $doc->savexml($content1); ?></p>
</body>
</html>
prints
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
<p><foo><h1>lalala</h1><b>xyz</b></foo></p>
</body>
</html>
精彩评论