Click here to Skip to main content
15,922,696 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to write tags into .txt file with DOMDocument parser and read them but sometimes at the end I get `&lt;` instead of `<` and `&gt;` instead of `>`

I have sort of rendering depends on `<`and `>` so when the change into `&lt;` and `&gt;` it doesn't match. but in a different part of the project everything is fine (writing, reading, rendering).

write
PHP
$fh = fopen($fn, 'wb');   $str = $this->saveXML($node);  fwrite($fh, $str );  fclose($fh);


where $fn is a string the holds the file path and the $node is the current node in the tree I'm navigating through
read
PHP
$fh = fopen($fn, 'rb');  $str = fread($fh, filesize($fn)); 
$renderer->doc .= $renderer->_xmlEntities($str);


sample input
HTML
    <par><id>22</id><date>2012-04-10T14:53:06+02:00</date>
<P_title>title</P_title>
<P_body>
body
</P_body>
<keywords>keys</keywords>
</par>

result in page source
&lt;par&gt;&lt;id&gt;22&lt;/id&gt;&lt;date&gt;2012-04-10T14:53:06+02:00&lt;/date&gt;
&lt;P_title&gt;title&lt;/P_title&gt;
&lt;P_body&gt;
body
&lt;/P_body&gt;
&lt;keywords&gt;keys&lt;/keywords&gt;
&lt;/par&gt;
Posted

1 solution

Try adding header in beginning of the xml document
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900