0

I have an XML file like such:

<spice>
	<sections>
		<contact></contact>
		<products></products>
		<people></people>
		<homes></homes>
		<harvest></harvest>
		<contactCopy> 
			<banners><![CDATA[Lots of <u>text</u> with tons of <a href="#">links</a> and <i>other</i> markup.]]></banners>
		</contactCopy>
		<homesCopy>
			<banners><![CDATA[Lots of <u>text</u> with tons of <a href="#">links</a> and <i>other</i> markup.]]></banners>
		</homesCopy>
		<productsCopy>
			<banners><![CDATA[Lots of <u>text</u> with tons of <a href="#">links</a> and <i>other</i> markup.]]></banners>
		</productsCopy>
		<peopleCopy>
			 <banners><![CDATA[Lots of <u>text</u> with tons of <a href="#">links</a> and <i>other</i> markup.]]></banners>
		</peopleCopy>
		<harvestCopy>
			<banners><![CDATA[Lots of <u>text</u> with tons of <a href="#">links</a> and <i>other</i> markup.]]></banners>
		</harvestCopy>	
	</sections>
</spice>

What I need to be able to do is pull the CDATA content out, WITH the tags intact, have the client edit the content with a markup editor and put unentitied HTML back into the CDATA section. I have been able to pull the content out of the CDATA field with

$doc = new DomDocument();
$file = "spice.xml";
$doc->load($file);
$xPath = new DomXPath($doc);
$homesCopy 	= $xPath->query("//sections/homesCopy/banners");
echo $homesCopy->item(0)->nodeValue;

but I cannot for the life of me figure out how to simply edit that content and put it back without turning the HTML tags into their entities.

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by hielo
0

. I have been able to pull the content out of the CDATA field with

How do you know which banner you are editing at any given time? I was expecting to see each banner node with a unique id attribute so that when you edit, you would know which node to update. Where's your attempted update code?

0
assuming you are POSTing from a form with <input name='homesCopy'> try:

<?php
$doc = new DomDocument();
$file = "spice.xml";
$doc->load($file);
$xPath = new DomXPath($doc);
$homesCopy 	= $xPath->query("//sections/homesCopy/banners")->item(0);
if( isset($_POST['homesCopy']) ){
  $homesCopy->firstChild->nodeValue=$_POST['homesCopy'];
  $doc->save($file);
}
echo $homesCopy->nodeValue;
?>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.