View Full Version : php's @include a xml file in a editable textarea; hiding node tags
subhailc
10-01-2004, 07:17 AM
hi. i posted this in the php forum but had no luck; i'd appreciate any advice. i'm using php's include function to stick the contents of an xml sheet in an editable textarea, that the user edits and submits to save to server. everything works fine and dandy. however, the node tags are visible and editable in the textarea and must be 'typed around' - there are additional php functions that'll strip the tags out completely, but i need them preserved for obvious reasons - i think i understand basically why this is happening, but don't know enough about xml or php to fix it. i'm guessing/hoping there's a very simple answer that's just not available to someone of my limited ability. the code follows; thanks in advance
<?php
$filename = "cmadata.xml";
if($submit && $string)
{
$textfile= fopen($filename,'w+');
fputs($textfile, $string);
fclose($textfile);
}
else {
?>
<html>
<body>
<form method=post action="<? echo $PHP_SELF; ?>" ?>
<textarea name=string><?php include 'cmadata.xml'; ?></textarea>
<input type=submit name=submit></form>
</body>
</html>
<?
}
?>
Alex Vincent
10-02-2004, 03:51 AM
Interesting.
(1) I suggest sending the document as an XHTML document, not as text/html. You'll have to do some markup cleanup, but it'll be worth it.
(2)
<?php echo "<![CDATA[";
include('cmadata.xml');
echo "]]>"?>
The CDATA tags tell XML-compatible user-agents to treat the contents as character data. In short, the contents become text.
subhailc
10-06-2004, 11:49 AM
Alex,
Thanks for the reply.
1. I'm not sure why I'd do this? What're the benefits you're thinking of... The documents are plain text xml files that we're using as a base for pretty much everything (production control in a dbms, sales and delivery in excel, the image gallery on the site, etc).
2. The problem with CDATA is that when I return the information, the tags are still stripped and no nodes = no use. I was hoping to hide them just while viewing online (the guy that uses this same sheet in excel has the node columsn hidden and the sheet protected but they're still there after he edits and saves; I was trying to accomplish the same thing using an online form).
I'm still curious as to number 1 (i'm not being rude; I honestly wonder if there's some added functionality or benefit that I'm not aware of), but as embarassing as it is, I found the solution to hiding the node tags in flash's ActionScript - it's got a (surprisingly) robust built-in XML class that allows pretty much any kind of array and string manipulation you'd need for small data structures. I parse the xml to text, display it in their custom textField objects, on password validation dynamically change the appropriate fields to their version of textboxes (with content intact), and on submit the php rewrites the xml document to the server. Overall, I was very pleasantly surprised by my first dip into macromedia's product.
Thanks again.
gsnedders
10-06-2004, 06:25 PM
In XHTML served as application/xhtml+xml you can put XML in it.
vBulletin® v3.8.2, Copyright ©2000-2010, Jelsoft Enterprises Ltd.