php part
<?php
$f = fopen( "temp.xml","r" );
$str = "";
while( $line = fgets($f) ){
if( !($line[1]=='?' || $line[1]=='b' || $line[2]=='b') ){
$str.= $line."<br>";
}
}
fclose( $f );
$xdoc = new DomDocument;
$xdoc->Load('text.xml');
$body = $xdoc->getElementsByTagName('textBody')->item(0);
$txtNode = $xdoc ->createTextNode ( $str );
$body -> appendChild($txtNode);
$test = $xdoc->save("text.xml");
?>
xml file updated.
<textBody>
<br>
<br> &#13;
<br><font>Heading Here...</font>&#13;
<br><font>Text Here...</font>&#13;
<br>
</textBody>
I want to create child in xml file but the special characters are converted into their codes as shown above.
I want the output as
<br><br>
<br><font>Heading Here </font>
<br><font>Text Here</font>
<br>
php part <?php $f = fopen( temp.xml,r ); $str = ; while( $line =
Share
A textNode contains only character-data.
If you like to create and insert a fragment containing multiple element-nodes use DOMDocument::createDocumentFragment
Please note:
appendXML()is not a part of the DOM, it’s a PHP-implementation.If you like to do it a “clean” DOM-way, create a new document, load the string using loadXML() and import the result into the other document.