On Feb 21, 12:37 pm, Ian Taylor <m...@ocset.rev erse.previous.w ord.net>
wrote:
dcrac...@gmail. com wrote:
I hope there is a simple solution to this, but I've been unable to
find it.
$dom = new DomDocument();
$dom->load("test.xml ");
$test = $dom->getElementsByT agName("test");
$test->nodeValue = "<b>test</b>";
$dom->save("test.xml ");
I would like the node in the xml file to look like:
<test><b>test </b></test>
Rather than the encoded version.
<b>test&l t;/b>
What can be done to accomplish this task?
Thank you
dwain
From what I can see, it's not really possible - if it was possible, and
you tried to re-read the resulting xml file back, you would end up with
something like:
...
<test>
<b>
test
</b>
</test>
...
where <bis a child node of the <testnode, rather than part of the
value of the <testnode.
Therefore, entities like < and do need to be encoded / decoded
(possible with html_entity_dec ode()) when dealing with xml.
If, however, you *are* looking to add <bas a child node of <test>, I'm
sure there are functions to handle that ( probably something like $child
= $test->append_child(' b') )- Hide quoted text -
- Show quoted text -
Thank you for the advice,
I'm looking to save HTML inside the XML, for that example that text
may be viewed bold when shown in a browser.
------------------------------------ Test.xml
<?xml version="1.0"?>
<ROOT>
<TEST>
<NAME>TEST PRODUCT 01</NAME>
<DESC>This is a test product, this is <b>bold</b>.</DESC>
<PRICE>9.99</PRICE>
</TEST>
</ROOT>
------------------------------------ Test.xsl
<?xml version="1.0"?>
<xsl:styleshe et version="1.0" xmlns:xsl="http ://www.w3.org/1999/XSL/
Transform">
<xsl:output method="html"/>
<xsl:template match="/">
<html>
<xsl:for-each select="ROOT/TEST">
<P>
<hr />
<xsl:value-of select="NAME" /<br />
<xsl:copy-of select="DESC |text()"/ <br />
<xsl:value-of select="PRICE" /<br />
<hr />
</P>
</xsl:for-each>
</html>
</xsl:template>
</xsl:stylesheet>
------------------------------------------------------- Test.php
<?php
$xsl = new DomDocument();
$xsl->load("test.xsl ");
$inputdom = new DomDocument();
$inputdom->load("test.xml ");
$proc = new XsltProcessor() ;
$xsl = $proc->importStyleshe et($xsl);
$newdom = $proc->transformToDoc ($inputdom);
print $newdom->saveXML();
?>
----------------------------- Result
<?xml version="1.0" standalone="yes "?>
<html><P><hr/>TEST PRODUCT 01<br/>
<DESC>This is a test product, this is <b>bold</b>.</DESC>
<br/>9.99<br/><hr/></P></html>
-------------------------------- The problem
When a XML document is saved by PHP it looks like
<?xml version="1.0"?>
<ROOT>
<TEST>
<NAME>TEST PRODUCT 01</NAME>
<DESC>This is a test product, this is <b>bold&l t;/b>.</
DESC>
<PRICE>9.99</PRICE>
</TEST>
</ROOT>
I need to be able to save the XML Doc after altering it in PHP:
EX:
$node->nodeValue = "This is a test product, this is <b>bold</b>.";
$dom->save("test.xml ");
without encoding the "<b>"'s.